fix race condition in channel exporter
This ensures the revision metric doesn't disappear while it's being updated.
Daiderd Jordan committed
Jun 3, 2020 at 20:24 UTC
0486753b1ce33b5ab447840678c4fe7a662bd6c1
1 file changed
+6
-4
delft/eris/channel-exporter.py
+6
-4
@@ -65,12 +65,14 @@ if __name__ == "__main__":
65
66
while True:
67
for (channel, about) in channels.items():
68
- if channel in revisions:
69
- CHANNEL_REVISION.remove(channel, revisions.pop(channel))
70
-
68
measurement = measure_channel(channel)
69
if measurement is not None:
70
+ revision = measurement['revision']
71
CHANNEL_UPDATE_TIME.labels(channel=channel).set(measurement['timestamp'])
72
CHANNEL_REVISION.labels(channel=channel, revision=measurement['revision']).set(1)
73
CHANNEL_CURRENT.labels(channel=channel).set(int(about['current']))
76
- revisions[channel] = measurement['revision']
74
+ print('updated {}'.format(channel))
75
+ previous_revision = revisions.pop(channel, None)
76
+ revisions[channel] = revision
77
+ if previous_revision and previous_revision != revision:
78
+ CHANNEL_REVISION.remove(channel, previous_revision)