Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid exports in AppConfig when running management commands #441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

olzhasar-reef
Copy link

Currently, migrations are being exported inside the ready() method of the django_prometheus.apps.AppConfig. This works fine for a default threaded prometheus mode, but leads to malformed metrics when using prometheus in multiprocess mode.

Consider the following typical deployment entrypoint:

# entrypoint.sh

./manage.py migrate  # - here metrics are exported for the pid
gunicorn some.app.wsgi - # metrics are exported again for different pid(s)

This leads to problems like this:

django_migrations_unapplied_total{connection="default",pid="16241"} 0.0                         
django_migrations_unapplied_total{connection="default",pid="16234"} 1.0                         
django_migrations_unapplied_total{connection="default",pid="16251"} 0.0                         
django_migrations_unapplied_total{connection="default",pid="16239"} 1.0                         
django_migrations_unapplied_total{connection="default",pid="16248"} 0.0                         
django_migrations_unapplied_total{connection="default",pid="16258"} 0.0                         
django_migrations_unapplied_total{connection="default",pid="16249"} 0.0                                                                                                                         
django_migrations_unapplied_total{connection="default",pid="16246"} 0.0  

This PR introduces a simple check to avoid exporting metrics in manage.py commands

@olzhasar-reef olzhasar-reef force-pushed the skip-export-migrations-in-commands branch from 03094e0 to 00c596f Compare October 24, 2024 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant