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

Update Thift Pool metrics to use class qualname #805

Merged
merged 4 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion baseplate/clients/thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def __init__(self, pool: ThriftConnectionPool, client_cls: Any):
)

def report_runtime_metrics(self, batch: metrics.Client) -> None:
pool_name = self.client_cls.__name__
pool_name = self.client_cls.__qualname__
self.max_connections_gauge.labels(pool_name).set(self.pool.size)
self.active_connections_gauge.labels(pool_name).set(self.pool.checkedout)
batch.gauge("pool.size").replace(self.pool.size)
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/clients/thrift_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest import mock

import pytest
import inspect

from prometheus_client import REGISTRY
from thrift.protocol.TProtocol import TProtocolException
Expand Down Expand Up @@ -228,7 +229,8 @@ def handle(*args, **kwargs):
def test_thrift_server_pool_prometheus_metrics(self, context_factory):
context_factory.report_runtime_metrics(batch=mock.MagicMock())
prom_labels = {
"thrift_pool": "Iface",
"thrift_pool": "TestThriftContextFactory.context_factory.<locals>.Iface",
}
assert context_factory.client_cls.__qualname__ == "TestThriftContextFactory.context_factory.<locals>.Iface"
assert REGISTRY.get_sample_value("thrift_client_pool_max_size", prom_labels) == 4
assert REGISTRY.get_sample_value("thrift_client_pool_active_connections", prom_labels) == 8
Loading