MCPcopy Create free account
hub / github.com/prometheus/common / extractHistogram

Function extractHistogram

expfmt/decode.go:379–464  ·  view source on GitHub ↗
(o *DecodeOptions, f *dto.MetricFamily)

Source from the content-addressed store, hash-verified

377}
378
379func extractHistogram(o *DecodeOptions, f *dto.MetricFamily) model.Vector {
380 samples := make(model.Vector, 0, len(f.Metric))
381
382 for _, m := range f.Metric {
383 if m.Histogram == nil {
384 continue
385 }
386
387 timestamp := o.Timestamp
388 if m.TimestampMs != nil {
389 timestamp = model.TimeFromUnixNano(*m.TimestampMs * 1000000)
390 }
391
392 infSeen := false
393
394 for _, q := range m.Histogram.Bucket {
395 lset := make(model.LabelSet, len(m.Label)+2)
396 for _, p := range m.Label {
397 lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue())
398 }
399 lset[model.LabelName(model.BucketLabel)] = model.LabelValue(fmt.Sprint(q.GetUpperBound()))
400 lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_bucket")
401
402 if math.IsInf(q.GetUpperBound(), +1) {
403 infSeen = true
404 }
405
406 v := q.GetCumulativeCountFloat()
407 if v <= 0 {
408 v = float64(q.GetCumulativeCount())
409 }
410 samples = append(samples, &model.Sample{
411 Metric: model.Metric(lset),
412 Value: model.SampleValue(v),
413 Timestamp: timestamp,
414 })
415 }
416
417 lset := make(model.LabelSet, len(m.Label)+1)
418 for _, p := range m.Label {
419 lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue())
420 }
421 lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_sum")
422
423 samples = append(samples, &model.Sample{
424 Metric: model.Metric(lset),
425 Value: model.SampleValue(m.Histogram.GetSampleSum()),
426 Timestamp: timestamp,
427 })
428
429 lset = make(model.LabelSet, len(m.Label)+1)
430 for _, p := range m.Label {
431 lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue())
432 }
433 lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_count")
434
435 v := m.Histogram.GetSampleCountFloat()
436 if v <= 0 {

Callers 1

extractSamplesFunction · 0.85

Calls 5

TimeFromUnixNanoFunction · 0.92
LabelNameTypeAlias · 0.92
LabelValueTypeAlias · 0.92
MetricTypeAlias · 0.92
SampleValueTypeAlias · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…