@@ -19,11 +19,8 @@ import (
19
19
"strings"
20
20
21
21
"github.com/cespare/xxhash/v2"
22
- dto "github.com/prometheus/client_model/go "
22
+ "github.com/prometheus/client_golang/prometheus/internal/fastdto "
23
23
"github.com/prometheus/common/model"
24
- "google.golang.org/protobuf/proto"
25
-
26
- "github.com/prometheus/client_golang/prometheus/internal"
27
24
)
28
25
29
26
// Desc is the descriptor used by every Prometheus Metric. It is essentially
@@ -56,7 +53,7 @@ type Desc struct {
56
53
variableLabelOrder []int
57
54
// labelPairs contains the sorted DTO label pairs based on the constant labels
58
55
// and variable labels
59
- labelPairs []* dto .LabelPair
56
+ labelPairs []fastdto .LabelPair
60
57
// id is a hash of the values of the ConstLabels and fqName. This
61
58
// must be unique among all registered descriptors and can therefore be
62
59
// used as an identifier of the descriptor.
@@ -164,24 +161,23 @@ func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, const
164
161
}
165
162
d .dimHash = xxh .Sum64 ()
166
163
167
- d .labelPairs = make ([]* dto.LabelPair , 0 , len (constLabels )+ len (d .variableLabels .names ))
164
+ d .labelPairs = make ([]fastdto.LabelPair , len (constLabels )+ len (d .variableLabels .names ))
165
+ i := 0
168
166
for n , v := range constLabels {
169
- d .labelPairs = append (d .labelPairs , & dto.LabelPair {
170
- Name : proto .String (n ),
171
- Value : proto .String (v ),
172
- })
167
+ d .labelPairs [i ].Name = n
168
+ d .labelPairs [i ].Value = v
169
+ i ++
173
170
}
174
171
for _ , labelName := range d .variableLabels .names {
175
- d .labelPairs = append (d .labelPairs , & dto.LabelPair {
176
- Name : proto .String (labelName ),
177
- })
172
+ d .labelPairs [i ].Name = labelName
173
+ i ++
178
174
}
179
- sort .Sort (internal .LabelPairSorter (d .labelPairs ))
175
+ sort .Sort (fastdto .LabelPairSorter (d .labelPairs ))
180
176
181
177
d .variableLabelOrder = make ([]int , len (d .variableLabels .names ))
182
178
for outputIndex , pair := range d .labelPairs {
183
179
// Constant labels have values variable labels do not.
184
- if pair .Value != nil {
180
+ if pair .Value != "" {
185
181
continue
186
182
}
187
183
for sourceIndex , variableLabel := range d .variableLabels .names {
@@ -190,7 +186,6 @@ func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, const
190
186
}
191
187
}
192
188
}
193
-
194
189
return d
195
190
}
196
191
@@ -207,7 +202,7 @@ func NewInvalidDesc(err error) *Desc {
207
202
func (d * Desc ) String () string {
208
203
lpStrings := make ([]string , 0 , len (d .labelPairs ))
209
204
for _ , lp := range d .labelPairs {
210
- if lp .Value == nil {
205
+ if lp .Value == "" {
211
206
continue
212
207
}
213
208
lpStrings = append (
0 commit comments