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

Function make_wsgi_app

prometheus_client/exposition.py:131–163  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

129
130
131def make_wsgi_app(registry: Collector = REGISTRY, disable_compression: bool = False) -> Callable:
132 """Create a WSGI app which serves the metrics from a registry."""
133
134 def prometheus_app(environ, start_response):
135 # Prepare parameters
136 accept_header = environ.get('HTTP_ACCEPT')
137 accept_encoding_header = environ.get('HTTP_ACCEPT_ENCODING')
138 params = parse_qs(environ.get('QUERY_STRING', ''))
139 method = environ['REQUEST_METHOD']
140
141 if method == 'OPTIONS':
142 status = '200 OK'
143 headers = [('Allow', 'OPTIONS,GET')]
144 output = b''
145 elif method != 'GET':
146 status = '405 Method Not Allowed'
147 headers = [('Allow', 'OPTIONS,GET')]
148 output = '# HTTP {}: {}; use OPTIONS or GET\n'.format(status, method).encode()
149 elif environ['PATH_INFO'] == '/favicon.ico':
150 # Serve empty response for browsers
151 status = '200 OK'
152 headers = []
153 output = b''
154 else:
155 # Note: For backwards compatibility, the URI path for GET is not
156 # constrained to the documented /metrics, but any path is allowed.
157 # Bake output
158 status, headers, output = _bake_output(registry, accept_header, accept_encoding_header, params, disable_compression)
159 # Return output
160 start_response(status, headers)
161 return [output]
162
163 return prometheus_app
164
165
166class _SilentHandler(WSGIRequestHandler):

Callers 5

validate_metricsMethod · 0.90
test_favicon_pathMethod · 0.90
test_gzipMethod · 0.90
test_gzip_disabledMethod · 0.90
start_wsgi_serverFunction · 0.85

Calls

no outgoing calls

Tested by 4

validate_metricsMethod · 0.72
test_favicon_pathMethod · 0.72
test_gzipMethod · 0.72
test_gzip_disabledMethod · 0.72