Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion prometheus_client/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def _accumulate_metrics(metrics, accumulate):
elif metric._multiprocess_mode in ('mostrecent', 'livemostrecent'):
current_timestamp = sample_timestamps[labels][name]
timestamp = float(timestamp or 0)
if current_timestamp < timestamp:
if (name, labels) not in samples[labels] or current_timestamp < timestamp:
samples[labels][(name, labels)] = value
sample_timestamps[labels][name] = timestamp
else: # all/liveall
Expand Down
10 changes: 10 additions & 0 deletions tests/test_multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ def test_gauge_livemostrecent(self):
mark_process_dead(123, os.environ['PROMETHEUS_MULTIPROC_DIR'])
self.assertEqual(2, self.registry.get_sample_value('g'))

def test_gauge_mostrecent_never_set(self):
# A child created but never set() has a stored timestamp of 0. It must
# still be reported as 0, like every other gauge mode, rather than
# dropped from collection because 0 is not strictly greater than the
# default timestamp of 0.
Gauge('g', 'help', registry=None, multiprocess_mode='mostrecent')
values.ValueClass = MultiProcessValue(lambda: 456)
Gauge('g', 'help', registry=None, multiprocess_mode='mostrecent')
self.assertEqual(0, self.registry.get_sample_value('g'))

def test_namespace_subsystem(self):
c1 = Counter('c', 'help', registry=None, namespace='ns', subsystem='ss')
c1.inc(1)
Expand Down