mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(fastapi): use metrics in cases where PROMETHEUS_MULTIPROC_DIR is defined
Previously, we restricted this to gunicorn to get it working on aur-dev. This change makes it usable through any backend, and also no-op if PROMETHEUS_MULTIPROC_DIR is not defined. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
cdb854259a
commit
9aa8decf40
3 changed files with 7 additions and 3 deletions
|
@ -209,9 +209,7 @@ async def index(request: Request):
|
||||||
@router.get("/metrics")
|
@router.get("/metrics")
|
||||||
async def metrics(request: Request):
|
async def metrics(request: Request):
|
||||||
registry = CollectorRegistry()
|
registry = CollectorRegistry()
|
||||||
if os.environ.get("FASTAPI_BACKEND", "") == "gunicorn": # pragma: no cover
|
if os.environ.get("PROMETHEUS_MULTIPROC_DIR", None): # pragma: no cover
|
||||||
# This case only ever happens in production, when we are running
|
|
||||||
# gunicorn. We don't test with gunicorn, so we don't cover this path.
|
|
||||||
multiprocess.MultiProcessCollector(registry)
|
multiprocess.MultiProcessCollector(registry)
|
||||||
data = generate_latest(registry)
|
data = generate_latest(registry)
|
||||||
headers = {
|
headers = {
|
||||||
|
|
|
@ -241,6 +241,7 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- AUR_CONFIG=conf/config
|
- AUR_CONFIG=conf/config
|
||||||
- TEST_RECURSION_LIMIT=${TEST_RECURSION_LIMIT}
|
- TEST_RECURSION_LIMIT=${TEST_RECURSION_LIMIT}
|
||||||
|
- PROMETHEUS_MULTIPROC_DIR=/tmp_prometheus
|
||||||
entrypoint: /docker/test-mysql-entrypoint.sh
|
entrypoint: /docker/test-mysql-entrypoint.sh
|
||||||
command: /docker/scripts/run-pytests.sh clean
|
command: /docker/scripts/run-pytests.sh clean
|
||||||
stdin_open: true
|
stdin_open: true
|
||||||
|
@ -267,6 +268,7 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- AUR_CONFIG=conf/config.sqlite
|
- AUR_CONFIG=conf/config.sqlite
|
||||||
- TEST_RECURSION_LIMIT=${TEST_RECURSION_LIMIT}
|
- TEST_RECURSION_LIMIT=${TEST_RECURSION_LIMIT}
|
||||||
|
- PROMETHEUS_MULTIPROC_DIR=/tmp_prometheus
|
||||||
entrypoint: /docker/test-sqlite-entrypoint.sh
|
entrypoint: /docker/test-sqlite-entrypoint.sh
|
||||||
command: setup-sqlite.sh run-pytests.sh clean
|
command: setup-sqlite.sh run-pytests.sh clean
|
||||||
stdin_open: true
|
stdin_open: true
|
||||||
|
@ -289,6 +291,7 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- AUR_CONFIG=conf/config
|
- AUR_CONFIG=conf/config
|
||||||
- TEST_RECURSION_LIMIT=${TEST_RECURSION_LIMIT}
|
- TEST_RECURSION_LIMIT=${TEST_RECURSION_LIMIT}
|
||||||
|
- PROMETHEUS_MULTIPROC_DIR=/tmp_prometheus
|
||||||
entrypoint: /docker/tests-entrypoint.sh
|
entrypoint: /docker/tests-entrypoint.sh
|
||||||
command: setup-sqlite.sh run-tests.sh
|
command: setup-sqlite.sh run-tests.sh
|
||||||
stdin_open: true
|
stdin_open: true
|
||||||
|
|
|
@ -22,6 +22,9 @@ while [ $# -ne 0 ]; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
rm -rf $PROMETHEUS_MULTIPROC_DIR
|
||||||
|
mkdir -p $PROMETHEUS_MULTIPROC_DIR
|
||||||
|
|
||||||
# Initialize the new database; ignore errors.
|
# Initialize the new database; ignore errors.
|
||||||
python -m aurweb.initdb 2>/dev/null || \
|
python -m aurweb.initdb 2>/dev/null || \
|
||||||
(echo "Error: aurweb.initdb failed; already initialized?" && /bin/true)
|
(echo "Error: aurweb.initdb failed; already initialized?" && /bin/true)
|
||||||
|
|
Loading…
Add table
Reference in a new issue