: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(logs): nest a platform logs alert's filters under source_config (#118280)
Jimmy Zhu2084c7af5119
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 4817711c44a5..509e3917b45d 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -13763,9 +13763,9 @@ snapshots:scenes-app-persons-modal--with-results--light:hash: v1.k794b7964.892edabd980ca7b6b06f80ed8879ef4b9100ae8ff6a6c03fc77d9a9574a4f553.YVtPZaAGoU1C4_4htQ_YK_xO1AxKBVtTuEEYW-n0eUMscenes-app-platformalerts--detail--dark:- hash: v1.k794b7964.888d953d422c04e421f3603549e4704dd2b718897df92814149c218eec46eca6.lTtI1hfXTS-GDSkgNVVRZ_O3MyyM8GjvCs6ChptwJXI+ hash: v1.k794b7964.178c9c6382e3fd11c229bf0624fda3606d4898d770ee731ef82f376b8007eca3.J5rYYX2mDsjd0mH-9oWjB2tqtkQmhTPzh0FGmz7C7icscenes-app-platformalerts--detail--light:- hash: v1.k794b7964.60df5deb2c9dafac546acf889862925d1852290b0ff6fe97168fbc43908a70ec.e17thFNgW2nMl9GRZBa2Bii_TZ4tVHg6ID8RFF6ZXIo+ hash: v1.k794b7964.50b5bc0beaece53afabce8aedb5c7c2ec4f8d08bde5b25677d5bb34bee3fd39f.boeRGNeqlhbD-x7u-jQ6QAQaSeolObB9TZF77AblX0cscenes-app-platformalerts--list--dark:hash: v1.k794b7964.aab1c9fbc591759a9e754595061e016837e6c4e862c2360de2168635f64a83ab.5EgAUewtjNyO6pUOWeokaTKJMivFHpfxpi9aOWBt9VMscenes-app-platformalerts--list--light:diff --git a/products/alerts_platform/backend/facade/contracts.py b/products/alerts_platform/backend/facade/contracts.pyindex 41aece18754d..634305aba6bf 100644--- a/products/alerts_platform/backend/facade/contracts.py+++ b/products/alerts_platform/backend/facade/contracts.py@@ -103,11 +103,6 @@ def source_condition(source_config: dict[str, Any]) -> dict[str, Any]:return condition if isinstance(condition, dict) else {}-def source_filters(source_config: dict[str, Any]) -> dict[str, Any]:- """A source's own configuration, without the bound `source_condition` reads."""- return {key: value for key, value in source_config.items() if key != SOURCE_CONDITION_KEY}--class GroupingMode(StrEnum):SINGLE = "single"BY_RESULT_LABELS = "by_result_labels"@@ -323,11 +318,6 @@ class PlatformAlertCheckInput:if instance.state != PlatformAlertState.NOT_FIRING.value]- @property- def filters(self) -> dict[str, Any]:- """Satisfies the logs query layer, which names this field `filters`."""- return self.source_config-@propertydef condition(self) -> dict[str, Any]:return source_condition(self.source_config)diff --git a/products/alerts_platform/backend/migrations/0017_nest_logs_filters.py b/products/alerts_platform/backend/migrations/0017_nest_logs_filters.pynew file mode 100644index 000000000000..d0af448b7c82--- /dev/null+++ b/products/alerts_platform/backend/migrations/0017_nest_logs_filters.py@@ -0,0 +1,28 @@+from django.db import migrations++# A logs copy kept its filters at the top level beside `condition`. The live read rewrites an+# enabled copy at its next check, but a disabled or switched-off copy is never checked, so this+# moves every row. A row that already has `filters` is left alone, which makes a retry under+# `bin/migrate` a no-op.+NEST_LOGS_FILTERS = """+-- migration-analyzer: safe reason=one row per logs alert copy, and the live read rewrites the same rows in the same shape+UPDATE alerts_platformalertconfiguration+SET source_config = jsonb_build_object('filters', source_config - 'condition')+ || CASE+ WHEN source_config ? 'condition' THEN jsonb_build_object('condition', source_config -> 'condition')+ ELSE '{}'::jsonb+ END+WHERE source_kind = 'logs'+ AND jsonb_typeof(source_config) = 'object'+ AND NOT source_config ? 'filters'+"""+++class Migration(migrations.Migration):+ dependencies = [+ ("alerts_platform", "0016_platformalertdeliverypath"),+ ]++ operations = [+ migrations.RunSQL(NEST_LOGS_FILTERS, reverse_sql=migrations.RunSQL.noop),+ ]diff --git a/products/alerts_platform/backend/migrations/max_migration.txt b/products/alerts_platform/backend/migrations/max_migration.txtindex ab8cfc825bf6..89fdc222ffaf 100644--- a/products/alerts_platform/backend/migrations/max_migration.txt+++ b/products/alerts_platform/backend/migrations/max_migration.txt@@ -1 +1 @@-0016_platformalertdeliverypath+0017_nest_logs_filtersdiff --git a/products/alerts_platform/backend/tests/test_migration_0017_nest_logs_filters.py b/products/alerts_platform/backend/tests/test_migration_0017_nest_logs_filters.pynew file mode 100644index 000000000000..4d1f624fb0f4--- /dev/null+++ b/products/alerts_platform/backend/tests/test_migration_0017_nest_logs_filters.py@@ -0,0 +1,39 @@+from typing import Any++from posthog.test.base import TestMigrations++FILTERS = {"serviceNames": ["api"], "severityLevels": ["error"]}+CONDITION = {"threshold_count": 10, "threshold_operator": "above", "window_minutes": 5}+++class TestNestLogsFilters(TestMigrations):+ app = "alerts_platform"+ migrate_from = "0016_platformalertdeliverypath"+ migrate_to = "0017_nest_logs_filters"++ def setUpBeforeMigration(self, apps: Any) -> None:+ Configuration = apps.get_model("alerts_platform", "PlatformAlertConfiguration")++ def make(source_kind: str, source_config: dict[str, Any]) -> Any:+ return Configuration.objects.create(+ team_id=self.team.id,+ name="API errors",+ source_kind=source_kind,+ source_config=source_config,+ check_interval_minutes=5,+ enabled=False,+ ).id++ self.flat = make("logs", {**FILTERS, "condition": CONDITION})+ self.no_condition = make("logs", FILTERS)+ self.nested = make("logs", {"filters": {"serviceNames": ["web"]}, "condition": CONDITION})+ self.insight = make("insight", {"insight_id": 7, "condition": {"comparison": {"type": "absolute"}}})++ def test_logs_filters_move_under_their_own_key(self) -> None:+ Configuration = self.apps.get_model("alerts_platform", "PlatformAlertConfiguration") # type: ignore[union-attr]+ stored = {c.id: c.source_config for c in Configuration.objects.all()}++ assert stored[self.flat] == {"filters": FILTERS, "condition": CONDITION}+ assert stored[self.no_condition] == {"filters": FILTERS}+ assert stored[self.nested] == {"filters": {"serviceNames": ["web"]}, "condition": CONDITION}+ assert stored[self.insight] == {"insight_id": 7, "condition": {"comparison": {"type": "absolute"}}}diff --git a/products/alerts_platform/frontend/PlatformAlerts.stories.tsx b/products/alerts_platform/frontend/PlatformAlerts.stories.tsxindex 06821850868d..7c1d26281497 100644--- a/products/alerts_platform/frontend/PlatformAlerts.stories.tsx+++ b/products/alerts_platform/frontend/PlatformAlerts.stories.tsx@@ -14,8 +14,7 @@ const CONFIGURATION: PlatformAlertConfigurationApi = {enabled: true,source_kind: 'logs',source_config: {- serviceNames: ['checkout'],- severityLevels: ['error'],+ filters: { serviceNames: ['checkout'], severityLevels: ['error'] },condition: { threshold_count: 100, threshold_operator: 'above', window_minutes: 5 },},check_interval_minutes: 1,diff --git a/products/logs/backend/alert_source_cycle.py b/products/logs/backend/alert_source_cycle.pyindex 35a34293de67..8f5cfcfcfb4a 100644--- a/products/logs/backend/alert_source_cycle.py+++ b/products/logs/backend/alert_source_cycle.py@@ -20,7 +20,7 @@ from collections.abc import Mapping, Sequencefrom dataclasses import replacefrom datetime import datetime, timedeltafrom itertools import batched-from typing import Final, cast+from typing import Any, Final, castfrom uuid import UUID, uuid4from django.conf import settings@@ -99,6 +99,7 @@ from products.logs.backend.alert_group_columns import GROUP_COLUMNSfrom products.logs.backend.alert_lookback import rolling_check_lookback_minutesfrom products.logs.backend.models import LogsAlertConfigurationfrom products.logs.backend.platform_alert_backfill import platform_upsert_of+from products.logs.backend.platform_source_config import filters_of# Private to the production activity. Reimplementing either would let this path drift from# what the logs stack evaluates. Promoting them to a shared home is the deeper fix.@@ -170,6 +171,19 @@ class LogsAlertCondition:)+@frozen+class _QuerySubject:+ """A check as the logs query layer reads it, with the filters out of `source_config`."""++ id: UUID+ team_id: int+ filters: dict[str, Any]++ @classmethod+ def of(cls, check: PlatformAlertCheckInput) -> "_QuerySubject":+ return cls(id=check.id, team_id=check.team_id, filters=filters_of(check.source_config))++# The copy's settings a check takes from the logs alert as it is now. The schedule stays the# platform's own once the copy exists._SETTINGS_FIELDS: Final = (@@ -222,7 +236,7 @@ class _QueryShape:return cls(window_minutes=check.condition.get("window_minutes"),evaluation_periods=check.evaluation_periods,- projection_eligible=is_projection_eligible(check.source_config),+ projection_eligible=is_projection_eligible(filters_of(check.source_config)),)@@ -581,7 +595,7 @@ def _evaluate_cohort(try:result = BatchedAlertCheckQuery(team=team,- alerts=checks,+ alerts=[_QuerySubject.of(check) for check in checks],date_from=date_to - timedelta(minutes=lookback),date_to=date_to,projection_eligible=projection_eligible,@@ -775,7 +789,7 @@ def _evaluate_grouped(try:result = GroupedAlertCheckQuery(team=team,- alert=check,+ alert=_QuerySubject.of(check),date_from=date_to - timedelta(minutes=lookback),date_to=date_to,group_by=check.grouping.keys,@@ -870,7 +884,9 @@ def _triage(checks: Sequence[PlatformAlertCheckInput], *, now: datetime, tz_namemuted_ids: set[UUID] = set()for check in checks:broken_reason = (- _detect_broken_filter_config(check.source_config) or _broken_condition(check) or _broken_grouping(check)+ _detect_broken_filter_config(filters_of(check.source_config))+ or _broken_condition(check)+ or _broken_grouping(check))if broken_reason is not None:logger.warning(diff --git a/products/logs/backend/platform_alert_backfill.py b/products/logs/backend/platform_alert_backfill.pyindex 912f2ff24b43..53d457409976 100644--- a/products/logs/backend/platform_alert_backfill.py+++ b/products/logs/backend/platform_alert_backfill.py@@ -19,10 +19,11 @@ import structlogfrom posthog.dataclasses import frozenfrom products.alerts_platform.backend.facade.api import disable_configurations, upsert_configuration, upsert_if_running-from products.alerts_platform.backend.facade.contracts import SOURCE_CONDITION_KEY, PlatformAlertUpsert, SourceKind+from products.alerts_platform.backend.facade.contracts import PlatformAlertUpsert, SourceKindfrom products.alerts_platform.backend.facade.enums import PlatformAlertStatefrom products.logs.backend.alert_state_machine import AlertStatefrom products.logs.backend.models import LogsAlertConfiguration+from products.logs.backend.platform_source_config import logs_source_configlogger = structlog.get_logger(__name__)@@ -47,14 +48,14 @@ def platform_upsert_of(alert: LogsAlertConfiguration) -> PlatformAlertUpsert:name=alert.name,enabled=alert.enabled,source_kind=SourceKind.LOGS,- source_config={- **alert.filters,- SOURCE_CONDITION_KEY: {+ source_config=logs_source_config(+ alert.filters,+ {"threshold_count": alert.threshold_count,"threshold_operator": alert.threshold_operator,"window_minutes": alert.window_minutes,},- },+ ),check_interval_minutes=alert.check_interval_minutes,evaluation_periods=alert.evaluation_periods,datapoints_to_alarm=alert.datapoints_to_alarm,diff --git a/products/logs/backend/platform_alert_legacy_events.py b/products/logs/backend/platform_alert_legacy_events.pyindex 4c80b134670b..bf302e745008 100644--- a/products/logs/backend/platform_alert_legacy_events.py+++ b/products/logs/backend/platform_alert_legacy_events.py@@ -24,7 +24,6 @@ from products.alerts_platform.backend.facade.contracts import (EvaluationAnnouncement,IncidentAction,LegacyEventEmission,- source_filters,)from products.logs.backend.alert_destinations import (EVENT_KIND_CONFIG,@@ -40,6 +39,7 @@ from products.logs.backend.alert_event_properties import (from products.logs.backend.alert_lookback import rolling_check_lookback_minutesfrom products.logs.backend.alert_state_machine import IncidentCloseReasonfrom products.logs.backend.platform_alert_wording import check_window_end, in_utc+from products.logs.backend.platform_source_config import filters_of# Below the delivery activity's own timeout, which a flush must not use up.FLUSH_TIMEOUT_SECONDS: Final = 5.0@@ -97,7 +97,7 @@ def _message_event(transition: AnnouncedTransition, alert: _Alert) -> AlertInteralert_name=alert.alert_name,team_id=alert.team_id,consecutive_failures=alert.consecutive_failures,- filters=source_filters(transition.source_config),+ filters=filters_of(transition.source_config),triggered_at=transition.occurred_at,)return alert.event(event_name, {**properties, error_key: transition.error_message or ""}, transition)@@ -135,7 +135,7 @@ def _threshold_properties(transition: AnnouncedTransition, alert: _Alert) -> dicthreshold_operator=condition["threshold_operator"],window_minutes=condition["window_minutes"],result_count=int(transition.value) if transition.value is not None else None,- filters=source_filters(transition.source_config),+ filters=filters_of(transition.source_config),date_from=date_to - timedelta(minutes=lookback),date_to=date_to,triggered_at=transition.occurred_at,diff --git a/products/logs/backend/platform_alert_wording.py b/products/logs/backend/platform_alert_wording.pyindex ceeb23f4726c..80fd7722c38c 100644--- a/products/logs/backend/platform_alert_wording.py+++ b/products/logs/backend/platform_alert_wording.py@@ -23,6 +23,7 @@ from products.alerts_platform.backend.facade.contracts import (from products.logs.backend.alert_evaluation_key import window_end_offrom products.logs.backend.alert_group_columns import GROUP_COLUMNSfrom products.logs.backend.logs_url_params import build_logs_url_params, has_filter_values+from products.logs.backend.platform_source_config import filters_of# A resolve reports the count that ended the firing, so it is not a breach. A held check, which# only moves a paging incident, can be either, so it gets a neutral label.@@ -33,11 +34,9 @@ _LABELS = {def describe_logs_transition(*, project_id: int, transition: AnnouncedTransition) -> SourceDescription:- # `source_config` holds the alert's filters beside the platform's `condition` key, which none- # of the readers below look at.return SourceDescription(details=_details(transition),- context=_context(transition.source_config),+ context=_context(filters_of(transition.source_config)),data_link=MessageLink(label="View logs", url=_logs_url(project_id, transition)),)@@ -112,7 +111,7 @@ def _group_filters(transition: AnnouncedTransition) -> dict[str, Any]:`filterGroup` selection of the column. An alert with a list counted only logs inside it, so thegroup's value is one of them and the link narrows, never widens."""- filters = dict(transition.source_config)+ filters = dict(filters_of(transition.source_config))selected: dict[str, str] = {}for column, group_column in GROUP_COLUMNS.items():if column in transition.labels:@@ -158,7 +157,7 @@ def legacy_logs_webhook_body("""transition = in_utc(transition)occurred_at = transition.occurred_at- filters = transition.source_config+ filters = filters_of(transition.source_config)alert_url = absolute_uri(f"/project/{project_id}/logs/alerts/{alert_id}")data: dict[str, Any] = {"alert_id": alert_id,diff --git a/products/logs/backend/platform_source_config.py b/products/logs/backend/platform_source_config.pynew file mode 100644index 000000000000..d7daa9115cc5--- /dev/null+++ b/products/logs/backend/platform_source_config.py@@ -0,0 +1,28 @@+"""The shape a logs alert takes in the platform's `source_config`.++Imported from `ready()` through the message wording, so it stays light: no models, no query layer.+"""++from typing import Any, Final++from products.alerts_platform.backend.facade.contracts import SOURCE_CONDITION_KEY++FILTERS_KEY: Final = "filters"+++def logs_source_config(filters: object, condition: dict[str, Any]) -> dict[str, Any]:+ # Every reader of a stored copy calls `.get` on its filters, so a copy never stores another type.+ if not isinstance(filters, dict):+ raise TypeError(f"A logs alert's filters must be an object, got {type(filters).__name__}")+ return {FILTERS_KEY: filters, SOURCE_CONDITION_KEY: condition}+++def filters_of(source_config: dict[str, Any]) -> dict[str, Any]:+ """The alert's filters, from the nested shape or the flat one.++ The flat shape holds the filters at the top level beside the condition. History rows in+ ClickHouse keep it permanently, and delivery builds messages from those rows.+ """+ if FILTERS_KEY in source_config:+ return source_config[FILTERS_KEY]+ return {key: value for key, value in source_config.items() if key != SOURCE_CONDITION_KEY}diff --git a/products/logs/backend/test/test_alert_evaluate.py b/products/logs/backend/test/test_alert_evaluate.pyindex 950168d24251..26aaa9a393f7 100644--- a/products/logs/backend/test/test_alert_evaluate.py+++ b/products/logs/backend/test/test_alert_evaluate.py@@ -56,6 +56,7 @@ from products.logs.backend.alert_source_cycle import ()from products.logs.backend.models import LogsAlertConfiguration, LogsAlertEventfrom products.logs.backend.platform_alert_backfill import backfill_platform_alert_configurations+from products.logs.backend.platform_source_config import filters_offrom products.logs.backend.temporal.alert_evaluate import (EVALUATE_SCHEDULE_TO_CLOSE,EVALUATE_START_TO_CLOSE,@@ -84,9 +85,8 @@ class TestLogsAlertEvaluation(APIBaseTest):redis.get_client().delete(INFLIGHT_KEY)def _legacy_alert(self, source_config: dict[str, Any], **fields: Any) -> LogsAlertConfiguration:- filters = {key: value for key, value in source_config.items() if key != "condition"}return LogsAlertConfiguration.objects.create(- team=self.team, name="API errors", filters=filters, **source_config["condition"], **fields+ team=self.team, name="API errors", filters=filters_of(source_config), **source_config["condition"], **fields)def _configuration(self, **overrides: Any) -> PlatformConfigurationSnapshot:@@ -233,9 +233,10 @@ class TestLogsAlertEvaluation(APIBaseTest):(check,) = due_checks(self.team.id, SourceKind.LOGS.value, self._slot(), self.cutoff)copied = platform_testing.configuration(check.id)- evaluation, _ = self._run(copied)+ evaluation, query = self._run(copied)assert [(g.kind, g.value) for o in evaluation.outcomes for g in o.groups] == [(AlertEventKind.FIRING, 500.0)]+ assert [alert.filters for alert in query.call_args.kwargs["alerts"]] == [{"serviceNames": ["api"]}]def test_a_cohort_query_is_capped_below_the_batch_budget(self) -> None:_, query = self._run(self._configuration())diff --git a/products/logs/backend/test/test_platform_alert_legacy_events.py b/products/logs/backend/test/test_platform_alert_legacy_events.pyindex 83b983a268e1..aec8b04be29a 100644--- a/products/logs/backend/test/test_platform_alert_legacy_events.py+++ b/products/logs/backend/test/test_platform_alert_legacy_events.py@@ -1,5 +1,5 @@from datetime import UTC, datetime, timedelta-from typing import Any+from typing import Any, Finalfrom uuid import UUIDimport pytest@@ -60,7 +60,12 @@ def _alert() -> LogsAlertConfiguration:return LogsAlertConfiguration(id=ALERT_ID, team_id=7, name="Errors", filters=FILTERS, **CONDITION, **SCHEDULE)-def _transition(kind: AlertEventKind) -> AnnouncedTransition:+# A copy stores its filters nested, and a history row written before the nesting keeps them flat.+NESTED_SOURCE_CONFIG: Final = {"filters": FILTERS, SOURCE_CONDITION_KEY: CONDITION}+FLAT_SOURCE_CONFIG: Final = {**FILTERS, SOURCE_CONDITION_KEY: CONDITION}+++def _transition(kind: AlertEventKind, source_config: dict[str, Any] = NESTED_SOURCE_CONFIG) -> AnnouncedTransition:return AnnouncedTransition(grouping_key="",kind=kind,@@ -68,7 +73,7 @@ def _transition(kind: AlertEventKind) -> AnnouncedTransition:value=42.0 if kind in (AlertEventKind.FIRING, AlertEventKind.RESOLVED) else None,labels={},condition={**CONDITION, **SCHEDULE},- source_config={**FILTERS, SOURCE_CONDITION_KEY: CONDITION},+ source_config=source_config,error_message="query timed out",occurred_at=NOW,evaluation_key=f"slot:1|{WINDOW_MARKER}{WINDOW_END.isoformat()}",@@ -111,13 +116,29 @@ class TestEmitLogsLegacyEvents(SimpleTestCase):@parameterized.expand([- ("firing", AlertEventKind.FIRING, True, None, "$logs_alert_firing"),- ("resolved", AlertEventKind.RESOLVED, True, None, "$logs_alert_resolved"),- ("errored", AlertEventKind.ERRORED, True, None, "$logs_alert_errored"),- ("auto_disabled", AlertEventKind.BROKEN, True, None, "$logs_alert_auto_disabled"),- # Cooldown held the message, and the incident still opens.- ("incident_opened", AlertEventKind.FIRING, False, IncidentAction.TRIGGER, "$logs_alert_incident_opened"),- ("incident_closed", AlertEventKind.RESOLVED, False, IncidentAction.RESOLVE, "$logs_alert_incident_closed"),+ (f"{name}_{shape}", kind, sends_message, incident_action, event_name, source_config)+ for name, kind, sends_message, incident_action, event_name in [+ ("firing", AlertEventKind.FIRING, True, None, "$logs_alert_firing"),+ ("resolved", AlertEventKind.RESOLVED, True, None, "$logs_alert_resolved"),+ ("errored", AlertEventKind.ERRORED, True, None, "$logs_alert_errored"),+ ("auto_disabled", AlertEventKind.BROKEN, True, None, "$logs_alert_auto_disabled"),+ # Cooldown held the message, and the incident still opens.+ (+ "incident_opened",+ AlertEventKind.FIRING,+ False,+ IncidentAction.TRIGGER,+ "$logs_alert_incident_opened",+ ),+ (+ "incident_closed",+ AlertEventKind.RESOLVED,+ False,+ IncidentAction.RESOLVE,+ "$logs_alert_incident_closed",+ ),+ ]+ for shape, source_config in [("nested", NESTED_SOURCE_CONFIG), ("flat", FLAT_SOURCE_CONFIG)]])def test_an_event_carries_what_the_logs_stack_emits_for_the_same_check(@@ -127,13 +148,16 @@ class TestEmitLogsLegacyEvents(SimpleTestCase):sends_message: bool,incident_action: IncidentAction | None,event_name: str,+ source_config: dict[str, Any],) -> None:with patch(_ACTIVITIES_PRODUCE) as legacy:_legacy_emit(event_name)produce = self._emit(LegacyEventEmission(- transition=_transition(kind), sends_message=sends_message, incident_action=incident_action+ transition=_transition(kind, source_config),+ sends_message=sends_message,+ incident_action=incident_action,))diff --git a/products/logs/backend/test/test_platform_alert_wording.py b/products/logs/backend/test/test_platform_alert_wording.pyindex 4b33a49b12c8..9177122ee893 100644--- a/products/logs/backend/test/test_platform_alert_wording.py+++ b/products/logs/backend/test/test_platform_alert_wording.py@@ -13,6 +13,7 @@ from products.cdp.backend.validation import generate_template_bytecodefrom products.logs.backend.alert_destinations import EVENT_KIND_CONFIG, EventKindfrom products.logs.backend.logs_url_params import build_logs_url_paramsfrom products.logs.backend.platform_alert_wording import describe_logs_transition, legacy_logs_webhook_body+from products.logs.backend.platform_source_config import logs_source_configfrom common.hogvm.python.execute import execute_bytecode@@ -21,7 +22,10 @@ OCCURRED = datetime(2026, 10, 8, 18, 5, tzinfo=UTC)def _transition(- kind: AlertEventKind = AlertEventKind.FIRING, value: float | None = 11.0, filters: dict[str, Any] | None = None+ kind: AlertEventKind = AlertEventKind.FIRING,+ value: float | None = 11.0,+ filters: dict[str, Any] | None = None,+ flat: bool = False,) -> AnnouncedTransition:return AnnouncedTransition(grouping_key="",@@ -30,7 +34,9 @@ def _transition(value=value,labels={},condition=CONDITION,- source_config={**(filters or {}), "condition": CONDITION},+ source_config={**(filters or {}), "condition": CONDITION}+ if flat+ else logs_source_config(filters or {}, CONDITION),error_message=None,occurred_at=OCCURRED,)@@ -94,12 +100,13 @@ class TestLogsPlatformAlertWording(SimpleTestCase):("Property filters applied",),),("no_filters", {}, ("All log levels and services",)),+ ("flat_history_row", {"serviceNames": ["api"]}, ("Services: api",), True),])def test_the_context_names_the_filters_the_alert_watches(- self, _name: str, filters: dict[str, Any], expected: tuple[str, ...]+ self, _name: str, filters: dict[str, Any], expected: tuple[str, ...], flat: bool = False) -> None:- description = describe_logs_transition(project_id=7, transition=_transition(filters=filters))+ description = describe_logs_transition(project_id=7, transition=_transition(filters=filters, flat=flat))assert description.context == expected@@ -183,7 +190,7 @@ class TestLogsPlatformAlertWording(SimpleTestCase):"service_names": ["api"],"severity_levels": ["error"],"logs_url_params": build_logs_url_params(- transition.source_config, date_from=OCCURRED - timedelta(minutes=10), date_to=OCCURRED+ filters, date_from=OCCURRED - timedelta(minutes=10), date_to=OCCURRED),"triggered_at": OCCURRED.isoformat(),"consecutive_failures": 2,