: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(alerts): compare insight alert destinations with every shipped default (#117407)
Jimmy Zhu7a0648a4d81b
diff --git a/products/alerts/backend/logic/destination_eligibility.py b/products/alerts/backend/logic/destination_eligibility.pyindex 00d926d7884a..607135586fd6 100644--- a/products/alerts/backend/logic/destination_eligibility.py+++ b/products/alerts/backend/logic/destination_eligibility.py@@ -9,19 +9,26 @@ so comparing with what the code builds today would read an old, unedited functioThe first snapshot is the stock content only when the function was created with stock inputs. Thelogs alert API creates every logs destination that way. The HogFunction editor that insight alerts-use lets a person change the message before the first save, so for insight a function without a-later edit can still be customized.+use lets a person change the message before the first save. So for insight the first inputs are also+compared with every default an insight alert path has shipped."""from __future__ import annotations+import jsonimport hashlibfrom collections.abc import Collection, Sequencefrom datetime import UTC, datetime, timedelta+from pathlib import Pathfrom typing import Any, Finalfrom uuid import UUID-from products.alerts.backend.facade.contracts import DestinationBucket, DestinationEligibility, DestinationHoldBack+from products.alerts.backend.facade.contracts import (+ INSIGHT_ALERT_EVENT_IDS,+ DestinationBucket,+ DestinationEligibility,+ DestinationHoldBack,+)from products.alerts.backend.logic.destination_configs import (SPEC_BY_TEMPLATE_ID,WEBHOOK_HEADERS,@@ -53,6 +60,14 @@ _INPUT_HOLD_BACKS: Final[dict[str, dict[str, DestinationHoldBack]]] = {},}+# Every value an insight alert path has shipped as a default, by template and input key. Built from+# git history: the insight alert sub-template, the template defaults, the alert wizard, the backend+# Slack blocks, the agent recipes and the chart-block backfill. Add the default of any new path here.+STOCK_INPUT_VALUES: Final[dict[str, dict[str, list[Any]]]] = json.loads(+ (Path(__file__).parent / "destination_stock_inputs.json").read_text()+)+_NOT_SENT_INPUTS: Final = frozenset({"debug"})+_DERIVED_FILTER_KEYS: Final = ("bytecode", "bytecode_error", "bytecode_contract", "transpiled")@@ -85,7 +100,7 @@ def classify_alert_destinations(.filter(**_RECEIVES_ALERT_EVENTS).order_by("created_at", "id"))- return _classify(team_id, functions)+ return _classify(team_id, functions, allowed_event_ids)def classify_destinations_by_alert(@@ -102,7 +117,7 @@ def classify_destinations_by_alert(.filter(**_RECEIVES_ALERT_EVENTS).order_by("created_at", "id"))- for function, eligibility in zip(functions, _classify(team_id, functions)):+ for function, eligibility in zip(functions, _classify(team_id, functions, allowed_event_ids)):for alert_id in _named_alert_ids(function.filters) & batch:by_alert[alert_id].append(eligibility)return {alert_id: tuple(eligibilities) for alert_id, eligibilities in by_alert.items()}@@ -116,13 +131,19 @@ def classify_unbound_alert_destinations(if not unbound_ids:return ()return _classify(- team_id, list(HogFunction.objects.filter(team_id=team_id, id__in=unbound_ids).order_by("created_at", "id"))+ team_id,+ list(HogFunction.objects.filter(team_id=team_id, id__in=unbound_ids).order_by("created_at", "id")),+ allowed_event_ids,)-def _classify(team_id: int, functions: list[HogFunction]) -> tuple[DestinationEligibility, ...]:+def _classify(+ team_id: int, functions: list[HogFunction], allowed_event_ids: Collection[str]+) -> tuple[DestinationEligibility, ...]:if not functions:return ()+ # Insight destinations are built in an editor, so the first revision can already hold an edit.+ stock = STOCK_INPUT_VALUES if not set(allowed_event_ids).isdisjoint(INSIGHT_ALERT_EVENT_IDS) else {}first_revisions: dict[UUID, HogFunctionRevision] = {revision.hog_function_id: revisionfor revision in HogFunctionRevision.objects.for_team(team_id)@@ -135,7 +156,7 @@ def _classify(team_id: int, functions: list[HogFunction]) -> tuple[DestinationElDestinationEligibility(hog_function_id=function.id,template_id=function.template_id,- hold_backs=_hold_backs(function, first_revisions.get(function.id)),+ hold_backs=_hold_backs(function, first_revisions.get(function.id), stock.get(function.template_id or "")),code_hash=hashlib.md5((function.hog or "").encode(), usedforsecurity=False).hexdigest(),)for function in functions@@ -192,7 +213,9 @@ def _bound_to_one_alert(filters: Any) -> bool:)-def _hold_backs(function: HogFunction, first_revision: HogFunctionRevision | None) -> tuple[DestinationHoldBack, ...]:+def _hold_backs(+ function: HogFunction, first_revision: HogFunctionRevision | None, stock: dict[str, list[Any]] | None+) -> tuple[DestinationHoldBack, ...]:template_id = function.template_idif not template_id:return (DestinationHoldBack.NO_TEMPLATE,)@@ -221,18 +244,18 @@ def _hold_backs(function: HogFunction, first_revision: HogFunctionRevision | Nonlast_untracked_save = function.updated_at if first_revision is None else first_revision.created_atif function.created_at < EDIT_TRACKING_STARTED and last_untracked_save - function.created_at > RESAVED_AFTER:found.append(DestinationHoldBack.UNTRACKED_EDIT)- if first_revision is None:- return tuple(found)-- first_snapshot = first_revision.content-- if code_edited:- found.append(DestinationHoldBack.CODE)- if function.inputs_schema != first_snapshot.get("inputs_schema"):- found.append(DestinationHoldBack.CUSTOM_INPUTS)- if _without_derived(function.filters) != _without_derived(first_snapshot.get("filters")):- found.append(DestinationHoldBack.FILTERS)- found.extend(_input_hold_backs(template_id, function.inputs or {}, first_snapshot.get("inputs") or {}))+ if stock is not None:+ first_inputs = function.inputs if first_revision is None else first_revision.content.get("inputs")+ found.extend(_stock_hold_backs(template_id, first_inputs or {}, stock))+ if first_revision is not None:+ first_snapshot = first_revision.content+ if code_edited:+ found.append(DestinationHoldBack.CODE)+ if function.inputs_schema != first_snapshot.get("inputs_schema"):+ found.append(DestinationHoldBack.CUSTOM_INPUTS)+ if _without_derived(function.filters) != _without_derived(first_snapshot.get("filters")):+ found.append(DestinationHoldBack.FILTERS)+ found.extend(_input_hold_backs(template_id, function.inputs or {}, first_snapshot.get("inputs") or {}))# Ordered and unique, so a report reads the same for the same function.return tuple(dict.fromkeys(found))@@ -241,27 +264,52 @@ def _input_hold_backs(template_id: str, inputs: dict[str, Any], first_inputs: dict[str, Any]) -> list[DestinationHoldBack]:found: list[DestinationHoldBack] = []- is_webhook = template_id == WebhookDestination.template_id- for key in sorted(set(inputs) | set(first_inputs)):- if key in SPEC_BY_TEMPLATE_ID[template_id].address_input_keys:- continue+ for key in _compared_keys(template_id, set(inputs) | set(first_inputs)):value, first_value = input_value(inputs, key), input_value(first_inputs, key)- if is_webhook and key == "headers":- # Native delivery sends the added headers that `added_webhook_headers` keeps, so only one- # it drops changes what reaches the receiver.- if value != first_value:- dropped = _dropped_headers(value)- if any(_has_template(header_value) for header_value in dropped.values()):- found.append(DestinationHoldBack.WEBHOOK_TEMPLATED_HEADER)- elif dropped:- found.append(DestinationHoldBack.WEBHOOK_HEADERS)+ same_mode = _is_webhook_headers(template_id, key) or _templating(inputs, key) == _templating(first_inputs, key)+ if value == first_value and same_mode:continue- if value == first_value and _templating(inputs, key) == _templating(first_inputs, key):+ found.extend(_key_hold_backs(template_id, key, value))+ return found+++def _stock_hold_backs(+ template_id: str, inputs: dict[str, Any], stock: dict[str, list[Any]]+) -> list[DestinationHoldBack]:+ found: list[DestinationHoldBack] = []+ for key in _compared_keys(template_id, set(inputs)):+ value = input_value(inputs, key)+ # The templates skip an empty input, so it sends what a missing one sends.+ if value in (None, "") or (value in stock.get(key, ()) and _templating(inputs, key) == "hog"):continue- found.append(_INPUT_HOLD_BACKS.get(template_id, {}).get(key, DestinationHoldBack.MESSAGE))+ found.extend(_key_hold_backs(template_id, key, value))return found+def _compared_keys(template_id: str, keys: set[str]) -> list[str]:+ skipped = SPEC_BY_TEMPLATE_ID[template_id].address_input_keys | _NOT_SENT_INPUTS+ return sorted(keys - skipped)+++def _is_webhook_headers(template_id: str, key: str) -> bool:+ return template_id == WebhookDestination.template_id and key == "headers"+++def _key_hold_backs(template_id: str, key: str, value: Any) -> list[DestinationHoldBack]:+ if _is_webhook_headers(template_id, key):+ return _header_hold_backs(value)+ return [_INPUT_HOLD_BACKS.get(template_id, {}).get(key, DestinationHoldBack.MESSAGE)]+++def _header_hold_backs(headers: Any) -> list[DestinationHoldBack]:+ # Native delivery sends the added headers that `added_webhook_headers` keeps, so only one it+ # drops changes what reaches the receiver.+ dropped = _dropped_headers(headers)+ if any(_has_template(header_value) for header_value in dropped.values()):+ return [DestinationHoldBack.WEBHOOK_TEMPLATED_HEADER]+ return [DestinationHoldBack.WEBHOOK_HEADERS] if dropped else []++def _templating(inputs: dict[str, Any], key: str) -> Any:# The renderer follows this mode, so the same value renders differently under another one.entry = inputs.get(key)diff --git a/products/alerts/backend/logic/destination_stock_inputs.json b/products/alerts/backend/logic/destination_stock_inputs.jsonnew file mode 100644index 000000000000..48a9f1f77758--- /dev/null+++ b/products/alerts/backend/logic/destination_stock_inputs.json@@ -0,0 +1,892 @@+{+ "template-discord": {+ "allowedMentions": ["none"],+ "content": [+ "**Alert '{event.properties.alert_name}' firing** for insight '{event.properties.insight_name}'\n{event.properties.breaches}\n{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}",+ "**{person.name}** triggered event: '{event.event}'"+ ]+ },+ "template-microsoft-teams": {+ "text": [+ "**Alert '{event.properties.alert_name}' firing** for insight '{event.properties.insight_name}'\n\n{event.properties.breaches}\n\n[View alert]({project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id})",+ "**{person.name}** triggered event: '{event.event}'"+ ]+ },+ "template-slack": {+ "blocks": [+ [+ {+ "text": {+ "text": "*{person.name}* triggered event: '{event.event}'",+ "type": "mrkdwn"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": {+ "text": "View Person in PostHog",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{person.url}"+ },+ {+ "text": {+ "text": "Message source",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{source.url}"+ }+ ],+ "type": "actions"+ }+ ],+ [+ {+ "text": {+ "text": "*{person.name}* triggered event: '{event.name}'",+ "type": "mrkdwn"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": {+ "text": "View Person in PostHog",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{person.url}"+ },+ {+ "text": {+ "text": "Message source",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{source.url}"+ }+ ],+ "type": "actions"+ }+ ],+ [+ {+ "text": {+ "text": "Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'",+ "type": "plain_text"+ },+ "type": "header"+ },+ {+ "text": {+ "text": "{event.properties.breaches}",+ "type": "plain_text"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": "Project: <{project.url}|{project.name}>",+ "type": "mrkdwn"+ },+ {+ "text": "Alert: <{source.url}|{source.name}>",+ "type": "mrkdwn"+ }+ ],+ "type": "context"+ },+ {+ "type": "divider"+ },+ {+ "elements": [+ {+ "text": {+ "text": "View Insight",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}"+ }+ ],+ "type": "actions"+ }+ ],+ [+ {+ "text": {+ "text": "Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'",+ "type": "plain_text"+ },+ "type": "header"+ },+ {+ "text": {+ "text": "{event.properties.breaches}",+ "type": "plain_text"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": "Project: <{project.url}|{project.name}>",+ "type": "mrkdwn"+ }+ ],+ "type": "context"+ },+ "{event.properties.insight_chart_url ? {'type': 'image', 'image_url': event.properties.insight_chart_url, 'alt_text': 'Insight chart'} : {'type': 'divider'}}",+ {+ "block_id": "insight_alert_snooze:{event.properties.alert_id}",+ "elements": [+ {+ "text": {+ "text": "{event.properties.investigation_notebook_url ? 'View Investigation' : 'View Alert'}",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{event.properties.investigation_notebook_url ? event.properties.investigation_notebook_url : concat(project.url, '/insights/', event.properties.insight_id, '/alerts?alert_id=', event.properties.alert_id, '&utm_source=alert&utm_campaign=alert_check_firing&utm_medium=slack')}"+ },+ {+ "text": {+ "text": "View Insight",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}?utm_source=alert&utm_campaign=alert_check_firing&utm_medium=slack"+ },+ {+ "action_id": "insight_alert_snooze",+ "options": [+ {+ "text": {+ "text": "For 1 hour",+ "type": "plain_text"+ },+ "value": "{event.properties.alert_id}|1h"+ },+ {+ "text": {+ "text": "For 6 hours",+ "type": "plain_text"+ },+ "value": "{event.properties.alert_id}|6h"+ },+ {+ "text": {+ "text": "For 1 day",+ "type": "plain_text"+ },+ "value": "{event.properties.alert_id}|1d"+ },+ {+ "text": {+ "text": "For 1 week",+ "type": "plain_text"+ },+ "value": "{event.properties.alert_id}|1w"+ },+ {+ "text": {+ "text": "Pick a date & time…",+ "type": "plain_text"+ },+ "value": "{event.properties.alert_id}|custom"+ }+ ],+ "placeholder": {+ "text": "Snooze…",+ "type": "plain_text"+ },+ "type": "static_select"+ }+ ],+ "type": "actions"+ }+ ],+ [+ {+ "text": {+ "text": "Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'",+ "type": "plain_text"+ },+ "type": "header"+ },+ {+ "text": {+ "text": "{event.properties.breaches}",+ "type": "plain_text"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": "Project: <{project.url}|{project.name}>",+ "type": "mrkdwn"+ }+ ],+ "type": "context"+ },+ {+ "type": "divider"+ },+ {+ "block_id": "insight_alert_snooze:{event.properties.alert_id}",+ "elements": [+ {+ "text": {+ "text": "{event.properties.investigation_notebook_url ? 'View Investigation' : 'View Alert'}",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{event.properties.investigation_notebook_url ? event.properties.investigation_notebook_url : concat(project.url, '/insights/', event.properties.insight_id, '/alerts?alert_id=', event.properties.alert_id, '&utm_source=alert&utm_campaign=alert_check_firing&utm_medium=slack')}"+ },+ {+ "text": {+ "text": "View Insight",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}?utm_source=alert&utm_campaign=alert_check_firing&utm_medium=slack"+ },+ {+ "action_id": "insight_alert_snooze",+ "options": [+ {+ "text": {+ "text": "For 1 hour",+ "type": "plain_text"+ },+ "value": "{event.properties.alert_id}|1h"+ },+ {+ "text": {+ "text": "For 6 hours",+ "type": "plain_text"+ },+ "value": "{event.properties.alert_id}|6h"+ },+ {+ "text": {+ "text": "For 1 day",+ "type": "plain_text"+ },+ "value": "{event.properties.alert_id}|1d"+ },+ {+ "text": {+ "text": "For 1 week",+ "type": "plain_text"+ },+ "value": "{event.properties.alert_id}|1w"+ },+ {+ "text": {+ "text": "Pick a date & time…",+ "type": "plain_text"+ },+ "value": "{event.properties.alert_id}|custom"+ }+ ],+ "placeholder": {+ "text": "Snooze…",+ "type": "plain_text"+ },+ "type": "static_select"+ }+ ],+ "type": "actions"+ }+ ],+ [+ {+ "text": {+ "text": "Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'",+ "type": "plain_text"+ },+ "type": "header"+ },+ {+ "text": {+ "text": "{event.properties.breaches}",+ "type": "plain_text"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": "Project: <{project.url}|{project.name}>",+ "type": "mrkdwn"+ }+ ],+ "type": "context"+ },+ {+ "type": "divider"+ },+ {+ "elements": [+ {+ "text": {+ "text": "View Insight",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}"+ },+ {+ "text": {+ "text": "View Alert",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}"+ }+ ],+ "type": "actions"+ }+ ],+ [+ {+ "text": {+ "text": "Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'",+ "type": "plain_text"+ },+ "type": "header"+ },+ {+ "text": {+ "text": "{event.properties.breaches}",+ "type": "plain_text"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": "Project: <{project.url}|{project.name}>",+ "type": "mrkdwn"+ }+ ],+ "type": "context"+ },+ {+ "type": "divider"+ },+ {+ "elements": [+ {+ "text": {+ "text": "View Insight",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}?utm_source=alert&utm_campaign=alert_check_firing&utm_medium=slack"+ },+ {+ "text": {+ "text": "View Alert",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}&utm_source=alert&utm_campaign=alert_check_firing&utm_medium=slack"+ }+ ],+ "type": "actions"+ }+ ],+ [+ {+ "text": {+ "text": "Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'",+ "type": "plain_text"+ },+ "type": "header"+ },+ {+ "text": {+ "text": "{event.properties.breaches}",+ "type": "plain_text"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": "Project: <{project.url}|{project.name}>",+ "type": "mrkdwn"+ }+ ],+ "type": "context"+ },+ {+ "type": "divider"+ },+ {+ "elements": [+ {+ "text": {+ "text": "{event.properties.investigation_notebook_url ? 'View Investigation' : 'View Alert'}",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{event.properties.investigation_notebook_url ? event.properties.investigation_notebook_url : concat(project.url, '/insights/', event.properties.insight_id, '/alerts?alert_id=', event.properties.alert_id, '&utm_source=alert&utm_campaign=alert_check_firing&utm_medium=slack')}"+ },+ {+ "text": {+ "text": "View Insight",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}?utm_source=alert&utm_campaign=alert_check_firing&utm_medium=slack"+ }+ ],+ "type": "actions"+ }+ ],+ [+ {+ "text": {+ "text": "Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'",+ "type": "plain_text"+ },+ "type": "header"+ },+ {+ "text": {+ "text": "{event.properties.breaches}",+ "type": "plain_text"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": "Project: <{project.url}|{project.name}>",+ "type": "mrkdwn"+ },+ {+ "text": "Alert: <{source.url}|{source.name}>",+ "type": "mrkdwn"+ }+ ],+ "type": "context"+ },+ "{event.properties.insight_chart_url ? {'type': 'image', 'image_url': event.properties.insight_chart_url, 'alt_text': 'Insight chart'} : {'type': 'divider'}}",+ {+ "elements": [+ {+ "text": {+ "text": "View Insight",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}"+ }+ ],+ "type": "actions"+ }+ ],+ [+ {+ "text": {+ "text": "Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'",+ "type": "plain_text"+ },+ "type": "header"+ },+ {+ "text": {+ "text": "{event.properties.breaches}",+ "type": "plain_text"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": "Project: <{project.url}|{project.name}>",+ "type": "mrkdwn"+ }+ ],+ "type": "context"+ },+ "{event.properties.insight_chart_url ? {'type': 'image', 'image_url': event.properties.insight_chart_url, 'alt_text': 'Insight chart'} : {'type': 'divider'}}",+ {+ "elements": [+ {+ "text": {+ "text": "View Insight",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}"+ },+ {+ "text": {+ "text": "View Alert",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}"+ }+ ],+ "type": "actions"+ }+ ],+ [+ {+ "text": {+ "text": "Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'",+ "type": "plain_text"+ },+ "type": "header"+ },+ {+ "text": {+ "text": "{event.properties.breaches}",+ "type": "plain_text"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": "Project: <{project.url}|{project.name}>",+ "type": "mrkdwn"+ }+ ],+ "type": "context"+ },+ "{event.properties.insight_chart_url ? {'type': 'image', 'image_url': event.properties.insight_chart_url, 'alt_text': 'Insight chart'} : {'type': 'divider'}}",+ {+ "elements": [+ {+ "text": {+ "text": "View Insight",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}?utm_source=alert&utm_campaign=alert_check_firing&utm_medium=slack"+ },+ {+ "text": {+ "text": "View Alert",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}&utm_source=alert&utm_campaign=alert_check_firing&utm_medium=slack"+ }+ ],+ "type": "actions"+ }+ ],+ [+ {+ "text": {+ "text": "Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'",+ "type": "plain_text"+ },+ "type": "header"+ },+ {+ "text": {+ "text": "{event.properties.breaches}",+ "type": "plain_text"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": "Project: <{project.url}|{project.name}>",+ "type": "mrkdwn"+ }+ ],+ "type": "context"+ },+ "{event.properties.insight_chart_url ? {'type': 'image', 'image_url': event.properties.insight_chart_url, 'alt_text': 'Insight chart'} : {'type': 'divider'}}",+ {+ "elements": [+ {+ "text": {+ "text": "{event.properties.investigation_notebook_url ? 'View Investigation' : 'View Alert'}",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{event.properties.investigation_notebook_url ? event.properties.investigation_notebook_url : concat(project.url, '/insights/', event.properties.insight_id, '/alerts?alert_id=', event.properties.alert_id, '&utm_source=alert&utm_campaign=alert_check_firing&utm_medium=slack')}"+ },+ {+ "text": {+ "text": "View Insight",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{project.url}/insights/{event.properties.insight_id}?utm_source=alert&utm_campaign=alert_check_firing&utm_medium=slack"+ }+ ],+ "type": "actions"+ }+ ],+ [+ {+ "type": "header",+ "text": {+ "type": "plain_text",+ "text": "Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'"+ }+ },+ {+ "type": "section",+ "text": {+ "type": "plain_text",+ "text": "{event.properties.breaches}"+ }+ },+ {+ "type": "context",+ "elements": [+ {+ "type": "mrkdwn",+ "text": "Project: <{project.url}|{project.name}>"+ }+ ]+ },+ "{event.properties.insight_chart_url ? {'type': 'image', 'image_url': event.properties.insight_chart_url, 'alt_text': 'Insight chart'} : {'type': 'divider'}}",+ {+ "type": "actions",+ "block_id": "insight_alert_snooze:{event.properties.alert_id}",+ "elements": [+ {+ "type": "button",+ "text": {+ "type": "plain_text",+ "text": "View Insight"+ },+ "url": "{project.url}/insights/{event.properties.insight_id}"+ },+ {+ "type": "button",+ "text": {+ "type": "plain_text",+ "text": "View Alert"+ },+ "url": "{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}"+ },+ {+ "type": "static_select",+ "action_id": "insight_alert_snooze",+ "placeholder": {+ "type": "plain_text",+ "text": "Snooze…"+ },+ "options": [+ {+ "text": {+ "type": "plain_text",+ "text": "For 1 hour"+ },+ "value": "{event.properties.alert_id}|1h"+ },+ {+ "text": {+ "type": "plain_text",+ "text": "For 6 hours"+ },+ "value": "{event.properties.alert_id}|6h"+ },+ {+ "text": {+ "type": "plain_text",+ "text": "For 1 day"+ },+ "value": "{event.properties.alert_id}|1d"+ },+ {+ "text": {+ "type": "plain_text",+ "text": "For 1 week"+ },+ "value": "{event.properties.alert_id}|1w"+ },+ {+ "text": {+ "type": "plain_text",+ "text": "Pick a date & time…"+ },+ "value": "{event.properties.alert_id}|custom"+ }+ ]+ }+ ]+ }+ ],+ [+ {+ "type": "header",+ "text": {+ "type": "plain_text",+ "text": "Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'"+ }+ },+ {+ "type": "section",+ "text": {+ "type": "plain_text",+ "text": "{event.properties.breaches}"+ }+ },+ {+ "type": "context",+ "elements": [+ {+ "type": "mrkdwn",+ "text": "Project: <{project.url}|{project.name}>"+ }+ ]+ },+ {+ "type": "divider"+ },+ {+ "type": "actions",+ "block_id": "insight_alert_snooze:{event.properties.alert_id}",+ "elements": [+ {+ "type": "button",+ "text": {+ "type": "plain_text",+ "text": "View Insight"+ },+ "url": "{project.url}/insights/{event.properties.insight_id}"+ },+ {+ "type": "button",+ "text": {+ "type": "plain_text",+ "text": "View Alert"+ },+ "url": "{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}"+ },+ {+ "type": "static_select",+ "action_id": "insight_alert_snooze",+ "placeholder": {+ "type": "plain_text",+ "text": "Snooze…"+ },+ "options": [+ {+ "text": {+ "type": "plain_text",+ "text": "For 1 hour"+ },+ "value": "{event.properties.alert_id}|1h"+ },+ {+ "text": {+ "type": "plain_text",+ "text": "For 6 hours"+ },+ "value": "{event.properties.alert_id}|6h"+ },+ {+ "text": {+ "type": "plain_text",+ "text": "For 1 day"+ },+ "value": "{event.properties.alert_id}|1d"+ },+ {+ "text": {+ "type": "plain_text",+ "text": "For 1 week"+ },+ "value": "{event.properties.alert_id}|1w"+ },+ {+ "text": {+ "type": "plain_text",+ "text": "Pick a date & time…"+ },+ "value": "{event.properties.alert_id}|custom"+ }+ ]+ }+ ]+ }+ ]+ ],+ "body": [+ {+ "blocks": [+ {+ "text": {+ "text": "*{person.name}* triggered event: '{event.name}'",+ "type": "mrkdwn"+ },+ "type": "section"+ },+ {+ "elements": [+ {+ "text": {+ "text": "View Person in PostHog",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{person.url}"+ },+ {+ "text": {+ "text": "Message source",+ "type": "plain_text"+ },+ "type": "button",+ "url": "{source.url}"+ }+ ],+ "type": "actions"+ }+ ]+ }+ ],+ "icon_emoji": [":hedgehog:"],+ "text": [+ "*{person.name}* triggered event: '{event.event}'",+ "Alert triggered: {event.properties.insight_name}"+ ],+ "username": ["PostHog"]+ },+ "template-webhook": {+ "body": [+ {+ "alert_name": "{event.properties.alert_name}",+ "alert_url": "{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}",+ "breaches": "{event.properties.breaches}",+ "insight_name": "{event.properties.insight_name}",+ "insight_url": "{project.url}/insights/{event.properties.insight_id}"+ },+ {+ "event": "{event}",+ "person": "{person}"+ }+ ],+ "headers": [+ {+ "Content-Type": "application/json"+ }+ ],+ "method": ["POST"]+ }+}diff --git a/products/alerts/backend/test/test_destination_eligibility.py b/products/alerts/backend/test/test_destination_eligibility.pyindex e377cc8a569d..d6159dbb59f5 100644--- a/products/alerts/backend/test/test_destination_eligibility.py+++ b/products/alerts/backend/test/test_destination_eligibility.py@@ -9,13 +9,20 @@ from django.test import SimpleTestCasefrom parameterized import parameterized-from products.alerts.backend.facade.contracts import DestinationBucket, DestinationEligibility, DestinationHoldBack+from products.alerts.backend.facade.contracts import (+ INSIGHT_ALERT_EVENT_IDS,+ DestinationBucket,+ DestinationEligibility,+ DestinationHoldBack,+)from products.alerts.backend.facade.destinations import (bucket_for,classify_alert_destinations,unbound_alert_destinations,)from products.alerts.backend.logic.destination_bucket_report import bucketed_destinations+from products.alerts.backend.logic.insight_alert_destinations import build_insight_alert_slack_config+from products.alerts_platform.backend.facade.contracts import AlertDestinationData, DestinationTypefrom products.cdp.backend.models.hog_functions.hog_function import HogFunctionfrom products.cdp.backend.models.hog_functions.hog_function_revision import HogFunctionRevision@@ -32,6 +39,11 @@ PAGERDUTY_INPUTS: dict[str, Any] = {"severity": {"value": "critical"},"region": {"value": "us"},}+INSIGHT_SLACK_DATA: AlertDestinationData = {+ "type": DestinationType.SLACK,+ "slack_workspace_id": 1,+ "slack_channel_id": "C-1",+}SLACK_INPUTS: dict[str, Any] = {"slack_workspace": {"value": 1},"channel": {"value": "C-1"},@@ -342,6 +354,55 @@ class TestDestinationEligibility(APIBaseTest):]assert [d.alert_id for d in report] == [None, None, ALERT_ID, other_alert]+ @parameterized.expand(+ [+ ("stock_blocks", {}, False, ()),+ ("text_edited_before_the_first_save", {"text": "Look at this"}, True, (DestinationHoldBack.MESSAGE,)),+ ("text_edited_with_no_revision", {"text": "Look at this"}, False, (DestinationHoldBack.MESSAGE,)),+ ("an_emptied_text", {"text": ""}, False, ()),+ (+ "stock_text_rendered_as_liquid",+ {"text": {"value": "Alert triggered: {event.properties.insight_name}", "templating": "liquid"}},+ False,+ (DestinationHoldBack.MESSAGE,),+ ),+ (+ "an_agent_chosen_emoji",+ {"icon_emoji": ":rotating_light:"},+ True,+ (DestinationHoldBack.MESSAGE_COSMETIC,),+ ),+ ]+ )+ def test_an_insight_destination_is_compared_with_the_shipped_defaults(+ self, _name: str, changes: dict[str, Any], revised: bool, expected: tuple[DestinationHoldBack, ...]+ ) -> None:+ (event,) = INSIGHT_ALERT_EVENT_IDS+ stock = build_insight_alert_slack_config(+ alert_id=ALERT_ID,+ alert_name="API errors",+ data=INSIGHT_SLACK_DATA,+ ).payload+ function = self._function(+ "template-slack",+ {+ **stock["inputs"],+ **{key: value if isinstance(value, dict) else {"value": value} for key, value in changes.items()},+ },+ )+ HogFunction.objects.filter(pk=function.pk).update(filters=stock["filters"])+ if revised:+ function.refresh_from_db()+ self._edited(function)++ (eligibility,) = classify_alert_destinations(team_id=self.team.id, alert_id=ALERT_ID, allowed_event_ids=[event])+ assert eligibility.hold_backs == expected++ def test_a_logs_destination_is_not_compared_with_insight_defaults(self) -> None:+ self._function("template-slack", _with(SLACK_INPUTS, "text", "Look at this"))++ assert self._classify() == ()+class TestBucketFor(SimpleTestCase):@parameterized.expand(