Browse Source

Add the PROMETHEUS_ENABLED setting

pull/474/head
Pēteris Caune 4 years ago
parent
commit
725be65bdd
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
13 changed files with 66 additions and 1 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -0
      docker/.env
  3. +14
    -0
      hc/accounts/tests/test_project.py
  4. +1
    -0
      hc/accounts/views.py
  5. +20
    -0
      hc/front/tests/test_add_prometheus.py
  6. +6
    -0
      hc/front/tests/test_metrics.py
  7. +4
    -0
      hc/front/views.py
  8. +4
    -1
      hc/settings.py
  9. +2
    -0
      templates/accounts/project.html
  10. +3
    -0
      templates/docs/self_hosted_configuration.html
  11. +6
    -0
      templates/docs/self_hosted_configuration.md
  12. +2
    -0
      templates/front/channels.html
  13. +2
    -0
      templates/front/welcome.html

+ 1
- 0
CHANGELOG.md View File

@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file.
- Add the OPSGENIE_ENABLED setting (#471) - Add the OPSGENIE_ENABLED setting (#471)
- Add the PD_ENABLED setting (#471) - Add the PD_ENABLED setting (#471)
- Add the PAGERTREE_ENABLED setting (#471) - Add the PAGERTREE_ENABLED setting (#471)
- Add the PROMETHEUS_ENABLED setting (#471)
## Bug Fixes ## Bug Fixes
- Fix unwanted HTML escaping in SMS and WhatsApp notifications - Fix unwanted HTML escaping in SMS and WhatsApp notifications


+ 1
- 0
docker/.env View File

@ -34,6 +34,7 @@ PD_VENDOR_KEY=
PING_BODY_LIMIT=10000 PING_BODY_LIMIT=10000
PING_EMAIL_DOMAIN=localhost PING_EMAIL_DOMAIN=localhost
PING_ENDPOINT=http://localhost:8000/ping/ PING_ENDPOINT=http://localhost:8000/ping/
PROMETHEUS_ENABLED=True
PUSHBULLET_CLIENT_ID= PUSHBULLET_CLIENT_ID=
PUSHBULLET_CLIENT_SECRET= PUSHBULLET_CLIENT_SECRET=
PUSHOVER_API_TOKEN= PUSHOVER_API_TOKEN=


+ 14
- 0
hc/accounts/tests/test_project.py View File

@ -35,6 +35,7 @@ class ProjectTestCase(BaseTestCase):
self.assertContains(r, "X" * 32) self.assertContains(r, "X" * 32)
self.assertContains(r, "R" * 32) self.assertContains(r, "R" * 32)
self.assertContains(r, "Prometheus metrics endpoint")
def test_it_creates_api_key(self): def test_it_creates_api_key(self):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
@ -246,3 +247,16 @@ class ProjectTestCase(BaseTestCase):
r = self.client.get(self.url) r = self.client.get(self.url)
self.assertNotContains(r, "#set-project-name-modal", status_code=200) self.assertNotContains(r, "#set-project-name-modal", status_code=200)
self.assertNotContains(r, "Show API Keys") self.assertNotContains(r, "Show API Keys")
@override_settings(PROMETHEUS_ENABLED=False)
def test_it_hides_prometheus_link_if_prometheus_not_enabled(self):
self.project.api_key_readonly = "R" * 32
self.project.save()
self.client.login(username="[email protected]", password="password")
form = {"show_api_keys": "1"}
r = self.client.post(self.url, form)
self.assertEqual(r.status_code, 200)
self.assertNotContains(r, "Prometheus metrics endpoint")

+ 1
- 0
hc/accounts/views.py View File

@ -291,6 +291,7 @@ def project(request, code):
"project": project, "project": project,
"is_owner": is_owner, "is_owner": is_owner,
"show_api_keys": "show_api_keys" in request.GET, "show_api_keys": "show_api_keys" in request.GET,
"enable_prometheus": settings.PROMETHEUS_ENABLED is True,
} }
if request.method == "POST": if request.method == "POST":


+ 20
- 0
hc/front/tests/test_add_prometheus.py View File

@ -0,0 +1,20 @@
from django.test.utils import override_settings
from hc.test import BaseTestCase
class AddPrometheusTestCase(BaseTestCase):
def setUp(self):
super().setUp()
self.url = "/projects/%s/add_prometheus/" % self.project.code
def test_instructions_work(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertContains(r, "Prometheus")
self.assertContains(r, f"{self.project.code}/metrics/")
@override_settings(PROMETHEUS_ENABLED=False)
def test_it_handles_disabled_integration(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertEqual(r.status_code, 404)

+ 6
- 0
hc/front/tests/test_metrics.py View File

@ -1,3 +1,4 @@
from django.test.utils import override_settings
from hc.api.models import Check from hc.api.models import Check
from hc.test import BaseTestCase from hc.test import BaseTestCase
@ -41,3 +42,8 @@ class MetricsTestCase(BaseTestCase):
url = "/projects/%s/checks/metrics/%s" % (self.project.code, "X" * 32) url = "/projects/%s/checks/metrics/%s" % (self.project.code, "X" * 32)
r = self.client.get(url) r = self.client.get(url)
self.assertEqual(r.status_code, 403) self.assertEqual(r.status_code, 403)
@override_settings(PROMETHEUS_ENABLED=False)
def test_it_requires_prometheus_enabled(self):
r = self.client.get(self.url)
self.assertEqual(r.status_code, 404)

+ 4
- 0
hc/front/views.py View File

@ -301,6 +301,7 @@ def index(request):
"enable_pagertree": settings.PAGERTREE_ENABLED is True, "enable_pagertree": settings.PAGERTREE_ENABLED is True,
"enable_pd": settings.PD_ENABLED is True, "enable_pd": settings.PD_ENABLED is True,
"enable_pdc": settings.PD_VENDOR_KEY is not None, "enable_pdc": settings.PD_VENDOR_KEY is not None,
"enable_prometheus": settings.PROMETHEUS_ENABLED is True,
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None, "enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None, "enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
"enable_shell": settings.SHELL_ENABLED is True, "enable_shell": settings.SHELL_ENABLED is True,
@ -774,6 +775,7 @@ def channels(request, code):
"enable_pagertree": settings.PAGERTREE_ENABLED is True, "enable_pagertree": settings.PAGERTREE_ENABLED is True,
"enable_pd": settings.PD_ENABLED is True, "enable_pd": settings.PD_ENABLED is True,
"enable_pdc": settings.PD_VENDOR_KEY is not None, "enable_pdc": settings.PD_VENDOR_KEY is not None,
"enable_prometheus": settings.PROMETHEUS_ENABLED is True,
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None, "enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None, "enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
"enable_shell": settings.SHELL_ENABLED is True, "enable_shell": settings.SHELL_ENABLED is True,
@ -1818,6 +1820,7 @@ def add_msteams(request, code):
return render(request, "integrations/add_msteams.html", ctx) return render(request, "integrations/add_msteams.html", ctx)
@require_setting("PROMETHEUS_ENABLED")
@login_required @login_required
def add_prometheus(request, code): def add_prometheus(request, code):
project, rw = _get_project_for_user(request, code) project, rw = _get_project_for_user(request, code)
@ -1825,6 +1828,7 @@ def add_prometheus(request, code):
return render(request, "integrations/add_prometheus.html", ctx) return render(request, "integrations/add_prometheus.html", ctx)
@require_setting("PROMETHEUS_ENABLED")
def metrics(request, code, key): def metrics(request, code, key):
if len(key) != 32: if len(key) != 32:
return HttpResponseBadRequest() return HttpResponseBadRequest()


+ 4
- 1
hc/settings.py View File

@ -2,7 +2,7 @@
Django settings for healthchecks project. Django settings for healthchecks project.
For the full list of settings and their values, see For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings
https://docs.djangoproject.com/en/3.1/ref/settings/
""" """
import os import os
@ -215,6 +215,9 @@ PAGERTREE_ENABLED = envbool("PAGERTREE_ENABLED", "True")
PD_ENABLED = envbool("PD_ENABLED", "True") PD_ENABLED = envbool("PD_ENABLED", "True")
PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY") PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
# Prometheus
PROMETHEUS_ENABLED = envbool("PROMETHEUS_ENABLED", "True")
# Pushover integration # Pushover integration
PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN") PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL") PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")


+ 2
- 0
templates/accounts/project.html View File

@ -92,9 +92,11 @@
<p>Related links:</p> <p>Related links:</p>
<ul> <ul>
<li><a href="{% url 'hc-serve-doc' 'api' %}">API documentation</a></li> <li><a href="{% url 'hc-serve-doc' 'api' %}">API documentation</a></li>
{% if enable_prometheus %}
<li> <li>
<a href="{% url 'hc-metrics' project.code project.api_key_readonly %}">Prometheus metrics endpoint</a> <a href="{% url 'hc-metrics' project.code project.api_key_readonly %}">Prometheus metrics endpoint</a>
</li> </li>
{% endif %}
<li> <li>
<a href="{{ project.dashboard_url }}">Read-only dashboard</a> <a href="{{ project.dashboard_url }}">Read-only dashboard</a>
(<a href="https://github.com/healthchecks/dashboard/#security">security considerations</a>) (<a href="https://github.com/healthchecks/dashboard/#security">security considerations</a>)


+ 3
- 0
templates/docs/self_hosted_configuration.html View File

@ -179,6 +179,9 @@ to <code>[email protected]</code>.</p>
<p>In this example, Healthchecks would generate ping URLs similar <p>In this example, Healthchecks would generate ping URLs similar
to <code>https://ping.my-hc.example.org/3f1a7317-8e96-437c-a17d-b0d550b51e86</code>.</p> to <code>https://ping.my-hc.example.org/3f1a7317-8e96-437c-a17d-b0d550b51e86</code>.</p>
<h2 id="PROMETHEUS_ENABLED"><code>PROMETHEUS_ENABLED</code></h2>
<p>Default: <code>True</code></p>
<p>A boolean that turns on/off the Prometheus integration. Enabled by default.</p>
<h2 id="PUSHBULLET_CLIENT_ID"><code>PUSHBULLET_CLIENT_ID</code></h2> <h2 id="PUSHBULLET_CLIENT_ID"><code>PUSHBULLET_CLIENT_ID</code></h2>
<p>Default: <code>None</code></p> <p>Default: <code>None</code></p>
<h2 id="PUSHBULLET_CLIENT_SECRET"><code>PUSHBULLET_CLIENT_SECRET</code></h2> <h2 id="PUSHBULLET_CLIENT_SECRET"><code>PUSHBULLET_CLIENT_SECRET</code></h2>


+ 6
- 0
templates/docs/self_hosted_configuration.md View File

@ -300,6 +300,12 @@ PING_ENDPOINT=https://ping.my-hc.example.org
In this example, Healthchecks would generate ping URLs similar In this example, Healthchecks would generate ping URLs similar
to `https://ping.my-hc.example.org/3f1a7317-8e96-437c-a17d-b0d550b51e86`. to `https://ping.my-hc.example.org/3f1a7317-8e96-437c-a17d-b0d550b51e86`.
## `PROMETHEUS_ENABLED` {: #PROMETHEUS_ENABLED }
Default: `True`
A boolean that turns on/off the Prometheus integration. Enabled by default.
## `PUSHBULLET_CLIENT_ID` {: #PUSHBULLET_CLIENT_ID } ## `PUSHBULLET_CLIENT_ID` {: #PUSHBULLET_CLIENT_ID }
Default: `None` Default: `None`


+ 2
- 0
templates/front/channels.html View File

@ -336,6 +336,7 @@
</li> </li>
{% endif %} {% endif %}
{% if enable_prometheus %}
<li> <li>
<img src="{% static 'img/integrations/prometheus.png' %}" <img src="{% static 'img/integrations/prometheus.png' %}"
class="icon" alt="Prometheus icon" /> class="icon" alt="Prometheus icon" />
@ -344,6 +345,7 @@
<p>Export check and tag status values to Prometheus.</p> <p>Export check and tag status values to Prometheus.</p>
<a href="{% url 'hc-add-prometheus' project.code %}" class="btn btn-primary">Add Integration</a> <a href="{% url 'hc-add-prometheus' project.code %}" class="btn btn-primary">Add Integration</a>
</li> </li>
{% endif %}
{% if enable_pushbullet %} {% if enable_pushbullet %}
<li> <li>


+ 2
- 0
templates/front/welcome.html View File

@ -542,6 +542,7 @@
</div> </div>
{% endif %} {% endif %}
{% if enable_prometheus %}
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6"> <div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
<a href="{% url 'hc-serve-doc' 'configuring_prometheus' %}" class="integration"> <a href="{% url 'hc-serve-doc' 'configuring_prometheus' %}" class="integration">
<img src="{% static 'img/integrations/prometheus.png' %}" class="icon" alt="" /> <img src="{% static 'img/integrations/prometheus.png' %}" class="icon" alt="" />
@ -551,6 +552,7 @@
</h3> </h3>
</a> </a>
</div> </div>
{% endif %}
{% if enable_pushbullet %} {% if enable_pushbullet %}
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6"> <div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">


Loading…
Cancel
Save