Skip to content

Commit 147b231

Browse files
committed
Soft-deprecate /metrics endpoint
/metrics is where notebook server publishes prometheus metrics. Currently, if nbresuse is installed, it's impossible to get prometheus metrics out of running notebooks. Just removing /metrics caused issues with third-party code (#36) that depended on the JSON API from the endpoint, and so was reverted. Instead, we 'soft' deprecate that endpoint. 1. Re-add /api/metrics/v1 endpoint, with exact same semantics as /metrics. This is enabled unconditionally. 2. /metrics is also enabled by default, but can be turned off with a notebook config. This allows admins who need prometheus metrics to turn it on. 3. The bundled notebook extension will read from /api/metrics/v1 endpoint, so for those users things will 'just work'. The path to removing /metrics is: 1. Release this as 0.4.0 even though there aren't any breaking changes. This makes it easier for code using legacy endpoints to simply pin to nbresuse<0.4.0 2. Find third party users relying on /metrics, and simply change them to use /api/metrics/v1 - should be a fairly simple change. They can then be pin to nbresuse>=0.4.0 3. When we're sure enough packages have switched, we can release a 0.5.0 where /metrics is disabled by default, but enablable with a config. 4. Eventually, we can simply remove /metrics and the associated config. Ref #36
1 parent de920c0 commit 147b231

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

nbresuse/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ def load_jupyter_server_extension(nbapp):
3535
resuseconfig = ResourceUseDisplay(parent=nbapp)
3636
nbapp.web_app.settings["nbresuse_display_config"] = resuseconfig
3737
base_url = nbapp.web_app.settings["base_url"]
38+
39+
if not resuseconfig.disable_legacy_endpoint:
40+
nbapp.web_app.add_handlers(
41+
".*", [(url_path_join(base_url, "/metrics"), ApiHandler)]
42+
)
43+
3844
nbapp.web_app.add_handlers(
39-
".*", [(url_path_join(base_url, "/metrics"), ApiHandler)]
45+
".*", [(url_path_join(base_url, "/api/metrics/v1"), ApiHandler)]
4046
)
47+
4148
callback = ioloop.PeriodicCallback(
4249
PrometheusHandler(PSUtilMetricsLoader(nbapp)), 1000
4350
)

nbresuse/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ class ResourceUseDisplay(Configurable):
3636
"""
3737
Holds server-side configuration for nbresuse
3838
"""
39+
disable_legacy_endpoint = Bool(
40+
True,
41+
help="""
42+
Disable legacy /metrics endpoint
43+
44+
This prevents nbresuse from shadowing the prometheus /metrics endpoint.
45+
""",
46+
config=True
47+
)
3948

4049
process_memory_metrics = List(
4150
trait=PSUtilMetric(),

nbresuse/static/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ define([
3434
return;
3535
}
3636
$.getJSON({
37-
url: utils.get_body_data('baseUrl') + 'metrics',
37+
url: utils.get_body_data('baseUrl') + 'api/metrics/v1',
3838
success: function (data) {
3939
totalMemoryUsage = humanFileSize(data['rss']);
4040

0 commit comments

Comments
 (0)