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

Function extractHistogram

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

Source from the content-addressed store, hash-verified

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