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