Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(flags): make hypercache sweep failures and bad zstd frames alertable (#105125)

James Gill9c8205ba062c
diff --git a/docs/internal/feature-flags/hypercache-system.md b/docs/internal/feature-flags/hypercache-system.md
index 3cf584a6ea41..0cb5f35949c4 100644
--- a/docs/internal/feature-flags/hypercache-system.md
+++ b/docs/internal/feature-flags/hypercache-system.md
@@ -335,14 +335,16 @@ Operational controls:
## Prometheus metrics
-| Metric | Labels | Purpose |
-| ------------------------------------------ | ------------------------------ | ------------------------------- |
-| `posthog_hypercache_get_from_cache` | `result`, `namespace`, `value` | Cache hit/miss tracking |
-| `posthog_hypercache_sync` | `result`, `namespace`, `value` | Cache sync task outcomes |
-| `posthog_hypercache_sync_duration_seconds` | `result`, `namespace`, `value` | Cache sync timing |
-| `posthog_remote_config_via_cache` | `result` | Remote config cache performance |
-| `posthog_hypercache_read_repair` | `result`, `namespace`, `value` | Rust reader repair outcomes |
-| `flags_flag_definitions_etag_total` | `result` | Rust reader ETag read outcomes |
+| Metric | Labels | Purpose |
+| ---------------------------------------------- | ------------------------------------ | ---------------------------------------- |
+| `posthog_hypercache_get_from_cache` | `result`, `namespace`, `value` | Cache hit/miss tracking |
+| `posthog_hypercache_sync` | `result`, `namespace`, `value` | Cache sync task outcomes |
+| `posthog_hypercache_sync_duration_seconds` | `result`, `namespace`, `value` | Cache sync timing |
+| `posthog_remote_config_via_cache` | `result` | Remote config cache performance |
+| `posthog_hypercache_read_repair` | `result`, `namespace`, `value` | Rust reader repair outcomes |
+| `flags_flag_definitions_etag_total` | `result` | Rust reader ETag read outcomes |
+| `posthog_hypercache_verify_errors_total` | `cache_type`, `reason` | Teams the verify sweep could not check |
+| `posthog_hypercache_verify_fix_failures_total` | `cache_type`, `issue_type`, `reason` | Repairs the verify sweep could not write |
Result labels: `hit_redis`, `hit_s3`, `hit_db`, `missing`, `batch_miss`
@@ -356,6 +358,10 @@ Read repair result labels: `success`, `skipped` (key already existed, repair def
`skipped` also covers replica lag: reads go to the replica and repairs to the primary, so a key written to the primary but not yet replicated reads as cold and its repair is correctly refused.
+The verify sweep counts a team it cannot check, and a repair it cannot write, then continues. Both carry a closed `reason` label, so every series is pre-created at import and an alert catches the first occurrence rather than the second. Verify reasons: `dependency_unavailable` (a Redis, S3 or Postgres outage, or a `HyperCacheDependencyUnavailable` from a `load_fn`), `data_error` (an entry the sweep cannot parse, which repeats on the same teams every run), `unknown`. Fix failures add `update_fn_returned_false` for a write path that returned False rather than raising. That covers a genuine refusal, such as a cache whose Redis URL is unset, and also a write error that `update_cache` caught and turned into False. The second case is reported by `update_cache` itself, in its own log line and, when a dependency was unavailable, in `posthog_hypercache_rebuild_skipped`. The label applies only where the sweep falls back to `update_fn`, because the direct write it normally uses raises, and those failures carry the reason of the exception. The exception class name is in the log line as `error_type`. A write the config vetoes is counted as neither a fix nor a failure.
+
+The sweep's other give-ups stay log-only on purpose: a team the grace period skips, and the batch-level fallbacks that degrade a batch to per-team reads. Both slow the sweep rather than leave an entry broken, and a sweep that runs out of time is already counted by `posthog_hypercache_verification_incomplete_runs_total`.
+
## Debugging
### Check Redis cache
diff --git a/posthog/caching/test/test_zstd_compressor.py b/posthog/caching/test/test_zstd_compressor.py
index ea68bceae92d..f8732e15c1b4 100644
--- a/posthog/caching/test/test_zstd_compressor.py
+++ b/posthog/caching/test/test_zstd_compressor.py
@@ -1,11 +1,16 @@
-from django.test import TestCase
+import struct
+from unittest.mock import patch
+
+from django.test import SimpleTestCase
+
+from celery.exceptions import SoftTimeLimitExceeded
from parameterized import parameterized
-from posthog.caching.zstd_compressor import ZstdCompressor
+from posthog.caching.zstd_compressor import ZSTD_FRAME_MAGIC, ZstdCompressor
-class TestZstdCompressor(TestCase):
+class TestZstdCompressor(SimpleTestCase):
# compressors take an options in init but don't use it 🤷
compressor = ZstdCompressor({})
@@ -14,6 +19,14 @@ class TestZstdCompressor(TestCase):
uncompressed_bytes = ("hello world hello world hello world hello world hello world" * 100).encode("utf-8")
zlib_compressed_bytes = b"x\x9c\xed\xcb\xb1\t\x00 \x0c\x00\xc1U2\x9cB\x8a@\xc0\xc6\xf5\x9d!\x95\xcdu_\xfc\xe5\xae\xea\xb8}jE\xcez\xb8\xa3(\x8a\xa2(\x8a\xa2(\x8a\xa2(\x8a\xa2(\x8a\xa2\xe8\x1f\xfa\x00\xaf\xed\xb6)"
zstd_compressed_bytes = b'(\xb5/\xfd`\x0c\x16\xbd\x02\x00`hello world \x80\xc7\xa8\xe0\xf77\xf0\x951\x12x\x81\xc1\xff\xbf\x7fDD\x94\x88\x880""JD\x84\x18\x11\x11%"D\x8c\x88\x88\x12!"FDD\t\x11\x11#""\x89\x88\x88\x11\x11\xa1DD\xc4\x88\x08Q""bD\x88(\x11\x11ed\xaa\xf9]\xa6'
+ # Carries the frame magic and still fails to decompress, as a truncated frame does.
+ unreadable_zstd_frame = zstd_compressed_bytes[:16]
+ # Frames that fail outside zstd.Error. Header descriptor 0xe0 declares a single segment with
+ # an 8-byte content size (RFC 8878, section 3.1.1.1), so the decoder trusts the size below it
+ # and allocates before it reads any data. 2^62 exhausts the allocator and raises MemoryError.
+ # 2^63 + 1 overflows a signed size and raises SystemError.
+ unallocatable_content_size_frame = ZSTD_FRAME_MAGIC + b"\xe0" + struct.pack("<Q", 1 << 62)
+ negative_content_size_frame = ZSTD_FRAME_MAGIC + b"\xe0" + struct.pack("<Q", (1 << 63) + 1)
@parameterized.expand(
[
@@ -67,3 +80,31 @@ class TestZstdCompressor(TestCase):
def test_the_zstd_compressor_decompression(self, _, setting: bool, input: bytes, output: bytes) -> None:
with self.settings(USE_REDIS_COMPRESSION=setting):
assert self.compressor.decompress(input) == output
+
+ @parameterized.expand(
+ [
+ ("a_frame_that_will_not_decompress", unreadable_zstd_frame, 1),
+ ("a_frame_declaring_a_content_size_that_cannot_be_allocated", unallocatable_content_size_frame, 1),
+ ("a_frame_declaring_a_content_size_that_overflows", negative_content_size_frame, 1),
+ ("a_value_that_was_never_compressed", short_uncompressed_bytes, 0),
+ ]
+ )
+ def test_only_an_unreadable_zstd_frame_is_counted(self, _, input: bytes, expected_increments: int) -> None:
+ for setting in (False, True):
+ with (
+ self.subTest(USE_REDIS_COMPRESSION=setting),
+ self.settings(USE_REDIS_COMPRESSION=setting),
+ patch("posthog.caching.zstd_compressor.COULD_NOT_DECOMPRESS_VALUE_COUNTER") as mock_counter,
+ ):
+ assert self.compressor.decompress(input) == input
+ assert mock_counter.inc.call_count == expected_increments
+
+ def test_soft_time_limit_during_decode_propagates(self) -> None:
+ with (
+ patch("posthog.caching.zstd_compressor.zstd.decompress", side_effect=SoftTimeLimitExceeded()),
+ patch("posthog.caching.zstd_compressor.COULD_NOT_DECOMPRESS_VALUE_COUNTER") as mock_counter,
+ self.assertRaises(SoftTimeLimitExceeded),
+ ):
+ self.compressor.decompress(self.zstd_compressed_bytes)
+
+ mock_counter.inc.assert_not_called()
diff --git a/posthog/caching/zstd_compressor.py b/posthog/caching/zstd_compressor.py
index 44c0e17fd03e..a899c5938ca2 100644
--- a/posthog/caching/zstd_compressor.py
+++ b/posthog/caching/zstd_compressor.py
@@ -7,14 +7,13 @@ from prometheus_client import Counter
logger = structlog.get_logger(__name__)
+# Every zstd frame starts with this magic number (RFC 8878, section 3.1.1).
+ZSTD_FRAME_MAGIC = b"\x28\xb5\x2f\xfd"
+
COULD_NOT_DECOMPRESS_VALUE_COUNTER = Counter(
"posthog_redis_could_not_decompress_value_counter",
- """
- Number of times decompression from redis failed while the setting was on.
- This is probably a sign that either there are still uncompressed values in redis
- or a value that was too small to compress and so doesn't need decompressing
- and so, seeing positive values here isn't necessarily an error.
- """,
+ "Zstd frames read from redis that this decoder could not decompress. The caller gets "
+ "the compressed bytes in place of its value, so any sustained rate is a defect.",
)
@@ -39,11 +38,15 @@ class ZstdCompressor(BaseCompressor):
return value
def decompress(self, value: bytes) -> bytes:
+ # Values at or below min_length are stored raw, so most reads hand this method
+ # something zstd never wrote. The magic number settles that without the decoder.
+ if not value.startswith(ZSTD_FRAME_MAGIC):
+ return value
try:
return zstd.decompress(value)
- except zstd.Error:
- if settings.USE_REDIS_COMPRESSION:
- COULD_NOT_DECOMPRESS_VALUE_COUNTER.inc()
- # if the decompression fails, behave like the IdentityCompressor
- # this way if the compressor is turned off we can still read values
+ except (zstd.Error, MemoryError, OverflowError, SystemError):
+ # Corrupt frame sizes can raise allocation errors instead of zstd.Error.
+ # Count old frames even after compression is disabled.
+ COULD_NOT_DECOMPRESS_VALUE_COUNTER.inc()
+ # The serializer can reject these bytes; this counter does not turn the read into a miss.
return value
diff --git a/posthog/storage/hypercache_verifier.py b/posthog/storage/hypercache_verifier.py
index 04531aa17547..bd677454bfef 100644
--- a/posthog/storage/hypercache_verifier.py
+++ b/posthog/storage/hypercache_verifier.py
@@ -6,21 +6,28 @@ and automatically fix issues.
"""
import gc
+import json
import time
+import pickle
from collections.abc import Callable
from dataclasses import dataclass, field
+from typing import Literal
from django.conf import settings
from django.db import InterfaceError, OperationalError, close_old_connections
from django.db.models import QuerySet
import structlog
+import redis.exceptions
from celery.exceptions import SoftTimeLimitExceeded
+from django_redis.exceptions import ConnectionInterrupted
from prometheus_client import Counter
from tenacity import RetryCallState, Retrying, retry_if_exception_type, stop_after_attempt, wait_exponential
from posthog.models.team.team import Team
+from posthog.storage.hypercache import HyperCacheDependencyUnavailable
from posthog.storage.hypercache_manager import HyperCacheManagementConfig, batch_check_expiry_tracking
+from posthog.storage.object_storage import ObjectStorageError
logger = structlog.get_logger(__name__)
@@ -41,6 +48,48 @@ HYPERCACHE_VERIFY_FIX_COUNTER = Counter(
labelnames=["cache_type", "issue_type", "writer"],
)
+# Closed sets, so posthog/tasks/hypercache_verification.py can pre-create every series:
+# increase() never reports a series' first increment, and the first occurrence is what
+# these counters exist to catch. The exception class name goes to the log line instead.
+VerifyFailureReason = Literal["dependency_unavailable", "data_error", "unknown"]
+FixFailureReason = Literal["update_fn_returned_false", "dependency_unavailable", "data_error", "unknown"]
+
+
+# Outages of the stores the sweep reads and writes. django-redis wraps redis connection and
+# timeout errors in ConnectionInterrupted, but a raw redis client raises them unwrapped.
+# OperationalError and InterfaceError are the connection drops that _fetch_team_batch retries.
+_DEPENDENCY_ERRORS = (
+ HyperCacheDependencyUnavailable,
+ ConnectionInterrupted,
+ redis.exceptions.ConnectionError,
+ redis.exceptions.TimeoutError,
+ ObjectStorageError,
+ OperationalError,
+ InterfaceError,
+)
+
+
+def classify_failure(error: Exception) -> VerifyFailureReason:
+ if isinstance(error, _DEPENDENCY_ERRORS):
+ return "dependency_unavailable"
+ # A plain ValueError can come from a dependency before it wraps the failure.
+ if isinstance(error, json.JSONDecodeError | UnicodeDecodeError | pickle.UnpicklingError | EOFError):
+ return "data_error"
+ return "unknown"
+
+
+HYPERCACHE_VERIFY_ERROR_COUNTER = Counter(
+ "posthog_hypercache_verify_errors_total",
+ "Teams whose verification raised during scheduled verification",
+ labelnames=["cache_type", "reason"],
+)
+
+HYPERCACHE_VERIFY_FIX_FAILURE_COUNTER = Counter(
+ "posthog_hypercache_verify_fix_failures_total",
+ "Repairs that failed to write during scheduled verification",
+ labelnames=["cache_type", "issue_type", "reason"],
+)
+
# Maximum number of team IDs to store for logging
MAX_FIXED_TEAM_IDS_TO_LOG = 10
@@ -328,7 +377,8 @@ def _verify_and_fix_batch(
raise
except Exception as e:
result.errors += 1
- logger.exception("Error verifying team", team_id=team.id, error=str(e))
+ HYPERCACHE_VERIFY_ERROR_COUNTER.labels(cache_type=cache_type, reason=classify_failure(e)).inc()
+ logger.exception("Error verifying team", team_id=team.id, error_type=type(e).__name__, error=str(e))
continue
# Ensure db_data is available for cache fixes even if the verify
@@ -429,6 +479,7 @@ def _fix_and_record(
logger.info("Fixing cache entry", **log_kwargs)
result.fix_detail_info_logs_emitted += 1
+ failure_reason: FixFailureReason = "update_fn_returned_false"
try:
# Use preloaded db_data if available to avoid redundant DB query
if "db_data" in verification:
@@ -448,7 +499,10 @@ def _fix_and_record(
raise
except Exception as e:
success = False
- logger.exception("Error fixing cache", team_id=team.id, issue_type=issue_type, error=str(e))
+ failure_reason = classify_failure(e)
+ logger.exception(
+ "Error fixing cache", team_id=team.id, issue_type=issue_type, error_type=type(e).__name__, error=str(e)
+ )
if success:
# Increment appropriate counter
@@ -465,6 +519,9 @@ def _fix_and_record(
HYPERCACHE_VERIFY_FIX_COUNTER.labels(cache_type=cache_type, issue_type=issue_type, writer=writer).inc()
else:
result.fix_failed += 1
+ HYPERCACHE_VERIFY_FIX_FAILURE_COUNTER.labels(
+ cache_type=cache_type, issue_type=issue_type, reason=failure_reason
+ ).inc()
def _run_verification_for_cache(
diff --git a/posthog/storage/test/test_hypercache_verifier.py b/posthog/storage/test/test_hypercache_verifier.py
index a681eff3c4d1..dd778157a930 100644
--- a/posthog/storage/test/test_hypercache_verifier.py
+++ b/posthog/storage/test/test_hypercache_verifier.py
@@ -8,7 +8,9 @@ Tests cover:
- Error handling and edge cases
"""
+import json
import time
+import pickle
from functools import partial
from posthog.test.base import BaseTest
@@ -18,10 +20,15 @@ from django.db import InterfaceError, OperationalError
from django.db.models import QuerySet
from django.test import SimpleTestCase, TestCase, override_settings
+import zstd
+import redis.exceptions
from celery.exceptions import SoftTimeLimitExceeded
+from django_redis.exceptions import ConnectionInterrupted
from parameterized import parameterized
+from posthog.caching.zstd_compressor import ZstdCompressor
from posthog.models.team.team import Team
+from posthog.storage.hypercache import HyperCacheDependencyUnavailable
from posthog.storage.hypercache_manager import HyperCacheManagementConfig
from posthog.storage.hypercache_verifier import (
MAX_FIXED_TEAM_IDS_TO_LOG,
@@ -31,8 +38,10 @@ from posthog.storage.hypercache_verifier import (
_fetch_team_batch,
_fix_and_record,
_verify_and_fix_batch,
+ classify_failure,
verify_and_fix_all_teams,
)
+from posthog.storage.object_storage import ObjectStorageError
class TestVerificationResult(TestCase):
@@ -256,24 +265,42 @@ class TestFixAndRecord(BaseTest):
assert result.cache_mismatch_fixed == 1
assert result.fix_failed == 0
- def test_exception_in_update_fn_increments_fix_failed(self):
- """Test that exception in update_fn increments fix_failed."""
+ @parameterized.expand(
+ [
+ ("write_refused_without_raising", {"return_value": False}, "update_fn_returned_false"),
+ (
+ "write_raised_a_parse_error",
+ {"side_effect": json.JSONDecodeError("bad payload", "bad", 0)},
+ "data_error",
+ ),
+ (
+ "write_raised_a_dependency_error",
+ {"side_effect": HyperCacheDependencyUnavailable("flags down")},
+ "dependency_unavailable",
+ ),
+ ("write_raised_anything_else", {"side_effect": RuntimeError("boom")}, "unknown"),
+ ]
+ )
+ def test_fix_failure_metric_carries_reason(self, _name, update_fn_behaviour, expected_reason):
mock_config = MagicMock()
- mock_config.should_skip_write = None # default: no write guard
+ mock_config.should_skip_write = None
mock_config.get_primary_writer_fn = None
- mock_config.update_fn.side_effect = Exception("Update failed")
+ mock_config.update_fn.configure_mock(**update_fn_behaviour)
result = VerificationResult()
- _fix_and_record(
- team=self.team,
- config=mock_config,
- issue_type="cache_miss",
- cache_type="test_cache",
- result=result,
- verification={"status": "miss"},
- )
+ with patch("posthog.storage.hypercache_verifier.HYPERCACHE_VERIFY_FIX_FAILURE_COUNTER") as mock_counter:
+ _fix_and_record(
+ team=self.team,
+ config=mock_config,
+ issue_type="cache_miss",
+ cache_type="flags",
+ result=result,
+ verification={"status": "miss"},
+ )
+ mock_counter.labels.assert_called_once_with(cache_type="flags", issue_type="cache_miss", reason=expected_reason)
+ mock_counter.labels.return_value.inc.assert_called_once_with()
assert result.cache_miss_fixed == 0
assert result.fix_failed == 1
@@ -569,7 +596,10 @@ class TestVerifyAndFixBatch(BaseTest):
def verify_fn(team, db_batch_data, cache_batch_data):
raise Exception("Verification failed")
- with patch("posthog.storage.hypercache_verifier.batch_check_expiry_tracking", return_value={}):
+ with (
+ patch("posthog.storage.hypercache_verifier.batch_check_expiry_tracking", return_value={}),
+ patch("posthog.storage.hypercache_verifier.HYPERCACHE_VERIFY_ERROR_COUNTER") as mock_error_counter,
+ ):
_verify_and_fix_batch(
teams=[self.team],
config=mock_config,
@@ -581,6 +611,8 @@ class TestVerifyAndFixBatch(BaseTest):
assert result.total == 1
assert result.errors == 1
assert result.total_fixed == 0
+ mock_error_counter.labels.assert_called_once_with(cache_type="test_cache", reason="unknown")
+ mock_error_counter.labels.return_value.inc.assert_called_once_with()
def test_soft_time_limit_exceeded_propagates_and_stops_batch(self):
"""SoftTimeLimitExceeded from verify_team_fn must propagate so the run winds
@@ -1334,3 +1366,33 @@ class TestFetchTeamBatch(SimpleTestCase):
cache_type="test_cache",
chunk_size=10,
)
+
+
+class TestClassifyFailure(SimpleTestCase):
+ def test_an_unreadable_cache_entry_is_a_data_error(self):
+ frame = zstd.compress(json.dumps({"flags": []}).encode() * 100, 0, 1)
+ # django-redis suppresses only CompressorError, and the compressor returns the stored
+ # bytes rather than raising, so an unreadable frame reaches pickle.loads whole.
+ unreadable = ZstdCompressor({}).decompress(frame[:16])
+ with self.assertRaises(Exception) as caught:
+ pickle.loads(unreadable)
+
+ assert classify_failure(caught.exception) == "data_error"
+
+ @parameterized.expand(
+ [
+ ("an_empty_stored_value", EOFError("Ran out of input"), "data_error"),
+ ("an_invalid_storage_endpoint", ValueError("Invalid endpoint"), "unknown"),
+ ("a_bug_in_the_sweep", AttributeError("'NoneType' object has no attribute 'get'"), "unknown"),
+ ("a_redis_write_during_an_outage", ConnectionInterrupted(connection=None), "dependency_unavailable"),
+ (
+ "a_raw_redis_timeout",
+ redis.exceptions.TimeoutError("Timeout reading from socket"),
+ "dependency_unavailable",
+ ),
+ ("an_s3_write_during_an_outage", ObjectStorageError("write failed"), "dependency_unavailable"),
+ ("a_dropped_db_connection", OperationalError("server closed the connection"), "dependency_unavailable"),
+ ]
+ )
+ def test_reason_separates_a_bad_entry_from_a_bug(self, _name, error, expected_reason):
+ assert classify_failure(error) == expected_reason
diff --git a/posthog/tasks/hypercache_verification.py b/posthog/tasks/hypercache_verification.py
index 84def1eb4f56..534091eaf8c9 100644
--- a/posthog/tasks/hypercache_verification.py
+++ b/posthog/tasks/hypercache_verification.py
@@ -28,8 +28,12 @@ from posthog.celery_task_names import (
from posthog.exceptions_capture import capture_exception
from posthog.storage.hypercache_manager import HyperCacheManagementConfig
from posthog.storage.hypercache_verifier import (
+ HYPERCACHE_VERIFY_ERROR_COUNTER,
HYPERCACHE_VERIFY_FIX_COUNTER,
+ HYPERCACHE_VERIFY_FIX_FAILURE_COUNTER,
+ FixFailureReason,
TeamBatchFetchError,
+ VerifyFailureReason,
VerifyTeamFn,
_run_verification_for_cache,
)
@@ -98,6 +102,16 @@ for _cache_type, _writers in _FIX_WRITERS_BY_CACHE_TYPE.items():
for _writer in _writers:
HYPERCACHE_VERIFY_FIX_COUNTER.labels(cache_type=_cache_type, issue_type=_issue_type, writer=_writer)
+# Same pre-creation rationale; these two stay at zero on a healthy cache.
+for _cache_type in _FIX_WRITERS_BY_CACHE_TYPE:
+ for _verify_reason in get_args(VerifyFailureReason):
+ HYPERCACHE_VERIFY_ERROR_COUNTER.labels(cache_type=_cache_type, reason=_verify_reason)
+ for _issue_type in _FIX_ISSUE_TYPES:
+ for _fix_reason in get_args(FixFailureReason):
+ HYPERCACHE_VERIFY_FIX_FAILURE_COUNTER.labels(
+ cache_type=_cache_type, issue_type=_issue_type, reason=_fix_reason
+ )
+
def _record_incomplete_run(cache_type: str, reason: IncompleteRunReason) -> None:
HYPERCACHE_VERIFICATION_INCOMPLETE_RUNS_COUNTER.labels(cache_type=cache_type, reason=reason).inc()
diff --git a/posthog/tasks/test/test_hypercache_verification.py b/posthog/tasks/test/test_hypercache_verification.py
index e8c7ed35ac49..53e8fc63f997 100644
--- a/posthog/tasks/test/test_hypercache_verification.py
+++ b/posthog/tasks/test/test_hypercache_verification.py
@@ -58,6 +58,29 @@ class TestFixCounterSeries(SimpleTestCase):
), f"series not pre-created: cache_type={cache_type}, issue_type={issue_type}, writer={writer}"
+class TestSweepFailureCounterSeries(SimpleTestCase):
+ def test_every_label_combination_is_pre_created_at_import(self) -> None:
+ for cache_type in ("flags", "team_metadata", "flag_definitions"):
+ for reason in ("dependency_unavailable", "data_error", "unknown"):
+ assert (
+ REGISTRY.get_sample_value(
+ "posthog_hypercache_verify_errors_total",
+ {"cache_type": cache_type, "reason": reason},
+ )
+ is not None
+ ), f"series not pre-created: cache_type={cache_type}, reason={reason}"
+
+ for issue_type in ("cache_miss", "cache_mismatch", "expiry_missing"):
+ for reason in ("update_fn_returned_false", "dependency_unavailable", "data_error", "unknown"):
+ assert (
+ REGISTRY.get_sample_value(
+ "posthog_hypercache_verify_fix_failures_total",
+ {"cache_type": cache_type, "issue_type": issue_type, "reason": reason},
+ )
+ is not None
+ ), f"series not pre-created: cache_type={cache_type}, issue_type={issue_type}, reason={reason}"
+
+
class TestIncompleteRunsCounterSeries(SimpleTestCase):
def test_every_label_pair_is_pre_created_at_import(self) -> None:
for cache_type in ("flags", "team_metadata", "flag_definitions"):
diff --git a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
index dbeccad93735..11a492ddb58d 100644
--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
@@ -86,7 +86,6 @@ posthog/api/test/test_toolbar_oauth_primitives.py::TestTokenEndpointStatusRemapp
posthog/api/test/test_toolbar_oauth_primitives.py::TestToolbarOAuthStateCache
posthog/api/test/test_user_integration.py::TestGithubUserFromCode
posthog/caching/test/test_redis_cluster_keys.py::TestRedisClusterKeySlots
-posthog/caching/test/test_zstd_compressor.py::TestZstdCompressor
posthog/cdp/templates/avo/test_template_avo.py::TestTemplateMigration
posthog/cdp/templates/customerio/test_template_customerio.py::TestTemplateMigration
posthog/cdp/templates/hubspot/test_template_hubspot.py::TestTemplateMigration