userver: samples/testsuite-support/tests/test_metrics.py
Loading...
Searching...
No Matches
samples/testsuite-support/tests/test_metrics.py
1async def test_basic(service_client, monitor_client):
2 response = await service_client.get('/metrics')
3 assert response.status_code == 200
4
5 metric = await monitor_client.single_metric('sample-metrics.foo')
6 assert metric.value > 0
7
8
9# /// [metrics reset]
10async def test_reset(service_client, monitor_client):
11 # Reset service metrics
12 await service_client.reset_metrics()
13 # Retrieve metrics
14 metric = await monitor_client.single_metric('sample-metrics.foo')
15 assert metric.value == 0
16 assert not metric.labels
17 # /// [metrics reset]
18
19 response = await service_client.get('/metrics')
20 assert response.status_code == 200
21
22 metric = await monitor_client.single_metric('sample-metrics.foo')
23 assert metric.value == 1
24
25 await service_client.reset_metrics()
26 metric = await monitor_client.single_metric('sample-metrics.foo')
27 assert metric.value == 0
28
29
30# /// [metrics labels]
31async def test_engine_metrics(service_client, monitor_client):
32 metric = await monitor_client.single_metric(
33 'engine.task-processors.tasks.finished',
34 labels={'task_processor': 'main-task-processor'},
35 )
36 assert metric.value > 0
37 assert metric.labels == {'task_processor': 'main-task-processor'}
38
39 metrics_dict = await monitor_client.metrics(
40 prefix='http.', labels={'http_path': '/ping'},
41 )
42
43 assert metrics_dict
44 assert 'http.handler.cancelled-by-deadline' in metrics_dict
45
46 assert (
47 metrics_dict.value_at(
48 'http.handler.in-flight',
49 labels={
50 'http_path': '/ping',
51 'http_handler': 'handler-ping',
52 'version': '2',
53 },
54 )
55 == 0
56 )
57 # /// [metrics labels]