11"""Main module that loads Prometheus registry and starts a web-server."""
2+ import threading
23from wsgiref .simple_server import make_server
34from prometheus_client import REGISTRY , make_wsgi_app
45from metrics import PrometheusCustomCollector
56
6-
77def return200 (_ , start_fn ):
88 """Wsgi http response function."""
99 start_fn ('200 OK' , [])
@@ -21,16 +21,26 @@ def exporter(environ, start_fn): # pylint: disable=inconsistent-return-statemen
2121 match environ ['PATH_INFO' ]:
2222 case '/metrics' :
2323 return metrics_app (environ , start_fn )
24+ case _:
25+ return return404 (environ , start_fn )
26+
27+ def liveness (environ , start_fn ):
28+ """Liveness endpoint function"""
29+ match environ ['PATH_INFO' ]:
2430 case '/readiness' :
2531 return return200 (environ , start_fn )
2632 case '/liveness' :
2733 return return200 (environ , start_fn )
28- case _:
29- return return404 (environ , start_fn )
3034
35+ def start_liveness ():
36+ """Liveness thread function"""
37+ httpd_liveness = make_server ('' , 8001 , liveness )
38+ httpd_liveness .serve_forever ()
3139
3240if __name__ == '__main__' :
3341 REGISTRY .register (PrometheusCustomCollector ())
3442 metrics_app = make_wsgi_app ()
43+ liveness_thread = threading .Thread (target = start_liveness )
44+ liveness_thread .start ()
3545 httpd = make_server ('' , 8000 , exporter )
3646 httpd .serve_forever ()
0 commit comments