MCPcopy Index your code
hub / github.com/prometheus/client_python / make_asgi_app

Function make_asgi_app

prometheus_client/asgi.py:8–40  ·  view source on GitHub ↗

Create a ASGI app which serves the metrics from a registry.

(registry: Collector = REGISTRY, disable_compression: bool = False)

Source from the content-addressed store, hash-verified

6
7
8def make_asgi_app(registry: Collector = REGISTRY, disable_compression: bool = False) -> Callable:
9 """Create a ASGI app which serves the metrics from a registry."""
10
11 async def prometheus_app(scope, receive, send):
12 assert scope.get("type") == "http"
13 # Prepare parameters
14 params = parse_qs(scope.get('query_string', b'').decode("utf8"))
15 accept_header = ",".join([
16 value.decode("utf8") for (name, value) in scope.get('headers')
17 if name.decode("utf8").lower() == 'accept'
18 ])
19 accept_encoding_header = ",".join([
20 value.decode("utf8") for (name, value) in scope.get('headers')
21 if name.decode("utf8").lower() == 'accept-encoding'
22 ])
23 # Bake output
24 status, headers, output = _bake_output(registry, accept_header, accept_encoding_header, params, disable_compression)
25 formatted_headers = []
26 for header in headers:
27 formatted_headers.append(tuple(x.encode('utf8') for x in header))
28 # Return output
29 payload = await receive()
30 if payload.get("type") == "http.request":
31 await send(
32 {
33 "type": "http.response.start",
34 "status": int(status.split(' ')[0]),
35 "headers": formatted_headers,
36 }
37 )
38 await send({"type": "http.response.body", "body": output})
39
40 return prometheus_app

Callers 8

simple_client.pyFile · 0.90
validate_metricsMethod · 0.90
test_gzipMethod · 0.90
test_gzip_disabledMethod · 0.90
test_qs_parsingMethod · 0.90
test_qs_parsing_multiMethod · 0.90

Calls

no outgoing calls

Tested by 7

validate_metricsMethod · 0.72
test_gzipMethod · 0.72
test_gzip_disabledMethod · 0.72
test_qs_parsingMethod · 0.72
test_qs_parsing_multiMethod · 0.72