Skip to content

Commit

Permalink
Separate Liveness check proc to not block requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rodgerjohnson committed Mar 12, 2024
1 parent 89b3d5c commit fd6aead
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ volumes:
services:
exporter:
build: .
# env_file:
# - path: ./.env
ports:
- "8000:8000"
- "8001:8001"
expose:
- 8080
networks:
Expand Down
13 changes: 10 additions & 3 deletions src/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from wsgiref.simple_server import make_server
from prometheus_client import REGISTRY, make_wsgi_app
from metrics import PrometheusCustomCollector

import threading

def return200(_, start_fn):
"""Wsgi http response function."""
Expand All @@ -21,16 +21,23 @@ def exporter(environ, start_fn): # pylint: disable=inconsistent-return-statemen
match environ['PATH_INFO']:
case '/metrics':
return metrics_app(environ, start_fn)
case _:
return return404(environ, start_fn)

def liveness(environ, start_fn):
match environ['PATH_INFO']:
case '/readiness':
return return200(environ, start_fn)
case '/liveness':
return return200(environ, start_fn)
case _:
return return404(environ, start_fn)

def start_liveness():
httpd = make_server('', 8001, liveness)
httpd.serve_forever()

if __name__ == '__main__':
REGISTRY.register(PrometheusCustomCollector())
metrics_app = make_wsgi_app()
liveness_thread = threading.Thread(target=start_liveness).start()
httpd = make_server('', 8000, exporter)
httpd.serve_forever()

0 comments on commit fd6aead

Please sign in to comment.