Snapshot of captured metrics that mimics the dict interface.
Metrics have the 'Dict[str(path), Set[Metric]]' format.
async def test_engine_metrics(service_client, monitor_client):
metric = await monitor_client.single_metric(
'engine.task-processors.tasks.finished' ,
labels={'task_processor' : 'main-task-processor' },
)
assert metric.value > 0
assert metric.labels == {'task_processor' : 'main-task-processor' }
metrics_dict = await monitor_client.metrics(
prefix='http.' , labels={'http_path' : '/ping' },
)
assert metrics_dict
assert 'http.handler.cancelled-by-deadline' in metrics_dict
assert (
metrics_dict.value_at(
'http.handler.in-flight' ,
labels={
'http_path' : '/ping' ,
'http_handler' : 'handler-ping' ,
'version' : '2' ,
},
)
== 0
)
Definition at line 46 of file metrics.py .
float pytest_userver.metrics.MetricsSnapshot.value_at
(
self ,
str
path ,
typing.Optional[typing.Dict]
labels = None
,
*typing.Optional[float]
default = None
)
Returns a single metric value at specified path.
If a dict of labels is provided, does en exact match of labels (i.e. {} stands for no labels; {'a': 'b', 'c': 'd'} matches only {'a': 'b', 'c': 'd'} or {'c': 'd', 'a': 'b'} but neither match {'a': 'b'} nor {'a': 'b', 'c': 'd', 'e': 'f'}).
Exceptions
AssertionError if not one metric by path
Definition at line 107 of file metrics.py .