forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore_cache_metrics.py
More file actions
40 lines (29 loc) · 1.33 KB
/
Copy pathfirestore_cache_metrics.py
File metadata and controls
40 lines (29 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Low-cardinality metrics for Firestore read-through caches.
This module intentionally lives under ``database/`` so database modules can
record metrics without importing upward from ``utils``. ``prometheus_client``
uses a global registry, so these metrics are exported automatically by the
existing /metrics endpoint.
"""
from prometheus_client import Counter, Histogram
FIRESTORE_CACHE_REQUESTS = Counter(
'firestore_cache_requests_total',
'Firestore cache requests by namespace and result',
['namespace', 'result'],
)
FIRESTORE_CACHE_FETCH_SECONDS = Histogram(
'firestore_cache_fetch_seconds',
'Time spent fetching Firestore cache misses from the source of truth',
['namespace'],
)
FIRESTORE_CACHE_PAYLOAD_BYTES = Histogram(
'firestore_cache_payload_bytes',
'Serialized Firestore cache payload size in bytes',
['namespace'],
buckets=(128, 512, 1024, 4096, 16384, 65536, 262144, 1048576),
)
def record_request(namespace: str, result: str) -> None:
FIRESTORE_CACHE_REQUESTS.labels(namespace=namespace, result=result).inc()
def observe_fetch(namespace: str, seconds: float) -> None:
FIRESTORE_CACHE_FETCH_SECONDS.labels(namespace=namespace).observe(seconds)
def observe_payload(namespace: str, payload_bytes: int) -> None:
FIRESTORE_CACHE_PAYLOAD_BYTES.labels(namespace=namespace).observe(payload_bytes)