Starts a WSGI server for prometheus metrics as a daemon thread.
(
port: int,
addr: str = '0.0.0.0',
registry: Collector = REGISTRY,
certfile: Optional[str] = None,
keyfile: Optional[str] = None,
client_cafile: Optional[str] = None,
client_capath: Optional[str] = None,
protocol: int = ssl.PROTOCOL_TLS_SERVER,
client_auth_required: bool = False,
)
| 231 | |
| 232 | |
| 233 | def start_wsgi_server( |
| 234 | port: int, |
| 235 | addr: str = '0.0.0.0', |
| 236 | registry: Collector = REGISTRY, |
| 237 | certfile: Optional[str] = None, |
| 238 | keyfile: Optional[str] = None, |
| 239 | client_cafile: Optional[str] = None, |
| 240 | client_capath: Optional[str] = None, |
| 241 | protocol: int = ssl.PROTOCOL_TLS_SERVER, |
| 242 | client_auth_required: bool = False, |
| 243 | ) -> Tuple[WSGIServer, threading.Thread]: |
| 244 | """Starts a WSGI server for prometheus metrics as a daemon thread.""" |
| 245 | |
| 246 | class TmpServer(ThreadingWSGIServer): |
| 247 | """Copy of ThreadingWSGIServer to update address_family locally""" |
| 248 | |
| 249 | TmpServer.address_family, addr = _get_best_family(addr, port) |
| 250 | app = make_wsgi_app(registry) |
| 251 | httpd = make_server(addr, port, app, TmpServer, handler_class=_SilentHandler) |
| 252 | if certfile and keyfile: |
| 253 | context = _get_ssl_ctx(certfile, keyfile, protocol, client_cafile, client_capath, client_auth_required) |
| 254 | httpd.socket = context.wrap_socket(httpd.socket, server_side=True) |
| 255 | t = threading.Thread(target=httpd.serve_forever) |
| 256 | t.daemon = True |
| 257 | t.start() |
| 258 | |
| 259 | return httpd, t |
| 260 | |
| 261 | |
| 262 | start_http_server = start_wsgi_server |
nothing calls this directly
no test coverage detected