Baptiste Beauplat pushed to branch master at snapshot / snapshot
Commits: 8a5acef6 by Philipp Kern at 2025-04-26T19:41:55+02:00 Implement a health check handler This can be polled by the load balancer. If either the database is unreachable or a reboot is pending, it will signal back bad health. - - - - - 887b86f9 by Philipp Kern at 2025-04-26T19:42:31+02:00 GitLab CI: Bump postgresql version to 17 - - - - - e8d50356 by Baptiste Beauplat at 2025-04-27T10:11:20+02:00 Merge remote-tracking branch 'pkern/feat/health-check' Signed-off-by: Baptiste Beauplat <[email protected]> - - - - - 2 changed files: - .gitlab-ci.yml - web/app/snapshot/views/root.py Changes: ===================================== .gitlab-ci.yml ===================================== @@ -57,8 +57,8 @@ trixie: image: debian:trixie variables: ADDITIONAL_PACKAGES: - postgresql-15-debversion - postgresql-plperl-15 + postgresql-17-debversion + postgresql-plperl-17 bookworm: <<: *test ===================================== web/app/snapshot/views/root.py ===================================== @@ -23,8 +23,10 @@ from logging import getLogger from urllib.parse import quote +import os -from flask import Blueprint, render_template, request, current_app +from flask import Blueprint, render_template, request, current_app, \ + make_response from snapshot.lib.control_helpers import link_quote_array, get_domain from snapshot.lib.cache import cache @@ -58,6 +60,24 @@ def oldnews(): return render_template('root/misc-oldnews.html', breadcrumbs=breadcrumbs) +def health_check(): + if os.path.exists('/run/systemd/shutdown/scheduled'): + return 'Reboot pending', 503 + try: + get_snapshot_model().archives_get_list() + except Exception: + return 'No database', 503 + return 'OK', 200 + + [email protected]("/healthz") +def healthz(): + response = make_response(*health_check()) + response.mimetype = 'text/plain' + response.headers['Cache-Control'] = 'private, no-store' + return response + + def _build_crumbs(page=None): crumbs = [] View it on GitLab: https://salsa.debian.org/snapshot-team/snapshot/-/compare/432ac95fee0c1fa5e80c67fed49c8ab0176113a1...e8d50356de7f6a5209388c19865cde58098d2649 -- View it on GitLab: https://salsa.debian.org/snapshot-team/snapshot/-/compare/432ac95fee0c1fa5e80c67fed49c8ab0176113a1...e8d50356de7f6a5209388c19865cde58098d2649 You're receiving this email because of your account on salsa.debian.org.
