Skip to content

Commit dedf3cf

Browse files
committed
feat: add healthcheck for metrics endpoint and improve latency observation
1 parent 0928fb3 commit dedf3cf

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ USER nonroot
2424
WORKDIR /app/src
2525
EXPOSE 8000
2626
CMD ["python", "-m", "python_response_time.main"]
27+
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
28+
CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/metrics').read()" || exit 1

src/python_response_time/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def run_app():
8686
}
8787
)
8888
REQUEST_COUNT.labels(status=str(response.status_code)).inc()
89-
REQUEST_LATENCY.observe(elapsed)
89+
REQUEST_LATENCY.labels(status=str(response.status_code)).observe(
90+
elapsed
91+
)
9092
except requests.exceptions.SSLError as e:
9193
console.print(f"{i + 1:>4} | SSL ERROR")
9294
logger.error(

0 commit comments

Comments
 (0)