|
4 | 4 | Read https://prometheus.io/docs/practices/naming/ for naming
|
5 | 5 | conventions for metrics & labels.
|
6 | 6 | """
|
7 |
| -# Do this to see if we end up in an import loop? |
8 |
| -from notebook.prometheus.metrics import ( |
9 |
| - HTTP_REQUEST_DURATION_SECONDS, |
10 |
| - KERNEL_CURRENTLY_RUNNING_TOTAL, |
11 |
| - TERMINAL_CURRENTLY_RUNNING_TOTAL, |
12 |
| -) |
| 7 | +from prometheus_client import Info, Gauge, Histogram |
13 | 8 |
|
14 | 9 | try:
|
15 |
| - # Jupyter Notebook also defines these metrics. Re-defining them results in a ValueError. |
16 |
| - # Try to de-duplicate by using the ones in Notebook if available. |
| 10 | + from notebook._version import version_info as notebook_version_info |
| 11 | +except ImportError: |
| 12 | + notebook_version_info = None |
| 13 | + |
| 14 | +if not notebook_version_info >= (7,): |
| 15 | + # Jupyter Notebook v6 also defined these metrics. Re-defining them results in a ValueError, |
| 16 | + # so we simply re-export them if we are co-existing with the notebook v6 package. |
17 | 17 | # See https://github.com/jupyter/jupyter_server/issues/209
|
18 | 18 | from notebook.prometheus.metrics import (
|
19 | 19 | HTTP_REQUEST_DURATION_SECONDS,
|
20 | 20 | KERNEL_CURRENTLY_RUNNING_TOTAL,
|
21 | 21 | TERMINAL_CURRENTLY_RUNNING_TOTAL,
|
22 | 22 | )
|
23 |
| - |
24 |
| -except ImportError: |
25 |
| - from prometheus_client import Gauge, Histogram |
26 |
| - |
| 23 | +else: |
27 | 24 | HTTP_REQUEST_DURATION_SECONDS = Histogram(
|
28 | 25 | "http_request_duration_seconds",
|
29 | 26 | "duration in seconds for all HTTP requests",
|
|
41 | 38 | ["type"],
|
42 | 39 | )
|
43 | 40 |
|
44 |
| - |
45 |
| -from prometheus_client import Info |
46 |
| - |
| 41 | +# New prometheus metrics that do not exist in notebook v6 go here |
47 | 42 | SERVER_INFO = Info("jupyter_server", "Jupyter Server Version information")
|
48 | 43 |
|
49 | 44 | __all__ = [
|
|
0 commit comments