-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prometheus exporter should use Gauge for non-monotonic sums #1210
Comments
I'd like to pick up this issue, if that's okay @jmacd |
@Verlet64 yes please 😀 |
Amazing, thanks! Should be able to throw some time at this at the weekend. |
Hey @jmacd, I took a look at this on Sunday, and whilst I was able to pretty trivially make the export the data points as a gauge rather than a counter, by checking if the metric was monotonic or not, I feel like I'm missing something if we're talking fixing some of the related issues. As as first pass, I was thinking of adding some logic to if sum, ok := agg.(aggregation.Sum); ok && record.Descriptor().MetricKind().Monotonic() {
if err := c.exportCounter(ch, sum, numberKind, desc, labels); err != nil {
return fmt.Errorf("exporting counter: %w", err)
}
} else if sum, ok := agg.(aggregation.Sum); ok && !record.Descriptor().MetricKind().Monotonic() {
if err := c.exportGauge(ch, sum, numberKind, desc, labels); err != nil {
return fmt.Errorf("exporting counter: %w", err)
}
} And then the body of exportGauge being something like: func (c *collector) exportGauge(ch chan<- prometheus.Metric, sum aggregation.Sum, kind metric.NumberKind, desc *prometheus.Desc, labels []string) error {
v, err := sum.Sum()
if err != nil {
return fmt.Errorf("error retrieving counter: %w", err)
}
m, err := prometheus.NewConstMetric(desc, prometheus.GaugeValue, v.CoerceToFloat64(kind), labels...)
if err != nil {
return fmt.Errorf("error creating constant metric: %w", err)
}
ch <- m
return nil
} That would still result in the same observed behavior for something like a Off the back of this, I've got three questions:
Thanks! |
@Verlet64 your assumptions and conclusions are all correct. This issue calls for a minor change which you have spelled out perfectly. To your final question (3), yes, a UpDownSumObserver is the right instrument for memory allocation over time, since the measurement is a sum of bytes. |
I want to leave this open until it's stated in a specification somewhere. |
Now fixed by spec. |
The existing
exporters/metric/prometheus
exporter exports a sum for the UpDown- instruments, which leads to issues like open-telemetry/opentelemetry-go-contrib#368.The
metric.Kind
type already has a getterKind.Monotonic()
that tells us whether the Sum aggregation is an UpDown- variety or not. If the aggregation is UpDown-, Prometheus exporters should not export Counter data points, Prometheus exporters should export Gauge data points.The text was updated successfully, but these errors were encountered: