File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -41,13 +41,16 @@ def _scrub_uri(uri: str) -> str:
4141 return uri
4242
4343
44- def log_request (handler ):
44+ def log_request (handler , record_prometheus_metrics = True ):
4545 """log a bit more information about each request than tornado's default
4646
4747 - move static file get success to debug-level (reduces noise)
4848 - get proxied IP instead of proxy IP
4949 - log referer for redirect and failed requests
5050 - log user-agent for failed requests
51+
52+ if record_prometheus_metrics is true, will record a histogram prometheus
53+ metric (http_request_duration_seconds) for each request handler
5154 """
5255 status = handler .get_status ()
5356 request = handler .request
@@ -97,4 +100,5 @@ def log_request(handler):
97100 headers [header ] = request .headers [header ]
98101 log_method (json .dumps (headers , indent = 2 ))
99102 log_method (msg .format (** ns ))
100- prometheus_log_method (handler )
103+ if record_prometheus_metrics :
104+ prometheus_log_method (handler )
Original file line number Diff line number Diff line change 2828import urllib
2929import warnings
3030from base64 import encodebytes
31+ from functools import partial
3132from pathlib import Path
3233
3334import jupyter_client
@@ -410,7 +411,9 @@ def init_settings(
410411
411412 settings = {
412413 # basics
413- "log_function" : log_request ,
414+ "log_function" : partial (
415+ log_request , record_prometheus_metrics = jupyter_app .record_http_request_metrics
416+ ),
414417 "base_url" : base_url ,
415418 "default_url" : default_url ,
416419 "template_path" : template_path ,
@@ -1993,6 +1996,18 @@ def _default_terminals_enabled(self) -> bool:
19931996 config = True ,
19941997 )
19951998
1999+ record_http_request_metrics = Bool (
2000+ True ,
2001+ help = """
2002+ Record http_request_duration_seconds metric in the metrics endpoint.
2003+
2004+ Since a histogram is exposed for each request handler, this can create a
2005+ *lot* of metrics, creating operational challenges for multitenant deployments.
2006+
2007+ Set to False to disable recording the http_request_duration_seconds metric.
2008+ """ ,
2009+ )
2010+
19962011 static_immutable_cache = List (
19972012 Unicode (),
19982013 help = """
You can’t perform that action at this time.
0 commit comments