Skip to content

Commit

Permalink
include timestamp in samples returned by MultiProcessCollector._accum…
Browse files Browse the repository at this point in the history
…ulate_metrics
  • Loading branch information
roganartu committed Aug 19, 2024
1 parent 7c45f84 commit ea68bfe
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions prometheus_client/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ def _accumulate_metrics(metrics, accumulate):
sample_timestamps = defaultdict(float)
buckets = defaultdict(lambda: defaultdict(float))
samples_setdefault = samples.setdefault
generate_pidless_key = lambda x, y: (x, tuple(l for l in y if l[0] != 'pid'))
for s in metric.samples:
name, labels, value, timestamp, exemplar = s
if metric.type == 'gauge':
without_pid_key = (name, tuple(l for l in labels if l[0] != 'pid'))
without_pid_key = generate_pidless_key(name, labels)
if metric._multiprocess_mode in ('min', 'livemin'):
current = samples_setdefault(without_pid_key, value)
if value < current:
Expand Down Expand Up @@ -150,7 +151,13 @@ def _accumulate_metrics(metrics, accumulate):
samples[(metric.name + '_count', labels)] = acc

# Convert to correct sample format.
metric.samples = [Sample(name_, dict(labels), value) for (name_, labels), value in samples.items()]
timestamped_samples = []
for (name_, labels), value in samples.items():
without_pid_key = generate_pidless_key(name_, labels)
timestamped_samples.append(
Sample(name_, dict(labels), value), sample_timestamps[without_pid_key]
)
metric.samples = timestamped_samples
return metrics.values()

def collect(self):
Expand Down

0 comments on commit ea68bfe

Please sign in to comment.