From ab157afe20f8e814d61c5e35e3cb49ce4e3f395f Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Wed, 6 Nov 2019 16:35:27 -0800 Subject: [PATCH] sheetsync: Clear event counts before each update Otherwise, no count of 0 ever gets set, and things are left showing values when they shouldn't. --- sheetsync/setup.py | 2 +- sheetsync/sheetsync/main.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sheetsync/setup.py b/sheetsync/setup.py index 32933cc..5627eb7 100644 --- a/sheetsync/setup.py +++ b/sheetsync/setup.py @@ -7,7 +7,7 @@ setup( install_requires = [ "argh", "gevent", - "prometheus-client", + "prometheus-client==0.7.1", # locked version as we rely on internals "psycogreen", "psycopg2", "python-dateutil", diff --git a/sheetsync/sheetsync/main.py b/sheetsync/sheetsync/main.py index 0466ac1..a85595c 100644 --- a/sheetsync/sheetsync/main.py +++ b/sheetsync/sheetsync/main.py @@ -201,6 +201,9 @@ class SheetSync(object): for row in result.fetchall(): by_id[row.id] = row counts[row.sheet_name, row.category, str(row.poster_moment), row.state, str(bool(row.error))] += 1 + # Reach into metric internals and forget about all previous values, + # or else any values we don't update will remain as a stale count. + event_counts._metrics.clear() for labels, count in counts.items(): event_counts.labels(*labels).set(count) return by_id