Skip to content

Commit

Permalink
Address Anthony Mirabella's feedback about using a single point
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed Apr 9, 2021
1 parent 4234682 commit c36b80c
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions exporter/prometheusexporter/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit c36b80c

Please sign in to comment.