-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Prometheus support, core entrypoint, packaging improvements #17
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a couple of minor comments, but it looks solid to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, great stuff! I'd like to test how this looks when setting up a Grafana dashboard for these metrics.
- Add Prometheus support - Cover Gunicorn with request metrics - Add support for custom application metrics - Add `flagsmith-test-tools` pytest plugin and `assert_metric` fixture - Add `flagsmith start api` package entrypoint - Improve packaging --------- Co-authored-by: Rodrigo López Dato <[email protected]>
Overview
flagsmith-test-toolspytest plugin andassert_metricfixtureflagsmith start apipackage entrypointPrometheus
Instead of using django-prometheus, I decided to introduce the Prometheus client directly, and gradually instrument parts of our stack, starting from the HTTP server. One advantage of this decision is that, unlike django-prometheus users, we are able to label HTTP metrics by request path without performance or cardinality risks. See
PrometheusGunicornLoggerMiddlewareandPrometheusGunicornLoggercode for details.I've also added a couple of developer tools to help us implement metrics in an organised, robust manner:
assert_metricPytest fixture is installed as part of theflagsmith-test-toolsPytest plugin along with this package.with_labelsutility function makes sure you always send a default"unknown"value to Prometheus for missing or null metric values. This greatly simplifies metric usage.metrics.pymodules contained in your Django application are autodiscovered, which makes it possible to advertise your metrics globally — seeflagsmith_build_infofor an example.Existing default metrics and a guideline for adding user metrics are added in the README.
Entrypoint
The library now installs a
flagsmithentrypoint, which is essentially amanage.pyscript that we can modify as needed. I've added aflagsmith start apicommand that runs the Gunicorn web server, ensuring some important defaults:The idea is that any
flagsmith startsubcommand command will accept Gunicorn arguments, as the base endpoints, includinghealth*,versionandmetricswill always be served by Gunicorn.The next PR will add an implementation of the
flagsmith start task-processorcommand.My hope is that we'll be able to eventually replace
run-docker.shwith this, which should help us ship binaries for customers that can't support Docker.Packaging
I've added the following improvements ahead of publishing the package on PyPI: