1919from wsgiref .simple_server import make_server , WSGIRequestHandler , WSGIServer
2020
2121from .openmetrics import exposition as openmetrics
22- from .registry import CollectorRegistry , REGISTRY
22+ from .registry import Collector , REGISTRY
2323from .utils import floatToGoString , parse_version
2424
2525__all__ = (
@@ -118,7 +118,7 @@ def _bake_output(registry, accept_header, accept_encoding_header, params, disabl
118118 return '200 OK' , headers , output
119119
120120
121- def make_wsgi_app (registry : CollectorRegistry = REGISTRY , disable_compression : bool = False ) -> Callable :
121+ def make_wsgi_app (registry : Collector = REGISTRY , disable_compression : bool = False ) -> Callable :
122122 """Create a WSGI app which serves the metrics from a registry."""
123123
124124 def prometheus_app (environ , start_response ):
@@ -223,7 +223,7 @@ def _get_ssl_ctx(
223223def start_wsgi_server (
224224 port : int ,
225225 addr : str = '0.0.0.0' ,
226- registry : CollectorRegistry = REGISTRY ,
226+ registry : Collector = REGISTRY ,
227227 certfile : Optional [str ] = None ,
228228 keyfile : Optional [str ] = None ,
229229 client_cafile : Optional [str ] = None ,
@@ -252,12 +252,12 @@ class TmpServer(ThreadingWSGIServer):
252252start_http_server = start_wsgi_server
253253
254254
255- def generate_latest (registry : CollectorRegistry = REGISTRY , escaping : str = openmetrics .UNDERSCORES ) -> bytes :
255+ def generate_latest (registry : Collector = REGISTRY , escaping : str = openmetrics .UNDERSCORES ) -> bytes :
256256 """
257257 Generates the exposition format using the basic Prometheus text format.
258258
259259 Params:
260- registry: CollectorRegistry to export data from.
260+ registry: Collector to export data from.
261261 escaping: Escaping scheme used for metric and label names.
262262
263263 Returns: UTF-8 encoded string containing the metrics in text format.
@@ -330,7 +330,7 @@ def sample_line(samples):
330330 return '' .join (output ).encode ('utf-8' )
331331
332332
333- def choose_encoder (accept_header : str ) -> Tuple [Callable [[CollectorRegistry ], bytes ], str ]:
333+ def choose_encoder (accept_header : str ) -> Tuple [Callable [[Collector ], bytes ], str ]:
334334 # Python client library accepts a narrower range of content-types than
335335 # Prometheus does.
336336 accept_header = accept_header or ''
@@ -408,7 +408,7 @@ def gzip_accepted(accept_encoding_header: str) -> bool:
408408
409409class MetricsHandler (BaseHTTPRequestHandler ):
410410 """HTTP handler that gives metrics from ``REGISTRY``."""
411- registry : CollectorRegistry = REGISTRY
411+ registry : Collector = REGISTRY
412412
413413 def do_GET (self ) -> None :
414414 # Prepare parameters
@@ -429,7 +429,7 @@ def log_message(self, format: str, *args: Any) -> None:
429429 """Log nothing."""
430430
431431 @classmethod
432- def factory (cls , registry : CollectorRegistry ) -> type :
432+ def factory (cls , registry : Collector ) -> type :
433433 """Returns a dynamic MetricsHandler class tied
434434 to the passed registry.
435435 """
@@ -444,7 +444,7 @@ def factory(cls, registry: CollectorRegistry) -> type:
444444 return MyMetricsHandler
445445
446446
447- def write_to_textfile (path : str , registry : CollectorRegistry , escaping : str = openmetrics .ALLOWUTF8 , tmpdir : Optional [str ] = None ) -> None :
447+ def write_to_textfile (path : str , registry : Collector , escaping : str = openmetrics .ALLOWUTF8 , tmpdir : Optional [str ] = None ) -> None :
448448 """Write metrics to the given path.
449449
450450 This is intended for use with the Node exporter textfile collector.
@@ -592,7 +592,7 @@ def tls_auth_handler(
592592def push_to_gateway (
593593 gateway : str ,
594594 job : str ,
595- registry : CollectorRegistry ,
595+ registry : Collector ,
596596 grouping_key : Optional [Dict [str , Any ]] = None ,
597597 timeout : Optional [float ] = 30 ,
598598 handler : Callable = default_handler ,
@@ -603,7 +603,7 @@ def push_to_gateway(
603603 'http://pushgateway.local', or 'pushgateway.local'.
604604 Scheme defaults to 'http' if none is provided
605605 `job` is the job label to be attached to all pushed metrics
606- `registry` is an instance of CollectorRegistry
606+ `registry` is a Collector, normally an instance of CollectorRegistry
607607 `grouping_key` please see the pushgateway documentation for details.
608608 Defaults to None
609609 `timeout` is how long push will attempt to connect before giving up.
@@ -641,7 +641,7 @@ def push_to_gateway(
641641def pushadd_to_gateway (
642642 gateway : str ,
643643 job : str ,
644- registry : Optional [CollectorRegistry ],
644+ registry : Optional [Collector ],
645645 grouping_key : Optional [Dict [str , Any ]] = None ,
646646 timeout : Optional [float ] = 30 ,
647647 handler : Callable = default_handler ,
@@ -652,7 +652,7 @@ def pushadd_to_gateway(
652652 'http://pushgateway.local', or 'pushgateway.local'.
653653 Scheme defaults to 'http' if none is provided
654654 `job` is the job label to be attached to all pushed metrics
655- `registry` is an instance of CollectorRegistry
655+ `registry` is a Collector, normally an instance of CollectorRegistry
656656 `grouping_key` please see the pushgateway documentation for details.
657657 Defaults to None
658658 `timeout` is how long push will attempt to connect before giving up.
@@ -702,7 +702,7 @@ def _use_gateway(
702702 method : str ,
703703 gateway : str ,
704704 job : str ,
705- registry : Optional [CollectorRegistry ],
705+ registry : Optional [Collector ],
706706 grouping_key : Optional [Dict [str , Any ]],
707707 timeout : Optional [float ],
708708 handler : Callable ,
0 commit comments