- forward x-tenant-id from queue message header to payload processor - add functions to receive storage infos from an endpoint or the config. This enables hashing and caching of connections created from these infos - add function to initialize storage connections from storage infos - streamline and refactor tests to make them more readable and robust and to make it easier to add new tests - update payload processor with first iteration of multi tenancy storage connection support with connection caching and backwards compability
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import re
|
|
import time
|
|
|
|
import pytest
|
|
import requests
|
|
|
|
from pyinfra.payload_processing.monitor import PrometheusMonitor
|
|
|
|
|
|
@pytest.fixture(scope="class")
|
|
def monitored_mock_function(metric_prefix, host, port):
|
|
def process(data=None):
|
|
time.sleep(2)
|
|
return ["result1", "result2", "result3"]
|
|
|
|
monitor = PrometheusMonitor(metric_prefix, host, port)
|
|
return monitor(process)
|
|
|
|
|
|
@pytest.fixture
|
|
def metric_endpoint(host, port):
|
|
return f"http://{host}:{port}/prometheus"
|
|
|
|
|
|
@pytest.mark.parametrize("metric_prefix, host, port", [("test", "0.0.0.0", 8000)], scope="class")
|
|
class TestPrometheusMonitor:
|
|
def test_prometheus_endpoint_is_available(self, metric_endpoint, monitored_mock_function):
|
|
resp = requests.get(metric_endpoint)
|
|
assert resp.status_code == 200
|
|
|
|
def test_processing_with_a_monitored_fn_increases_parameter_counter(
|
|
self,
|
|
metric_endpoint,
|
|
metric_prefix,
|
|
monitored_mock_function,
|
|
):
|
|
monitored_mock_function(data=None)
|
|
resp = requests.get(metric_endpoint)
|
|
pattern = re.compile(rf".*{metric_prefix}_processing_time_count (\d\.\d).*")
|
|
assert pattern.search(resp.text).group(1) == "1.0"
|
|
|
|
monitored_mock_function(data=None)
|
|
resp = requests.get(metric_endpoint)
|
|
assert pattern.search(resp.text).group(1) == "2.0"
|