goauthentik / goauthentik/authentik

Regression of `django_migrations_unapplied_total` metric's availability

Open
#9,941 9 comments 0 reactions 1 assignee Claimed by @rissson View on GitHub
bug status/reviewing
Dominant language
Python
Stars
25.6k
Forks
2k
Avg merge
1d 1h
Merged PRs (30d)
644

Description

**Describe the bug**
The helm charts indicate that there's a metric `django_migrations_unapplied_total` to check if all DB migrations were properly applied[1].

**To Reproduce**
* Configure a prometheus endpoint
* Send GET a request against `/metrics` : `django_http_*` metrics will be there, `django_migrations_*` won't.

**Expected behavior**
To have this metric available.

**Screenshots**
n/a

**Logs**
n/a

**Version and Deployment (please complete the following information):**

- authentik version: 2024.4.2
- Deployment: [custom](https://github.com/nix-community/authentik-nix/)

**Additional context**
I managed to identify two issues:
* `django-prometheus` requires you to explicitly turn this on nowadays[2]. This can be fixed by adding `PROMETHEUS_EXPORT_MIGRATIONS` to `authentik.root.settings`:
```diff
diff --git a/authentik/root/settings.py b/authentik/root/settings.py
index 15e689b06..7668a444b 100644
--- a/authentik/root/settings.py
+++ b/authentik/root/settings.py
@@ -19,6 +19,7 @@ from authentik.stages.password import BACKEND_APP_PASSWORD, BACKEND_INBUILT, BAC

BASE_DIR = Path(__file__).absolute().parent.parent.parent

+PROMETHEUS_EXPORT_MIGRATIONS = True
DEBUG = CONFIG.get_bool("debug")
SECRET_KEY = CONFIG.get("secret_key")

```

* For some reason I can't explain this option doesn't have any effect until you remove the `run_migrations()` invocation from the gunicorn config. I can't explain way which is why I refrain from filing a patch for now.
EDIT: for it to work currently, you also need to set `preload_app` to `False`.

[1] https://github.com/goauthentik/helm/blob/main/charts/authentik/templates/prometheusrule.yaml#L142C36-L142C69
[2] https://github.com/korfuri/django-prometheus/pull/425

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.