@@ -47,6 +47,8 @@ type Desc struct {
47
47
fqName string
48
48
// help provides some helpful information about this metric.
49
49
help string
50
+ // unit provides the unit of this metric
51
+ unit string
50
52
// constLabelPairs contains precalculated DTO label pairs based on
51
53
// the constant labels.
52
54
constLabelPairs []* dto.LabelPair
@@ -75,8 +77,8 @@ type Desc struct {
75
77
//
76
78
// For constLabels, the label values are constant. Therefore, they are fully
77
79
// specified in the Desc. See the Collector example for a usage pattern.
78
- func NewDesc (fqName , help string , variableLabels []string , constLabels Labels ) * Desc {
79
- return V2 .NewDesc (fqName , help , UnconstrainedLabels (variableLabels ), constLabels )
80
+ func NewDesc (fqName , help string , unit string , variableLabels []string , constLabels Labels ) * Desc {
81
+ return V2 .NewDesc (fqName , help , unit , UnconstrainedLabels (variableLabels ), constLabels )
80
82
}
81
83
82
84
// NewDesc allocates and initializes a new Desc. Errors are recorded in the Desc
@@ -89,10 +91,11 @@ func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) *
89
91
//
90
92
// For constLabels, the label values are constant. Therefore, they are fully
91
93
// specified in the Desc. See the Collector example for a usage pattern.
92
- func (v2 ) NewDesc (fqName , help string , variableLabels ConstrainableLabels , constLabels Labels ) * Desc {
94
+ func (v2 ) NewDesc (fqName , help string , unit string , variableLabels ConstrainableLabels , constLabels Labels ) * Desc {
93
95
d := & Desc {
94
96
fqName : fqName ,
95
97
help : help ,
98
+ unit : unit ,
96
99
variableLabels : variableLabels .compile (),
97
100
}
98
101
if ! model .IsValidMetricName (model .LabelValue (fqName )) {
@@ -149,10 +152,11 @@ func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, const
149
152
d .id = xxh .Sum64 ()
150
153
// Sort labelNames so that order doesn't matter for the hash.
151
154
sort .Strings (labelNames )
152
- // Now hash together (in this order) the help string and the sorted
155
+ // Now hash together (in this order) the help string, the unit string and the sorted
153
156
// label names.
154
157
xxh .Reset ()
155
158
xxh .WriteString (help )
159
+ xxh .WriteString (unit )
156
160
xxh .Write (separatorByteSlice )
157
161
for _ , labelName := range labelNames {
158
162
xxh .WriteString (labelName )
@@ -198,9 +202,10 @@ func (d *Desc) String() string {
198
202
}
199
203
}
200
204
return fmt .Sprintf (
201
- "Desc{fqName: %q, help: %q, constLabels: {%s}, variableLabels: {%s}}" ,
205
+ "Desc{fqName: %q, help: %q, unit: %q, constLabels: {%s}, variableLabels: {%s}}" ,
202
206
d .fqName ,
203
207
d .help ,
208
+ d .unit ,
204
209
strings .Join (lpStrings , "," ),
205
210
strings .Join (vlStrings , "," ),
206
211
)
0 commit comments