From f16a5285d4679c7a43a82e42317da876921a852e Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Sun, 11 Aug 2024 13:10:16 +0530 Subject: [PATCH] Fix doc issues --- docs/requirements.txt | 2 +- proxy/http/server/metrics.py | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 1b3b1533bc..6eb5b29171 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile --allow-unsafe --generate-hashes --output-file=docs/requirements.txt --strip-extras docs/requirements.in diff --git a/proxy/http/server/metrics.py b/proxy/http/server/metrics.py index 55a306cac3..e95d719ceb 100644 --- a/proxy/http/server/metrics.py +++ b/proxy/http/server/metrics.py @@ -10,7 +10,7 @@ """ import os import glob -from typing import TYPE_CHECKING, Any, Dict, List, Tuple, Generator +from typing import Any, Dict, List, Tuple, Generator, cast from pathlib import Path from urllib.parse import parse_qs, urlparse from multiprocessing.synchronize import Lock @@ -27,10 +27,6 @@ ) -if TYPE_CHECKING: - from prometheus_client.registry import Collector - - flags.add_argument( '--enable-metrics', action='store_true', @@ -92,12 +88,7 @@ def _set_gauge(self, name: str, value: float) -> None: g.write(str(value)) -def get_collector(metrics_lock: Lock) -> 'Collector': - """ - Returns an instance of the `Collector` class. - - :rtype: prometheus_client.core.Collector - """ +def get_collector(metrics_lock: Lock) -> Any: # pylint: disable=import-outside-toplevel from prometheus_client.core import Metric from prometheus_client.registry import Collector @@ -195,10 +186,11 @@ class MetricsWebServerPlugin(HttpWebServerBasePlugin): def __init__(self, *args: Any, **kwargs: Any) -> None: # pylint: disable=import-outside-toplevel from prometheus_client.core import CollectorRegistry + from prometheus_client.registry import Collector super().__init__(*args, **kwargs) self.registry = CollectorRegistry() - self.registry.register(get_collector(self.flags.metrics_lock)) + self.registry.register(cast(Collector, get_collector(self.flags.metrics_lock))) def routes(self) -> List[Tuple[int, str]]: if self.flags.metrics_path: