Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitoring Improvements: Prometheus client to export receiver up stat… #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions src/tests/utils/test_metric_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
BinaryMutableOutcome,
IncrementMutableOutcome,
MetricExporter,
ReceiverAdapter,
ReceiverBackend,
)


Expand All @@ -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():
Expand Down Expand Up @@ -97,20 +85,22 @@ 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():
Expand Down
Loading