Skip to content

Avoid exports in AppConfig when running management commands#441

Closed
olzhasar-reef wants to merge 1 commit into
django-commons:masterfrom
olzhasar-reef:skip-export-migrations-in-commands
Closed

Avoid exports in AppConfig when running management commands#441
olzhasar-reef wants to merge 1 commit into
django-commons:masterfrom
olzhasar-reef:skip-export-migrations-in-commands

Conversation

@olzhasar-reef

Copy link
Copy Markdown

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
@olzhasar-reef

Copy link
Copy Markdown
Author

Is there anything that could be done to move this forward?

@olzhasar-reef

Copy link
Copy Markdown
Author

Closing in favor of #499

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