@@ -72,15 +72,6 @@ type CollectSession struct {
72
72
currentByName map [string ]* dto.MetricFamily
73
73
}
74
74
75
- func (s * CollectSession ) Commit () {
76
- // TODO(bwplotka): Sort metrics within family.
77
- s .c .metricFamilyByName = s .currentByName
78
- s .c .metrics = s .currentMetrics
79
-
80
- s .closed = true
81
- s .c .pendingSession = false
82
- }
83
-
84
75
func (s * CollectSession ) MustAddMetric (fqName , help string , labelNames , labelValues []string , valueType ValueType , value float64 , ts * time.Time ) {
85
76
if err := s .AddMetric (fqName , help , labelNames , labelValues , valueType , value , ts ); err != nil {
86
77
panic (err )
@@ -95,7 +86,7 @@ func (s *CollectSession) AddMetric(fqName, help string, labelNames, labelValues
95
86
}
96
87
97
88
// Label names can be unsorted, will be sorting them later. The only implication is cachability if
98
- // consumer provide non-deterministic order of those (unlikely since label values has to be matched.
89
+ // consumer provide non-deterministic order of those (unlikely since label values has to be matched) .
99
90
100
91
if len (labelNames ) != len (labelValues ) {
101
92
return errors .New ("new metric: label name has different len than values" )
@@ -125,7 +116,7 @@ func (s *CollectSession) AddMetric(fqName, help string, labelNames, labelValues
125
116
h := xxhash .New ()
126
117
h .WriteString (fqName )
127
118
h .Write (separatorByteSlice )
128
- for i := range labelNames {
119
+ for i := range labelNames { // Ofc not in the same order...
129
120
h .WriteString (labelNames [i ])
130
121
h .Write (separatorByteSlice )
131
122
h .WriteString (labelValues [i ])
@@ -149,7 +140,6 @@ func (s *CollectSession) AddMetric(fqName, help string, labelNames, labelValues
149
140
}
150
141
sort .Sort (labelPairSorter (m .Label ))
151
142
}
152
- s .currentMetrics [hSum ] = m
153
143
switch valueType {
154
144
case CounterValue :
155
145
v := m .Counter
@@ -186,12 +176,22 @@ func (s *CollectSession) AddMetric(fqName, help string, labelNames, labelValues
186
176
if ts != nil {
187
177
m .TimestampMs = proto .Int64 (ts .Unix ()* 1000 + int64 (ts .Nanosecond ()/ 1000000 ))
188
178
}
179
+ s .currentMetrics [hSum ] = m
189
180
190
181
// Will be sorted later.
191
182
d .Metric = append (d .Metric , m )
192
183
return nil
193
184
}
194
185
186
+ func (s * CollectSession ) Commit () {
187
+ // TODO(bwplotka): Sort metrics within family.
188
+ s .c .metricFamilyByName = s .currentByName
189
+ s .c .metrics = s .currentMetrics
190
+
191
+ s .closed = true
192
+ s .c .pendingSession = false
193
+ }
194
+
195
195
type BlockingRegistry struct {
196
196
* Registry
197
197
0 commit comments