@@ -18,12 +18,10 @@ import (
1818 "sort"
1919 "strings"
2020
21+ "github.com/prometheus/client_golang/prometheus/internal/fastdto"
22+
2123 "github.com/cespare/xxhash/v2"
22- dto "github.com/prometheus/client_model/go"
2324 "github.com/prometheus/common/model"
24- "google.golang.org/protobuf/proto"
25-
26- "github.com/prometheus/client_golang/prometheus/internal"
2725)
2826
2927// Desc is the descriptor used by every Prometheus Metric. It is essentially
@@ -56,7 +54,7 @@ type Desc struct {
5654 variableLabelOrder []int
5755 // labelPairs contains the sorted DTO label pairs based on the constant labels
5856 // and variable labels
59- labelPairs []* dto .LabelPair
57+ labelPairs []fastdto .LabelPair
6058 // id is a hash of the values of the ConstLabels and fqName. This
6159 // must be unique among all registered descriptors and can therefore be
6260 // used as an identifier of the descriptor.
@@ -164,24 +162,23 @@ func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, const
164162 }
165163 d .dimHash = xxh .Sum64 ()
166164
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
168167 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 ++
173171 }
174172 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 ++
178175 }
179- sort .Sort (internal .LabelPairSorter (d .labelPairs ))
176+ sort .Sort (fastdto .LabelPairSorter (d .labelPairs ))
180177
181178 d .variableLabelOrder = make ([]int , len (d .variableLabels .names ))
182179 for outputIndex , pair := range d .labelPairs {
183180 // Constant labels have values variable labels do not.
184- if pair .Value != nil {
181+ if pair .Value != "" {
185182 continue
186183 }
187184 for sourceIndex , variableLabel := range d .variableLabels .names {
@@ -190,7 +187,6 @@ func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, const
190187 }
191188 }
192189 }
193-
194190 return d
195191}
196192
@@ -207,7 +203,7 @@ func NewInvalidDesc(err error) *Desc {
207203func (d * Desc ) String () string {
208204 lpStrings := make ([]string , 0 , len (d .labelPairs ))
209205 for _ , lp := range d .labelPairs {
210- if lp .Value == nil {
206+ if lp .Value == "" {
211207 continue
212208 }
213209 lpStrings = append (
0 commit comments