File tree 2 files changed +22
-3
lines changed
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:
41
41
return uri
42
42
43
43
44
- def log_request (handler ):
44
+ def log_request (handler , record_prometheus_metrics = True ):
45
45
"""log a bit more information about each request than tornado's default
46
46
47
47
- move static file get success to debug-level (reduces noise)
48
48
- get proxied IP instead of proxy IP
49
49
- log referer for redirect and failed requests
50
50
- 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
51
54
"""
52
55
status = handler .get_status ()
53
56
request = handler .request
@@ -97,4 +100,5 @@ def log_request(handler):
97
100
headers [header ] = request .headers [header ]
98
101
log_method (json .dumps (headers , indent = 2 ))
99
102
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 28
28
import urllib
29
29
import warnings
30
30
from base64 import encodebytes
31
+ from functools import partial
31
32
from pathlib import Path
32
33
33
34
import jupyter_client
@@ -410,7 +411,9 @@ def init_settings(
410
411
411
412
settings = {
412
413
# basics
413
- "log_function" : log_request ,
414
+ "log_function" : partial (
415
+ log_request , record_prometheus_metrics = jupyter_app .record_http_request_metrics
416
+ ),
414
417
"base_url" : base_url ,
415
418
"default_url" : default_url ,
416
419
"template_path" : template_path ,
@@ -1993,6 +1996,18 @@ def _default_terminals_enabled(self) -> bool:
1993
1996
config = True ,
1994
1997
)
1995
1998
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
+
1996
2011
static_immutable_cache = List (
1997
2012
Unicode (),
1998
2013
help = """
You can’t perform that action at this time.
0 commit comments