Skip to content

Commit b6a0f75

Browse files
committed
Reduce noisy disabled analytics cache metrics
1 parent 6b3ed0c commit b6a0f75

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/primer/server/services/analytics_cache_service.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ def _disable_cache_client() -> None:
7474
def get_cached_json(namespace: str, params: dict[str, Any]) -> Any | None:
7575
client = _get_redis_client()
7676
if client is None:
77-
record_counter(
78-
"primer.analytics_cache.requests",
79-
1,
80-
{"namespace": namespace, "result": "disabled"},
81-
)
8277
return None
8378
try:
8479
payload = client.get(_build_cache_key(namespace, params))
@@ -123,11 +118,6 @@ def set_cached_json(
123118
) -> None:
124119
client = _get_redis_client()
125120
if client is None:
126-
record_counter(
127-
"primer.analytics_cache.writes",
128-
1,
129-
{"namespace": namespace, "result": "disabled"},
130-
)
131121
return
132122
try:
133123
client.setex(

tests/test_analytics_cache_service.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,37 @@
22

33

44
def test_get_cached_json_returns_none_without_redis_url(monkeypatch):
5+
counters: list[tuple[str, int | float, dict[str, str]]] = []
6+
57
monkeypatch.setattr(analytics_cache_service.settings, "analytics_cache_enabled", True)
68
monkeypatch.setattr(analytics_cache_service.settings, "redis_url", "")
9+
monkeypatch.setattr(
10+
analytics_cache_service,
11+
"record_counter",
12+
lambda name, value, attributes=None: counters.append((name, value, attributes or {})),
13+
)
714
analytics_cache_service._redis_client = None
815
analytics_cache_service._redis_disabled_until = None
916

1017
assert analytics_cache_service.get_cached_json("overview", {"team_id": None}) is None
18+
assert counters == []
1119

1220

1321
def test_set_cached_json_noops_without_redis_url(monkeypatch):
22+
counters: list[tuple[str, int | float, dict[str, str]]] = []
23+
1424
monkeypatch.setattr(analytics_cache_service.settings, "analytics_cache_enabled", True)
1525
monkeypatch.setattr(analytics_cache_service.settings, "redis_url", "")
26+
monkeypatch.setattr(
27+
analytics_cache_service,
28+
"record_counter",
29+
lambda name, value, attributes=None: counters.append((name, value, attributes or {})),
30+
)
1631
analytics_cache_service._redis_client = None
1732
analytics_cache_service._redis_disabled_until = None
1833

1934
analytics_cache_service.set_cached_json("overview", {"team_id": None}, {"total_sessions": 1})
35+
assert counters == []
2036

2137

2238
def test_get_cached_json_backs_off_after_redis_error(monkeypatch):

0 commit comments

Comments
 (0)