From de1cd7e83431eb4ccfd92faf65bd68f45304a046 Mon Sep 17 00:00:00 2001 From: dharani-oqc Date: Wed, 7 Aug 2024 12:34:55 +0100 Subject: [PATCH 1/2] Monitoring Improvements: Prometheus client to export receiver up statues and other metrics Signed-off-by: dharani-oqc --- src/tests/utils/test_metric_exporter.py | 28 +++++++------------------ 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/tests/utils/test_metric_exporter.py b/src/tests/utils/test_metric_exporter.py index 2f60b2e..c42c8b1 100644 --- a/src/tests/utils/test_metric_exporter.py +++ b/src/tests/utils/test_metric_exporter.py @@ -7,6 +7,8 @@ BinaryMutableOutcome, IncrementMutableOutcome, MetricExporter, + ReceiverBackend, + ReceiverAdapter, ) @@ -29,23 +31,9 @@ def mock_backend(): return BackendAdapter(Mock(Backend)) -class IncrementBackend(abc.ABC): - @abc.abstractmethod - def report(self, outcome: IncrementMutableOutcome): ... - - -class IncrementBackendAdapter(Backend): - def __init__(self, decorated): - super(IncrementBackendAdapter, self).__init__() - self.decorated = decorated - - def report(self, outcome: IncrementMutableOutcome): - self.decorated.report(outcome) - - @pytest.fixture def mock_increment_backend(): - return IncrementBackendAdapter(Mock(IncrementBackend)) + return ReceiverAdapter(Mock(ReceiverBackend)) def test_metric_exporter_aborts_if_given_type(): @@ -97,20 +85,20 @@ def test_metric_exporter_context_manager_with_sticky_false(mock_backend): def test_increment_metric_exporter_single_increment(mock_increment_backend): - with MetricExporter(backend=mock_increment_backend).report() as metric: + with MetricExporter(backend=mock_increment_backend).failed_messages() as metric: metric.increment() - expected_increment_outcome = mock_increment_backend.decorated.report.call_args[0][0] + expected_increment_outcome = mock_increment_backend.decorated.failed_messages.call_args[0][0] assert float(expected_increment_outcome) == 1.0 - mock_increment_backend.decorated.report.assert_called_once_with( + mock_increment_backend.decorated.failed_messages.assert_called_once_with( expected_increment_outcome ) def test_increment_metric_exporter_multiple_increment(mock_increment_backend): - with MetricExporter(backend=mock_increment_backend).report() as metric: + with MetricExporter(backend=mock_increment_backend).failed_messages() as metric: for _ in range(5): metric.increment() - assert float(mock_increment_backend.decorated.report.call_args[0][0]) == 5.0 + assert float(mock_increment_backend.decorated.failed_messages.call_args[0][0]) == 5.0 def test_implicit_conversion_of_proxy_object(): From 054bdbdfe152bc314fcbe9ab34101f9380ae395d Mon Sep 17 00:00:00 2001 From: dharani-oqc Date: Mon, 12 Aug 2024 15:13:15 +0100 Subject: [PATCH 2/2] Formatting test Signed-off-by: dharani-oqc --- src/tests/utils/test_metric_exporter.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tests/utils/test_metric_exporter.py b/src/tests/utils/test_metric_exporter.py index c42c8b1..9b332f0 100644 --- a/src/tests/utils/test_metric_exporter.py +++ b/src/tests/utils/test_metric_exporter.py @@ -7,8 +7,8 @@ BinaryMutableOutcome, IncrementMutableOutcome, MetricExporter, - ReceiverBackend, ReceiverAdapter, + ReceiverBackend, ) @@ -87,7 +87,9 @@ def test_metric_exporter_context_manager_with_sticky_false(mock_backend): def test_increment_metric_exporter_single_increment(mock_increment_backend): with MetricExporter(backend=mock_increment_backend).failed_messages() as metric: metric.increment() - expected_increment_outcome = mock_increment_backend.decorated.failed_messages.call_args[0][0] + expected_increment_outcome = mock_increment_backend.decorated.failed_messages.call_args[ + 0 + ][0] assert float(expected_increment_outcome) == 1.0 mock_increment_backend.decorated.failed_messages.assert_called_once_with( expected_increment_outcome