client_python
client_python copied to clipboard
Set label-specific timestamps
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.
A workaround to set timestamp for each set of labels: https://github.com/prometheus/client_python/issues/588#issuecomment-1769119164
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)
?