From ba9f2d4a88b7aa7170422b2739748381c5347779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martti=20Rannanj=C3=A4rvi?= Date: Mon, 27 Jul 2020 18:09:18 +0300 Subject: [PATCH] regression-tests: Test that real prometheus can access wforce metrics --- regression-tests/prometheus-wforce.yml | 14 ++++++++++++++ regression-tests/test_Prometheus.py | 24 +++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 regression-tests/prometheus-wforce.yml diff --git a/regression-tests/prometheus-wforce.yml b/regression-tests/prometheus-wforce.yml new file mode 100644 index 00000000..c7a39473 --- /dev/null +++ b/regression-tests/prometheus-wforce.yml @@ -0,0 +1,14 @@ +global: + scrape_interval: 4s + +scrape_configs: + - job_name: wforce + + scrape_interval: 4s + + static_configs: + - targets: [ 'localhost:8084' ] + + basic_auth: + username: 'wforce' + password: 'super' diff --git a/regression-tests/test_Prometheus.py b/regression-tests/test_Prometheus.py index c4da13b3..48ed4e10 100644 --- a/regression-tests/test_Prometheus.py +++ b/regression-tests/test_Prometheus.py @@ -1,7 +1,7 @@ import requests import time import os -import requests +import subprocess from urllib.parse import urlparse from urllib.parse import urljoin @@ -9,6 +9,10 @@ from prometheus_client.samples import Sample from test_helper import ApiTestCase +PROMETHEUS_PORT="9090" +PROMETHEUS_URL="http://localhost:%s" % PROMETHEUS_PORT +PROMETHEUS_CONF="./prometheus-wforce.yml" + class TestPrometheus(ApiTestCase): def parsePrometheusResponse(self, response): @@ -83,3 +87,21 @@ def test_TrackalertMetrics(self): self.assertGreater(float(values['trackalert_commands_total{cmd="custom"}']), custom_count) self.assertGreater(float(values['trackalert_worker_response_duration_seconds_bucket{le="+Inf"}']), 0) + def test_RealPrometheus(self): + cmd = ["prometheus", "--config.file=%s" % PROMETHEUS_CONF] + prometheus = subprocess.Popen(cmd, close_fds=True) + prometheus_tries = 20 + try: + for i in range(prometheus_tries+1): + try: + r = requests.get('%s/api/v1/label/__name__/values' % + PROMETHEUS_URL) + assert 'wforce_commands_total' in r.text, r.text + break + except: + if i == prometheus_tries: + raise + time.sleep(4) + finally: + prometheus.terminate() + prometheus.wait()