@@ -52,8 +52,14 @@ import (
52
52
// its type will be set to `unknown` in that case to avoid invalid OpenMetrics
53
53
// output.
54
54
//
55
- // - The `# UNIT` line is optional, but if populated, the unit has to be present in the metric
56
- // name as its suffix (see https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#unit)
55
+ // - According to the OM specs, the `# UNIT` line is optional, but if populated,
56
+ // the unit has to be present in the metric name as its suffix:
57
+ // (see https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#unit).
58
+ // However, in order to accomodate any potential scenario where such a change in the
59
+ // metric name is not desirable, the users are here given the choice of either explicitly
60
+ // opt in, in case they wish for the unit to be included in the output AND in the metric name
61
+ // as a suffix (see the description of the ToOpenMetricsWithUnit function below),
62
+ // or not to opt in, in case they don't want for any of that to happen.
57
63
//
58
64
// - No support for the following (optional) features: `_created`
59
65
// line, info type, stateset type, gaugehistogram type.
@@ -66,11 +72,16 @@ import (
66
72
67
73
type ToOpenMetrics struct {
68
74
withUnit bool
69
- // withCreated bool can be added in the future
75
+ // withCreated bool can be added in the future.
70
76
}
71
77
72
78
type ToOpenMetricsOption = func (* ToOpenMetrics )
73
79
80
+ // ToOpenMetricsWithUnit is meant to be called as an optional argument in the MetricFamilyToOpenMetrics
81
+ // function. It enables a set unit to be written to the output and to be added to the metric name, (if
82
+ // it's not there already), as a suffix. Without opting in this way, the unit will not be added to the
83
+ // metric name and, on top of that, the unit will not be passed onto the output, even if it were declared
84
+ // in the *dto.MetricFamily struct, i.e. even if in.Unit !=nil.
74
85
func ToOpenMetricsWithUnit () ToOpenMetricsOption {
75
86
return func (om * ToOpenMetrics ) {
76
87
om .withUnit = true
0 commit comments