MCPcopy Create free account
hub / github.com/netdata/netdata / addHistogram

Method addHistogram

src/go/pkg/prometheus/parse.go:336–373  ·  view source on GitHub ↗
(value float64)

Source from the content-addressed store, hash-verified

334}
335
336func (p *promTextParser) addHistogram(value float64) {
337 hash := p.currSeries.Hash()
338
339 p.currSeries, _, _ = removeLabel(p.currSeries, labels.MetricName)
340
341 h, ok := p.histograms[hash]
342 if !ok {
343 if v := len(p.currMF.metrics); v == cap(p.currMF.metrics) {
344 h = &Histogram{}
345 p.currMF.metrics = append(p.currMF.metrics, Metric{
346 labels: copyLabels(p.currSeries),
347 histogram: h,
348 })
349 } else {
350 p.currMF.metrics = p.currMF.metrics[:v+1]
351 if p.currMF.metrics[v].histogram == nil {
352 p.currMF.metrics[v].histogram = &Histogram{}
353 }
354 p.currMF.metrics[v].histogram.sum = 0
355 p.currMF.metrics[v].histogram.count = 0
356 p.currMF.metrics[v].histogram.buckets = p.currMF.metrics[v].histogram.buckets[:0]
357 p.currMF.metrics[v].labels = p.currMF.metrics[v].labels[:0]
358 p.currMF.metrics[v].labels = append(p.currMF.metrics[v].labels, p.currSeries...)
359 h = p.currMF.metrics[v].histogram
360 }
361
362 p.histograms[hash] = h
363 }
364
365 switch {
366 case p.isBucket:
367 h.buckets = append(h.buckets, Bucket{upperBound: p.currBucket, cumulativeCount: value})
368 case p.isSum:
369 h.sum = value
370 case p.isCount:
371 h.count = value
372 }
373}
374
375func (p *promTextParser) reset() {
376 p.currMF = nil

Callers 1

parseToMetricFamiliesMethod · 0.95

Calls 3

removeLabelFunction · 0.85
copyLabelsFunction · 0.70
HashMethod · 0.65

Tested by

no test coverage detected