diff --git a/docker/regression/Dockerfile b/docker/regression/Dockerfile index 88f61d03..f902b415 100644 --- a/docker/regression/Dockerfile +++ b/docker/regression/Dockerfile @@ -27,6 +27,7 @@ RUN apt-get update && \ docker-compose \ python3-pip \ python3-venv \ + prometheus \ redis \ geoip-bin \ geoip-database \ 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()