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

[WIP/experiment] Add prometheus metrics support #518

Closed
wants to merge 2 commits into from
Closed

[WIP/experiment] Add prometheus metrics support #518

wants to merge 2 commits into from

Conversation

alikins
Copy link
Contributor

@alikins alikins commented Jan 27, 2020

Note: This is mostly just an example of how prometheus metrics support could be added to pulpcore (and presumably, all the pulp plugins).

I'm looking for a more general way to set up this configuration, if that is possible.
For example, I'm not sure this is something that could be done with dynaconf
(it seems like dynaconf's django support doesn't allow changing INSTALLED_APPS or MIDDLEWARE.)

So looking for suggestions on the best way to approach this.

This enables pulpcore to export pulp metrics to
be scraped by prometheus.

It uses the django module 'django_prometheus'
django app/middleware to do this.
(https://github.com/korfuri/django-prometheus)
The result is a set of metrics exposed at /metrics

@alikins
Copy link
Contributor Author

alikins commented Jan 27, 2020

Example content of /metrics https://gist.github.com/alikins/39435297bad1637c4d3bc2edcb96f6b9

Grafana screenshot showing some basic metrics: https://imgur.com/a/xbn7uOK

@bmbouter
Copy link
Member

dynaconf will let you override the installed apps like any attribute in the settings module. Still though, I prefer the way this PR is positioning it as an optional dependency that "just works" if its installed.

@@ -115,6 +115,7 @@ def __repr__(self):
url(r'^{api_root}status/'.format(api_root=API_ROOT), StatusView.as_view()),
url(r'^{api_root}orphans/'.format(api_root=API_ROOT), OrphansView.as_view()),
url(r'^auth/', include('rest_framework.urls')),
url('', include('django_prometheus.urls')),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because django_prometheus is an optional dependency, urls must be configured conditionally too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

@pulpbot
Copy link
Member

pulpbot commented Apr 7, 2020

WARNING!!! This PR is not attached to an issue. In most cases this is not advisable. Please see our PR docs for more information about how to attach this PR to an issue.

@alikins
Copy link
Contributor Author

alikins commented Apr 7, 2020

Note: a1ac736 (making django_prometheus imports optional in urls.py) is untested at the moment

This enables pulpcore to export pulp metrics to
be scraped by prometheus.

It uses the django module 'django_prometheus'
django app/middleware to do this.
(https://github.com/korfuri/django-prometheus)

Setup the app.

Register the middleware.

Add /metrics url.

re: #6462
https://pulp.plan.io/issues/6462
Copy link
Member

@bmbouter bmbouter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding this support. Our users will appreciate it. There are two things I want to ask about:

The first is docs; it needs user facing docs explaining the url, what users need to install. Also maybe with a screenshot or two? I looked at the docs site and the place I think it makes the most sense at is as a new section titled Prometheus Integration at the bottom of the components page.

Also I think it needs a test. I believe this can be easily done if the CI folks add django_prometheus to the single-container which is the environment that tests this. Then a new test module named test_prometheus.py could be added here perhaps.

Would you be able to add ^?

Also I'll ask the installer team how they want to position an installer feature to install the optional package too.

@bmbouter
Copy link
Member

I filed the installer change here: https://pulp.plan.io/issues/6808

@RCMariko
Copy link
Contributor

And is there an issue already written up for this support? Good to see this moving forward.

@alikins
Copy link
Contributor Author

alikins commented May 27, 2020

@bmbouter I can update the examples from #518 (comment) and add some docs into docs rst somewhere.

@alikins
Copy link
Contributor Author

alikins commented May 27, 2020

@bmbouter One thing I was wondering about is if it would be useful to add a settings.py variable to explicitly disable prometheus even if the required django-prometheus modules are importable.

@alikins
Copy link
Contributor Author

alikins commented May 27, 2020

@bmbouter

dynaconf will let you override the installed apps like any attribute in the settings module. Still though, I prefer the way this PR is positioning it as an optional dependency that "just works" if its installed.

That was my first approach, but didn't have much luck getting that to work. Could be revisited.

@daviddavis
Copy link
Contributor

We're closing this until the requested changes can be made. Please reopen.

@daviddavis daviddavis closed this Jun 23, 2020
@ralphbean
Copy link

Chiming in here just to say that a user may want to see prometheus metrics around tasks - for example, their duration, total count, and error counts - in addition to the httpd request metrics already implemented here.

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.

None yet

7 participants