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