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

monitoring functional #26876

Merged
merged 43 commits into from
Mar 19, 2020
Merged

monitoring functional #26876

merged 43 commits into from
Mar 19, 2020

Conversation

snopoke
Copy link
Contributor

@snopoke snopoke commented Mar 17, 2020

Re-take of #26837 that takes a simplified approach.

The class based implementation was much more complex and since most of the calls are single use this approach seemed cleaner.

SUMMARY

Initial implementation of #26816

Initial code structure and classes to allow supporting multiple monitoring backends. Current support for Datadog and Prometheus.

Outstanding work (not for this PR):

  • Migrate remaining usages of Datadog functions
  • Enable use of the push gateway for sending metrics from Celery tasks

Corresponding commcare-cloud change: dimagi/commcare-cloud#3721

corehq/apps/receiverwrapper/views.py Outdated Show resolved Hide resolved
corehq/util/metrics/__init__.py Outdated Show resolved Hide resolved
corehq/util/metrics/__init__.py Outdated Show resolved Hide resolved
corehq/util/metrics/__init__.py Outdated Show resolved Hide resolved
corehq/util/metrics/datadog.py Outdated Show resolved Hide resolved
corehq/util/metrics/metrics.py Outdated Show resolved Hide resolved
corehq/util/metrics/tests/test_metrics.py Outdated Show resolved Hide resolved
corehq/util/metrics/tests/test_metrics.py Outdated Show resolved Hide resolved
corehq/util/metrics/tests/test_metrics.py Outdated Show resolved Hide resolved
deployment/gunicorn/gunicorn_conf.py Show resolved Hide resolved
Copy link
Contributor

@esoergel esoergel left a comment

Choose a reason for hiding this comment

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

I like this code structure and the resulting API very much.

corehq/util/metrics/datadog.py Outdated Show resolved Hide resolved
corehq/util/metrics/metrics.py Outdated Show resolved Hide resolved
corehq/util/metrics/metrics.py Outdated Show resolved Hide resolved
corehq/util/metrics/metrics.py Show resolved Hide resolved
corehq/util/metrics/__init__.py Show resolved Hide resolved
corehq/util/metrics/__init__.py Show resolved Hide resolved
Copy link
Contributor

@millerdev millerdev left a comment

Choose a reason for hiding this comment

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

I like the functional interface, thanks.

corehq/util/metrics/__init__.py Show resolved Hide resolved
corehq/util/metrics/metrics.py Outdated Show resolved Hide resolved
corehq/util/metrics/metrics.py Outdated Show resolved Hide resolved


def prometheus_metrics(request):
"""Exports /metrics as a Django view.
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this view used for? Should it be protected by an admin-only decorator? I'm assuming this is not the only interface for viewing prometheus metrics... seems like it would be bad if metrics became unavailable if this django view became inaccessible for whatever reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because Prometheus is primarily a pull based system the metrics need to be exposed as a view. There are a few options for this:

  1. As a Django view
    • this can either be protected by a shared secret / basic auth or, since it will be behind nginx in production we can deny access to it via the proxy.
  2. A separate HTTP server run on Django startup
    • prometheus_client.start_http_server(port, addr=addr)
  3. A completely separate HTTP server

I'm leaning towards 3: f1874e4

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that makes sense.

  1. As a Django view ... since it will be behind nginx in production we can deny access to it via the proxy

I'm -1 on this option if it's not authenticated in some way. It sounds like it may increase the complexity of proxy configuration, and someone who is setting up their own instance of HQ but doesn't know that it should be hidden may inadvertently advertise their metrics to the world.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we went that route I would update commcare-cloud to have the correct configuration by default. But I think for now I'll remove this view or restrict it's access.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deployment/gunicorn/gunicorn_conf.py Outdated Show resolved Hide resolved
urls.py Outdated Show resolved Hide resolved
@snopoke
Copy link
Contributor Author

snopoke commented Mar 18, 2020

I think I'm done with this PR for now and will do further work in a new branch.

===========

* All metrics must use the prefix 'commcare.'
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

This is great, thanks for adding!

deployment/prometheum_server.py Outdated Show resolved Hide resolved
corehq/util/metrics/__init__.py Outdated Show resolved Hide resolved
corehq/util/metrics/prometheus.py Show resolved Hide resolved
Copy link
Contributor

@kaapstorm kaapstorm left a comment

Choose a reason for hiding this comment

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

I want to echo the feedback on the great interface. I really like the approach you've taken here.

And great docs. In fact, it was the reference to the Datadog tagging docs that made me think that split(':') might need to be a split(':', 1).

corehq/util/metrics/datadog.py Outdated Show resolved Hide resolved
corehq/util/metrics/tests/utils.py Outdated Show resolved Hide resolved
@snopoke snopoke removed the Open for review: do not merge A work in progress label Mar 19, 2020
@snopoke snopoke merged commit b5b3fba into master Mar 19, 2020
@snopoke snopoke deleted the sk/monitoring-functional branch March 19, 2020 11:58
@snopoke
Copy link
Contributor Author

snopoke commented Mar 19, 2020

DD metrics changes:

commcare.xform_submissions.count lag tag (histogram)
  -> commcare.xform_submissions.lag.days lag tag 

commcare.xform_submissions.count duration tag (histogram)
  -> commcare.xform_submissions.duration.seconds duration tag

commcare.corrupt-multimedia-submission.error.count (counter)
  -> commcare.corrupt_multimedia_submissions

def _histogram(self, name: str, value: float, bucket_tag: str, buckets: List[int], bucket_unit: str = '',
tags: dict = None, documentation: str = ''):
"""
A cumulative histogram with a base metric name of <basename> exposes multiple time series
Copy link
Contributor

Choose a reason for hiding this comment

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

You missed the one on this line

Suggested change
A cumulative histogram with a base metric name of <basename> exposes multiple time series
A cumulative histogram with a base metric name of <name> exposes multiple time series

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks: #26916

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product/invisible Change has no end-user visible impact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants