Skip to content

Commit

Permalink
Merge pull request #68 from yuvipanda/legacy-api-endpoint
Browse files Browse the repository at this point in the history
Soft-deprecate /metrics endpoint
  • Loading branch information
jtpio authored Nov 19, 2020
2 parents de920c0 + 87c306f commit 1d7b8d4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
9 changes: 8 additions & 1 deletion nbresuse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ def load_jupyter_server_extension(nbapp):
resuseconfig = ResourceUseDisplay(parent=nbapp)
nbapp.web_app.settings["nbresuse_display_config"] = resuseconfig
base_url = nbapp.web_app.settings["base_url"]

if not resuseconfig.disable_legacy_endpoint:
nbapp.web_app.add_handlers(
".*", [(url_path_join(base_url, "/metrics"), ApiHandler)]
)

nbapp.web_app.add_handlers(
".*", [(url_path_join(base_url, "/metrics"), ApiHandler)]
".*", [(url_path_join(base_url, "/api/metrics/v1"), ApiHandler)]
)

callback = ioloop.PeriodicCallback(
PrometheusHandler(PSUtilMetricsLoader(nbapp)), 1000
)
Expand Down
10 changes: 10 additions & 0 deletions nbresuse/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ class ResourceUseDisplay(Configurable):
Holds server-side configuration for nbresuse
"""

disable_legacy_endpoint = Bool(
True,
help="""
Disable legacy /metrics endpoint
This prevents nbresuse from shadowing the prometheus /metrics endpoint.
""",
config=True,
)

process_memory_metrics = List(
trait=PSUtilMetric(),
default_value=[{"name": "memory_info", "attribute": "rss"}],
Expand Down
2 changes: 1 addition & 1 deletion nbresuse/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ define([
return;
}
$.getJSON({
url: utils.get_body_data('baseUrl') + 'metrics',
url: utils.get_body_data('baseUrl') + 'api/metrics/v1',
success: function (data) {
totalMemoryUsage = humanFileSize(data['rss']);

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setuptools.setup(
name="nbresuse",
version="0.3.6",
version="0.4.0",
url="https://github.com/yuvipanda/nbresuse",
author="Yuvi Panda",
description="Simple Jupyter extension to show how much resources (RAM) your notebook is using",
Expand Down

0 comments on commit 1d7b8d4

Please sign in to comment.