-
-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix double init of prometheus metrics (#2544)
Tornado handlers are initaliazed multiple times within the same python interpreter process (once per request). Adding new prometheus gauges/counters every time leads to `ValueError: Duplicated timeseries` errors because `prometheus_client` has one single, global registry to track all known metrics. Instead, use the collector mechanism which is the recommended way to generate metrics. Also, enable prometheus tests for worker and add `prometheus_client` to the official dev requirements.
- Loading branch information
1 parent
df4b70c
commit b800a35
Showing
5 changed files
with
124 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ ipython >= 5.0.0 | |
jupyter_client >= 4.4.0 | ||
ipykernel >= 4.5.2 | ||
pytest >= 3.0.5 | ||
prometheus_client >= 0.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pytest | ||
pytest.importorskip('bokeh') | ||
|
||
from tornado.httpclient import AsyncHTTPClient | ||
from distributed.utils_test import gen_cluster | ||
from distributed.bokeh.worker import BokehWorker | ||
|
||
|
||
@gen_cluster(client=True, | ||
worker_kwargs={'services': {('bokeh', 0): BokehWorker}}) | ||
def test_prometheus(c, s, a, b): | ||
pytest.importorskip('prometheus_client') | ||
from prometheus_client.parser import text_string_to_metric_families | ||
|
||
http_client = AsyncHTTPClient() | ||
|
||
# request data twice since there once was a case where metrics got registered multiple times resulting in | ||
# prometheus_client errors | ||
for _ in range(2): | ||
response = yield http_client.fetch('http://localhost:%d/metrics' | ||
% a.services['bokeh'].port) | ||
assert response.code == 200 | ||
assert response.headers['Content-Type'] == 'text/plain; version=0.0.4' | ||
|
||
txt = response.body.decode('utf8') | ||
families = { | ||
familiy.name | ||
for familiy in text_string_to_metric_families(txt) | ||
} | ||
assert len(families) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters