Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 48bf738

Browse files
authored
Send the trend count as a metric (#31)
* Send the trend count as a metric. Otherwise this information is lost when using prometheus. * Update comment.
1 parent 23f9041 commit 48bf738

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pkg/remotewrite/prometheus.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ func (pm *PrometheusMapping) MapRate(ms *metricsStorage, sample metrics.Sample,
7474
func (pm *PrometheusMapping) MapTrend(ms *metricsStorage, sample metrics.Sample, labels []prompb.Label) []prompb.TimeSeries {
7575
metric := ms.update(sample, trendAdd)
7676

77-
// Prometheus metric system does not support Trend so this mapping will store gauges
78-
// to keep track of key values.
77+
// Prometheus metric system does not support Trend so this mapping will
78+
// store a counter for the number of reported values and gauges to keep
79+
// track of aggregated values.
7980
// TODO: when Prometheus implements support for sparse histograms, re-visit this implementation
8081

8182
s := metric.Sink.(*metrics.TrendSink)
8283
aggr := map[string]float64{
84+
"count": float64(s.Count),
8385
"min": s.Min,
8486
"max": s.Max,
8587
"avg": s.Avg,
@@ -89,6 +91,18 @@ func (pm *PrometheusMapping) MapTrend(ms *metricsStorage, sample metrics.Sample,
8991
}
9092

9193
return []prompb.TimeSeries{
94+
{
95+
Labels: append(labels, prompb.Label{
96+
Name: "__name__",
97+
Value: fmt.Sprintf("%s%s_count", defaultMetricPrefix, sample.Metric.Name),
98+
}),
99+
Samples: []prompb.Sample{
100+
{
101+
Value: aggr["count"],
102+
Timestamp: timestamp.FromTime(sample.Time),
103+
},
104+
},
105+
},
92106
{
93107
Labels: append(labels, prompb.Label{
94108
Name: "__name__",

0 commit comments

Comments
 (0)