MCPcopy Index your code
hub / github.com/coder/coder / aggregate

Method aggregate

coderd/prometheusmetrics/aggregator.go:239–271  ·  view source on GitHub ↗
(am annotatedMetric, labels []string)

Source from the content-addressed store, hash-verified

237}
238
239func (a *labelAggregator) aggregate(am annotatedMetric, labels []string) error {
240 // Use a LabelSet because it can give deterministic fingerprints of label combinations regardless of map ordering.
241 labelSet := make(model.LabelSet, len(labels))
242
243 for _, label := range labels {
244 val, err := am.getFieldByLabel(label)
245 if err != nil {
246 return err
247 }
248
249 labelSet[model.LabelName(label)] = model.LabelValue(val)
250 }
251
252 // Memoize based on the metric name & the unique combination of labels.
253 key := fmt.Sprintf("%s:%v", am.Stats_Metric.Name, labelSet.FastFingerprint())
254
255 // Aggregate the value based on the key.
256 a.aggregations[key] += am.Value
257
258 metric, found := a.metrics[key]
259 if !found {
260 // Take a copy of the given annotatedMetric because it may be manipulated later and contains pointers.
261 metric = am.shallowCopy()
262 }
263
264 // Store the metric.
265 metric.aggregateByLabels = labels
266 metric.Value = a.aggregations[key]
267
268 a.metrics[key] = metric
269
270 return nil
271}
272
273func (a *labelAggregator) listMetrics() []annotatedMetric {
274 var out []annotatedMetric

Callers 1

RunMethod · 0.45

Calls 2

getFieldByLabelMethod · 0.80
shallowCopyMethod · 0.80

Tested by

no test coverage detected