Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow toggling auth for prometheus metrics #344

Merged
merged 1 commit into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,10 +842,12 @@ def get(self):

class PrometheusMetricsHandler(JupyterHandler):
"""
Return prometheus metrics for this Jupyter server
Return prometheus metrics for this notebook server
"""
@web.authenticated
def get(self):
if self.settings['authenticate_prometheus'] and not self.logged_in:
raise web.HTTPError(403)

self.set_header('Content-Type', prometheus_client.CONTENT_TYPE_LATEST)
self.write(prometheus_client.generate_latest(prometheus_client.REGISTRY))

Expand Down
9 changes: 9 additions & 0 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def init_settings(self, jupyter_app, kernel_manager, contents_manager,
disable_check_xsrf=jupyter_app.disable_check_xsrf,
allow_remote_access=jupyter_app.allow_remote_access,
local_hostnames=jupyter_app.local_hostnames,
authenticate_prometheus=jupyter_app.authenticate_prometheus,

# managers
kernel_manager=kernel_manager,
Expand Down Expand Up @@ -1199,6 +1200,14 @@ def _update_server_extensions(self, change):
is not available.
"""))

authenticate_prometheus = Bool(
True,
help=""""
Require authentication to access prometheus metrics.
""",
config=True
)

def parse_command_line(self, argv=None):

super(ServerApp, self).parse_command_line(argv)
Expand Down