client_python icon indicating copy to clipboard operation
client_python copied to clipboard

Set label-specific timestamps

Open z3rone opened this issue 1 year ago • 2 comments

Issue #588 describes a way to set a timestamp for a whole metric using a custom collector. However, this solution does not work if different timestamps for different labels are required (e.g. a metric temperature with label source=node1 and source=node2) a more specific setting is described here and additional reasoning for this feature can be found here.

As issue #588 is closed and does not seem to get much attention anymore I decided to create a new issue for this more specific use case.

z3rone avatar Jun 05 '23 15:06 z3rone

A workaround to set timestamp for each set of labels: https://github.com/prometheus/client_python/issues/588#issuecomment-1769119164

chriskhanhtran avatar Oct 18 '23 18:10 chriskhanhtran

Before this is closed with something like "there's no valid use cases for having a timestamp with direct instrumentation", here is an additional use case:

We are proxy-ing metrics from a source that has severe rate-limiting restrictions, so we need to query it every minute and in each minute we get a sequence of many events (e.g. "started", "progress", "completed") which are correlated by labels. We want the events to show in Prometheus in chronological order instead of all events every minute when the gauge is updated by the proxy.

If Prometheus would know when each event occurred it would store them in the correct order. How to achieve this? The suggested workaround looks like a hack, is there a cleaner method such as my_gauge.labels(my_labels).set(my_value).timestamp(my_timestamp)?

alecz20 avatar Dec 12 '23 20:12 alecz20