@cryptotaxi247 / infra / commits / d2ce99be

remove custom registry from channel exporter

Currently the exporter gets stuck sometimes, perhaps there are some concurrency issues with unregistering/registering dynamically.

Daiderd Jordan committed Jun 3, 2020 at 00:50 UTC d2ce99be395b19ba4cc8695b227cb03dc325fd77
1 file changed +11 -15
delft/eris/channel-exporter.py
+11 -15
@@ -9,13 +9,11 @@ from pprint import pprint
9 import json
10
11
12 -def new_revision_registry():
13 - return Gauge(
14 - "channel_revision",
15 - "Current revision, exported as a hack",
16 - ["channel", "revision"],
17 - registry=None
18 - )
12 +CHANNEL_REVISION = Gauge(
13 + "channel_revision",
14 + "Current revision, exported as a hack",
15 + ["channel", "revision"],
16 +)
17
18
19 CHANNEL_REQUEST_TIME = Histogram(
@@ -63,18 +61,16 @@ if __name__ == "__main__":
61 with open(sys.argv[1]) as channel_data:
62 channels = json.load(channel_data)
63
66 - previous_channel_revision = None
64 + revisions = {}
65 +
66 while True:
68 - CHANNEL_REVISION = new_revision_registry()
67 for (channel, about) in channels.items():
68 + if channel in revisions:
69 + CHANNEL_REVISION.remove(channel, revisions.pop(channel))
70 +
71 measurement = measure_channel(channel)
72 if measurement is not None:
73 CHANNEL_UPDATE_TIME.labels(channel=channel).set(measurement['timestamp'])
74 CHANNEL_REVISION.labels(channel=channel, revision=measurement['revision']).set(1)
75 CHANNEL_CURRENT.labels(channel=channel).set(int(about['current']))
75 -
76 - if previous_channel_revision is not None:
77 - REGISTRY.unregister(previous_channel_revision)
78 - REGISTRY.register(CHANNEL_REVISION)
79 - previous_channel_revision = CHANNEL_REVISION
80 - time.sleep(55)
76 + revisions[channel] = measurement['revision']