From c36b80ce0ee89f4a113fb3e0a768f0d2b3882d51 Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Fri, 9 Apr 2021 14:17:53 -0700 Subject: [PATCH] Address Anthony Mirabella's feedback about using a single point --- exporter/prometheusexporter/collector.go | 33 ++++++++---------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/exporter/prometheusexporter/collector.go b/exporter/prometheusexporter/collector.go index 58f2969596a..e6bbdda6897 100644 --- a/exporter/prometheusexporter/collector.go +++ b/exporter/prometheusexporter/collector.go @@ -210,36 +210,25 @@ func (c *collector) convertIntHistogram(metric pdata.Metric) (prometheus.Metric, } func (c *collector) convertSummary(metric pdata.Metric) (prometheus.Metric, error) { - dataPoints := metric.Summary().DataPoints() + // TODO: In the off chance that we have multiple points + // within the same metric, how should we handle them? + point := metric.Summary().DataPoints().At(0) - var cumSum float64 - var cumCount uint64 quantiles := make(map[float64]float64) - labelsMap := pdata.NewStringMap() - for i := 0; i < dataPoints.Len(); i++ { - sdpi := dataPoints.At(i) - qv := sdpi.QuantileValues() - for j := 0; j < qv.Len(); j++ { - qvj := qv.At(j) - // There should be EXACTLY one quantile value lest it is an invalid exposition. - quantiles[qvj.Quantile()] = qvj.Value() - } - // Copy all the label map values. - sdpi.LabelsMap().ForEach(func(key, value string) { - labelsMap.Insert(key, value) - }) - cumSum += sdpi.Sum() - cumCount += sdpi.Count() + qv := point.QuantileValues() + for j := 0; j < qv.Len(); j++ { + qvj := qv.At(j) + // There should be EXACTLY one quantile value lest it is an invalid exposition. + quantiles[qvj.Quantile()] = qvj.Value() } - desc, labelValues := c.getMetricMetadata(metric, labelsMap) - m, err := prometheus.NewConstSummary(desc, cumCount, cumSum, quantiles, labelValues...) + desc, labelValues := c.getMetricMetadata(metric, point.LabelsMap()) + m, err := prometheus.NewConstSummary(desc, point.Count(), point.Sum(), quantiles, labelValues...) if err != nil { return nil, err } if c.sendTimestamps { - ip := dataPoints.At(0) - return prometheus.NewMetricWithTimestamp(ip.Timestamp().AsTime(), m), nil + return prometheus.NewMetricWithTimestamp(point.Timestamp().AsTime(), m), nil } return m, nil }