(o *DecodeOptions, f *dto.MetricFamily)
| 352 | } |
| 353 | |
| 354 | func extractHistogram(o *DecodeOptions, f *dto.MetricFamily) model.Vector { |
| 355 | samples := make(model.Vector, 0, len(f.Metric)) |
| 356 | |
| 357 | for _, m := range f.Metric { |
| 358 | if m.Histogram == nil { |
| 359 | continue |
| 360 | } |
| 361 | |
| 362 | timestamp := o.Timestamp |
| 363 | if m.TimestampMs != nil { |
| 364 | timestamp = model.TimeFromUnixNano(*m.TimestampMs * 1000000) |
| 365 | } |
| 366 | |
| 367 | infSeen := false |
| 368 | |
| 369 | for _, q := range m.Histogram.Bucket { |
| 370 | lset := make(model.LabelSet, len(m.Label)+2) |
| 371 | for _, p := range m.Label { |
| 372 | lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) |
| 373 | } |
| 374 | lset[model.LabelName(model.BucketLabel)] = model.LabelValue(fmt.Sprint(q.GetUpperBound())) |
| 375 | lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_bucket") |
| 376 | |
| 377 | if math.IsInf(q.GetUpperBound(), +1) { |
| 378 | infSeen = true |
| 379 | } |
| 380 | |
| 381 | samples = append(samples, &model.Sample{ |
| 382 | Metric: model.Metric(lset), |
| 383 | Value: model.SampleValue(q.GetCumulativeCount()), |
| 384 | Timestamp: timestamp, |
| 385 | }) |
| 386 | } |
| 387 | |
| 388 | lset := make(model.LabelSet, len(m.Label)+1) |
| 389 | for _, p := range m.Label { |
| 390 | lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) |
| 391 | } |
| 392 | lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_sum") |
| 393 | |
| 394 | samples = append(samples, &model.Sample{ |
| 395 | Metric: model.Metric(lset), |
| 396 | Value: model.SampleValue(m.Histogram.GetSampleSum()), |
| 397 | Timestamp: timestamp, |
| 398 | }) |
| 399 | |
| 400 | lset = make(model.LabelSet, len(m.Label)+1) |
| 401 | for _, p := range m.Label { |
| 402 | lset[model.LabelName(p.GetName())] = model.LabelValue(p.GetValue()) |
| 403 | } |
| 404 | lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_count") |
| 405 | |
| 406 | count := &model.Sample{ |
| 407 | Metric: model.Metric(lset), |
| 408 | Value: model.SampleValue(m.Histogram.GetSampleCount()), |
| 409 | Timestamp: timestamp, |
| 410 | } |
| 411 | samples = append(samples, count) |
no test coverage detected