Coverage for databases/sync_tests/test_metrics.py: 100%
31 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1from prisma import Prisma
2from prisma._compat import model_json
5def test_prometheus(client: Prisma) -> None:
6 """Metrics can be returned in Prometheus format"""
7 client.user.create(data={'name': 'Robert'})
9 metrics = client.get_metrics(format='prometheus')
11 assert 'prisma_client_queries_total' in metrics
12 assert 'prisma_datasource_queries_total' in metrics
13 assert 'prisma_client_queries_active' in metrics
14 assert 'prisma_client_queries_duration_histogram_ms_bucket' in metrics
17def test_json_string(client: Prisma) -> None:
18 """Metrics can be serlialized to JSON"""
19 client.user.create(data={'name': 'Robert'})
21 metrics = client.get_metrics()
22 assert isinstance(model_json(metrics), str)
25def test_json(client: Prisma) -> None:
26 """Metrics returned in the JSON format"""
27 client.user.create(data={'name': 'Robert'})
29 metrics = client.get_metrics(format='json')
31 assert len(metrics.counters) > 0
32 assert metrics.counters[0].value > 0
34 assert len(metrics.gauges) > 0
35 gauge = next(filter(lambda g: g.key == 'prisma_pool_connections_open', metrics.gauges))
36 assert gauge.value > 0
38 assert len(metrics.histograms) > 0
39 assert metrics.histograms[0].value.sum > 0
40 assert metrics.histograms[0].value.count > 0
42 assert len(metrics.histograms[0].value.buckets) > 0
44 for bucket in metrics.histograms[0].value.buckets:
45 assert bucket.max_value >= 0
46 assert bucket.total_count >= 0
49def test_global_labels(client: Prisma) -> None:
50 metrics = client.get_metrics(global_labels={'foo': 'bar'})
51 assert metrics.counters[0].labels == {'foo': 'bar'}