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(data-warehouse): add sync alerts to the sources page and source tabs (#114397)

Tom Owersc4e452d57a5f
diff --git a/products/data_warehouse/frontend/scenes/SourceScene/SourceScene.tsx b/products/data_warehouse/frontend/scenes/SourceScene/SourceScene.tsx
index 916dc37659dd..86cebc4dcceb 100644
--- a/products/data_warehouse/frontend/scenes/SourceScene/SourceScene.tsx
+++ b/products/data_warehouse/frontend/scenes/SourceScene/SourceScene.tsx
@@ -42,6 +42,7 @@ import {
SidePanelTab,
} from '~/types'
+import { SourceAlerts } from 'products/data_warehouse/frontend/shared/sourceAlerts/SourceAlerts'
import { cleanSourceId, isSelfManagedSourceId } from 'products/data_warehouse/frontend/utils'
import { ConfigurationTab } from './tabs/ConfigurationTab'
@@ -60,6 +61,7 @@ const SOURCE_SCENE_TABS = [
'configuration',
'webhook',
'history',
+ 'alerts',
] as const
export type SourceSceneTab = (typeof SOURCE_SCENE_TABS)[number]
@@ -102,13 +104,13 @@ export interface sourceSceneLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sourceSceneLogicActions {
_setCurrentTab: (tab: SourceSceneTab) => {
- tab: 'configuration' | 'destinations' | 'history' | 'metrics' | 'schemas' | 'syncs' | 'webhook'
+ tab: 'alerts' | 'configuration' | 'destinations' | 'history' | 'metrics' | 'schemas' | 'syncs' | 'webhook'
}
setBreadcrumbName: (name: string) => {
name: string
}
setCurrentTab: (tab: SourceSceneTab) => {
- tab: 'configuration' | 'destinations' | 'history' | 'metrics' | 'schemas' | 'syncs' | 'webhook'
+ tab: 'alerts' | 'configuration' | 'destinations' | 'history' | 'metrics' | 'schemas' | 'syncs' | 'webhook'
}
}
@@ -247,6 +249,7 @@ export function SourceScene({ id }: SourceSceneProps): JSX.Element {
{isManagedSourceSceneId(id) ? (
<ManagedSourceTabs
sourceId={sourceId}
+ sourceName={breadcrumbName}
currentTab={currentTab}
setCurrentTab={setCurrentTab}
attachTo={logic}
@@ -271,11 +274,13 @@ export function SourceScene({ id }: SourceSceneProps): JSX.Element {
function ManagedSourceTabs({
sourceId,
+ sourceName,
currentTab,
setCurrentTab,
attachTo,
}: {
sourceId: string
+ sourceName: string
currentTab: SourceSceneTab
setCurrentTab: (tab: SourceSceneTab) => void
attachTo: BuiltLogic | LogicWrapper
@@ -291,6 +296,7 @@ function ManagedSourceTabs({
const showWebhookTab = !!source?.supports_webhooks
const showDestinationsTab = !!featureFlags[FEATURE_FLAGS.WAREHOUSE_MULTI_DESTINATION]
const showMetricsTab = shouldShowManagedSourceMetricsTab(source, !!featureFlags[FEATURE_FLAGS.DWH_SOURCE_METRICS])
+ const showAlertsTab = !!featureFlags[FEATURE_FLAGS.DWH_SYNC_ALERTS]
useEffect(() => {
// Wait until the source has loaded before deciding a tab is unavailable.
@@ -309,7 +315,10 @@ function ManagedSourceTabs({
if (!showMetricsTab && currentTab === 'metrics') {
setCurrentTab('schemas')
}
- }, [source, showSyncsTab, showWebhookTab, showMetricsTab, currentTab, setCurrentTab])
+ if (!showAlertsTab && currentTab === 'alerts') {
+ setCurrentTab('schemas')
+ }
+ }, [source, showSyncsTab, showWebhookTab, showMetricsTab, showAlertsTab, currentTab, setCurrentTab])
if (sourceLoading && !source) {
return <LemonSkeleton className="w-full h-12" />
@@ -344,6 +353,14 @@ function ManagedSourceTabs({
})
}
+ if (showAlertsTab) {
+ tabs.push({
+ label: 'Alerts',
+ key: 'alerts',
+ content: <SourceAlerts sourceId={sourceId} sourceName={sourceName} />,
+ })
+ }
+
tabs.push({
label: 'History',
key: 'history',
diff --git a/products/data_warehouse/frontend/scenes/SourcesScene/SourcesList.tsx b/products/data_warehouse/frontend/scenes/SourcesScene/SourcesList.tsx
index e5d5abb6b04c..3c9199f4641b 100644
--- a/products/data_warehouse/frontend/scenes/SourcesScene/SourcesList.tsx
+++ b/products/data_warehouse/frontend/scenes/SourcesScene/SourcesList.tsx
@@ -4,6 +4,7 @@ import { IconPlusSmall } from '@posthog/icons'
import { LemonButton, LemonTag } from '@posthog/lemon-ui'
import { FlaggedFeature } from 'lib/components/FlaggedFeature'
+import { FEATURE_FLAGS } from 'lib/constants'
import { HogFunctionList } from 'scenes/hog-functions/list/HogFunctionsList'
import { urls } from 'scenes/urls'
@@ -17,6 +18,7 @@ import {
import { DirectConnectSourcesTable } from 'products/data_warehouse/frontend/shared/components/DirectConnectSourcesTable'
import { ManagedSourcesTable } from 'products/data_warehouse/frontend/shared/components/ManagedSourcesTable'
import { SelfManagedSourcesTable } from 'products/data_warehouse/frontend/shared/components/SelfManagedSourcesTable'
+import { SourceAlerts } from 'products/data_warehouse/frontend/shared/sourceAlerts/SourceAlerts'
export function SourcesList(): JSX.Element {
return (
@@ -88,6 +90,18 @@ export function SourcesList(): JSX.Element {
>
<SelfManagedSourcesTable />
</SceneSection>
+
+ <FlaggedFeature flag={FEATURE_FLAGS.DWH_SYNC_ALERTS}>
+ <>
+ <SceneDivider />
+ <SceneSection
+ title="Alerts"
+ description="Get a message in Slack, Discord, Teams, or a webhook when a source sync fails, recovers, or finishes"
+ >
+ <SourceAlerts />
+ </SceneSection>
+ </>
+ </FlaggedFeature>
</div>
)
}
diff --git a/products/data_warehouse/frontend/shared/sourceAlerts/SourceAlerts.tsx b/products/data_warehouse/frontend/shared/sourceAlerts/SourceAlerts.tsx
new file mode 100644
index 000000000000..d33312cbe0dc
--- /dev/null
+++ b/products/data_warehouse/frontend/shared/sourceAlerts/SourceAlerts.tsx
@@ -0,0 +1,154 @@
+import { BindLogic, useActions, useMountedLogic, useValues } from 'kea'
+import posthog from 'posthog-js'
+
+import { LemonButton } from '@posthog/lemon-ui'
+
+import { AlertWizard } from 'lib/components/Alerting/AlertWizard/AlertWizard'
+import {
+ AlertCreationView,
+ AlertWizardLogicProps,
+ alertWizardLogic,
+ decorateAlertName,
+} from 'lib/components/Alerting/AlertWizard/alertWizardLogic'
+import { Link } from 'lib/lemon-ui/Link'
+import { HogFunctionList } from 'scenes/hog-functions/list/HogFunctionsList'
+import { HogFunctionTemplateList } from 'scenes/hog-functions/list/HogFunctionTemplateList'
+import { getFiltersFromSubTemplateId } from 'scenes/hog-functions/list/LinkedHogFunctions'
+import { urls } from 'scenes/urls'
+
+import { HogFunctionSubTemplateType } from '~/types'
+
+import {
+ buildSourceAlertFilterGroups,
+ buildSourceAlertNameSuffix,
+ buildSourceAlertPropertyFilters,
+} from './sourceAlertFilters'
+import { sourceAlertsLogic } from './sourceAlertsLogic'
+import {
+ SOURCE_ALERT_DESTINATIONS,
+ SOURCE_ALERT_SUB_TEMPLATE_IDS,
+ SOURCE_ALERT_TRIGGERS,
+} from './sourceAlertWizardConfig'
+
+export interface SourceAlertsProps {
+ sourceId?: string
+ sourceName?: string
+}
+
+export function SourceAlerts({ sourceId, sourceName }: SourceAlertsProps): JSX.Element {
+ useMountedLogic(sourceAlertsLogic({ sourceId }))
+
+ const wizardProps: AlertWizardLogicProps = {
+ logicKey: `data-warehouse-alerts-${sourceId ?? 'project'}`,
+ subTemplateIds: SOURCE_ALERT_SUB_TEMPLATE_IDS,
+ triggers: SOURCE_ALERT_TRIGGERS,
+ destinations: SOURCE_ALERT_DESTINATIONS,
+ contextId: 'data-warehouse-alerts',
+ presetPropertyFilters: buildSourceAlertPropertyFilters(sourceId),
+ nameSuffix: buildSourceAlertNameSuffix(sourceId, sourceName),
+ createdEventName: 'data_warehouse_alert_created',
+ }
+
+ return (
+ <BindLogic logic={alertWizardLogic} props={wizardProps}>
+ <SourceAlertsInner sourceId={sourceId} sourceName={sourceName} />
+ </BindLogic>
+ )
+}
+
+function SourceAlertsInner({ sourceId, sourceName }: SourceAlertsProps): JSX.Element {
+ const { alertCreationView, subTemplateIds } = useValues(alertWizardLogic)
+ const { setAlertCreationView, resetWizard } = useActions(alertWizardLogic)
+
+ const surface = sourceId ? 'source_tab' : 'sources_page'
+
+ if (alertCreationView === AlertCreationView.Wizard) {
+ return (
+ <AlertWizard
+ onCancel={() => {
+ setAlertCreationView(AlertCreationView.None)
+ resetWizard()
+ }}
+ onSwitchToTraditional={() => {
+ posthog.capture('data_warehouse_alert_creation_switched_to_traditional', { surface })
+ setAlertCreationView(AlertCreationView.Traditional)
+ resetWizard()
+ }}
+ />
+ )
+ }
+
+ if (alertCreationView === AlertCreationView.Traditional) {
+ const properties = buildSourceAlertPropertyFilters(sourceId)
+ const nameSuffix = buildSourceAlertNameSuffix(sourceId, sourceName)
+
+ return (
+ <HogFunctionTemplateList
+ type="destination"
+ subTemplateIds={subTemplateIds}
+ getConfigurationOverrides={(id, subTemplate) => {
+ const filters = id ? getFiltersFromSubTemplateId(id) : undefined
+ if (!filters) {
+ return undefined
+ }
+ const overrides: Partial<HogFunctionSubTemplateType> = {
+ filters: properties.length > 0 ? { ...filters, properties } : filters,
+ }
+ if (nameSuffix && subTemplate?.name) {
+ overrides.name = decorateAlertName(subTemplate.name, null, nameSuffix)
+ }
+ return overrides
+ }}
+ extraControls={
+ <LemonButton
+ type="secondary"
+ size="small"
+ onClick={() => setAlertCreationView(AlertCreationView.None)}
+ >
+ Cancel
+ </LemonButton>
+ }
+ />
+ )
+ }
+
+ return (
+ <div className="flex flex-col gap-2">
+ {sourceId ? (
+ <p className="text-secondary mb-0">
+ These alerts apply to this source only. Alerts for all sources are on the{' '}
+ <Link to={urls.sources()}>Sources page</Link>.
+ </p>
+ ) : null}
+ <HogFunctionList
+ forceFilterGroups={buildSourceAlertFilterGroups(sourceId)}
+ type="internal_destination"
+ returnTo={sourceId ? urls.dataWarehouseSource(`managed-${sourceId}`, 'alerts') : urls.sources()}
+ emptyText={
+ sourceId
+ ? 'No alerts for this source yet. Create an alert to send a message to Slack, Discord, Teams, or a webhook when a sync fails, recovers, or finishes.'
+ : 'No alerts yet. Create an alert to send a message to Slack, Discord, Teams, or a webhook when a sync fails, recovers, or finishes.'
+ }
+ onDeleteHogFunction={(hogFunction) => {
+ posthog.capture('data_warehouse_alert_deleted', { hog_function_id: hogFunction.id, surface })
+ }}
+ onEditHogFunction={(hogFunction) => {
+ posthog.capture('data_warehouse_alert_edit_clicked', { hog_function_id: hogFunction.id, surface })
+ }}
+ extraControls={
+ <LemonButton
+ type="primary"
+ size="small"
+ data-attr="new-data-warehouse-alert"
+ onClick={() => {
+ posthog.capture('data_warehouse_alert_creation_started', { surface })
+ setAlertCreationView(AlertCreationView.Wizard)
+ }}
+ >
+ New alert
+ </LemonButton>
+ }
+ />
+ </div>
+ )
+}
diff --git a/products/data_warehouse/frontend/shared/sourceAlerts/sourceAlertFilters.test.ts b/products/data_warehouse/frontend/shared/sourceAlerts/sourceAlertFilters.test.ts
new file mode 100644
index 000000000000..deebdbbc64d3
--- /dev/null
+++ b/products/data_warehouse/frontend/shared/sourceAlerts/sourceAlertFilters.test.ts
@@ -0,0 +1,44 @@
+import {
+ buildSourceAlertFilterGroups,
+ buildSourceAlertNameSuffix,
+ buildSourceAlertPropertyFilters,
+} from './sourceAlertFilters'
+import { SOURCE_ALERT_SUB_TEMPLATE_IDS } from './sourceAlertWizardConfig'
+
+describe('sourceAlertFilters', () => {
+ const sourceFilter = { key: 'source_id', type: 'event', value: 'abc-123', operator: 'exact' }
+
+ it.each([
+ ['no source id', undefined, []],
+ ['empty source id', '', []],
+ ['a source id', 'abc-123', [sourceFilter]],
+ ])('builds property filters for %s', (_name, sourceId, expected) => {
+ expect(buildSourceAlertPropertyFilters(sourceId)).toEqual(expected)
+ })
+
+ it('builds one bare event filter per alert type at project level', () => {
+ const groups = buildSourceAlertFilterGroups()
+ expect(groups).toHaveLength(SOURCE_ALERT_SUB_TEMPLATE_IDS.length)
+ groups.forEach((group) => {
+ expect(group.source).toBe('internal-events')
+ expect(group.events).toHaveLength(1)
+ expect(group.properties).toBeUndefined()
+ })
+ })
+
+ it('adds the source filter to every event filter for one source', () => {
+ const groups = buildSourceAlertFilterGroups('abc-123')
+ expect(groups).toHaveLength(SOURCE_ALERT_SUB_TEMPLATE_IDS.length)
+ groups.forEach((group) => {
+ expect(group.properties).toEqual([sourceFilter])
+ })
+ })
+
+ it.each([
+ ['both set', 'abc-123', 'Stripe', 'for Stripe'],
+ ['no name', 'abc-123', undefined, undefined],
+ ['no source id', undefined, 'Stripe', undefined],
+ ])('builds the name suffix with %s', (_name, sourceId, sourceName, expected) => {
+ expect(buildSourceAlertNameSuffix(sourceId, sourceName)).toBe(expected)
+ })
+})
diff --git a/products/data_warehouse/frontend/shared/sourceAlerts/sourceAlertFilters.ts b/products/data_warehouse/frontend/shared/sourceAlerts/sourceAlertFilters.ts
new file mode 100644
index 000000000000..d4795b4c2057
--- /dev/null
+++ b/products/data_warehouse/frontend/shared/sourceAlerts/sourceAlertFilters.ts
@@ -0,0 +1,39 @@
+import { getFiltersFromSubTemplateId } from 'scenes/hog-functions/list/LinkedHogFunctions'
+
+import {
+ CyclotronJobFilterPropertyFilter,
+ CyclotronJobFiltersType,
+ PropertyFilterType,
+ PropertyOperator,
+} from '~/types'
+
+import { SOURCE_ALERT_SUB_TEMPLATE_IDS } from './sourceAlertWizardConfig'
+
+export function buildSourceAlertPropertyFilters(sourceId?: string): CyclotronJobFilterPropertyFilter[] {
+ if (!sourceId) {
+ return []
+ }
+ return [
+ {
+ key: 'source_id',
+ type: PropertyFilterType.Event,
+ value: sourceId,
+ operator: PropertyOperator.Exact,
+ },
+ ]
+}
+
+export function buildSourceAlertFilterGroups(sourceId?: string): CyclotronJobFiltersType[] {
+ const properties = buildSourceAlertPropertyFilters(sourceId)
+ return SOURCE_ALERT_SUB_TEMPLATE_IDS.flatMap((id) => {
+ const filters = getFiltersFromSubTemplateId(id)
+ if (!filters) {
+ return []
+ }
+ return [properties.length > 0 ? { ...filters, properties } : filters]
+ })
+}
+
+export function buildSourceAlertNameSuffix(sourceId?: string, sourceName?: string): string | undefined {
+ return sourceId && sourceName ? `for ${sourceName}` : undefined
+}
diff --git a/products/data_warehouse/frontend/shared/sourceAlerts/sourceAlertWizardConfig.ts b/products/data_warehouse/frontend/shared/sourceAlerts/sourceAlertWizardConfig.ts
new file mode 100644
index 000000000000..ae03004e273c
--- /dev/null
+++ b/products/data_warehouse/frontend/shared/sourceAlerts/sourceAlertWizardConfig.ts
@@ -0,0 +1,64 @@
+import { WizardDestination, WizardTrigger } from 'lib/components/Alerting/AlertWizard/alertWizardLogic'
+
+import { HogFunctionSubTemplateIdType } from '~/types'
+
+export const SOURCE_ALERT_SUB_TEMPLATE_IDS: HogFunctionSubTemplateIdType[] = [
+ 'data-warehouse-sync-failed',
+ 'data-warehouse-sync-recovered',
+ 'data-warehouse-sync-completed',
+ 'data-warehouse-billing-limit-reached',
+]
+
+export const SOURCE_ALERT_TRIGGERS: WizardTrigger[] = [
+ {
+ key: 'data-warehouse-sync-failed',
+ name: 'Sync failed',
+ description: 'Get notified when a sync fails',
+ },
+ {
+ key: 'data-warehouse-sync-recovered',
+ name: 'Sync recovered',
+ description: 'Get notified when a sync works again after it failed',
+ },
+ {
+ key: 'data-warehouse-sync-completed',
+ name: 'Sync completed',
+ description: 'Get notified when a sync finishes',
+ },
+ {
+ key: 'data-warehouse-billing-limit-reached',
+ name: 'Billing limit reached',
+ description: 'Get notified when a sync stops because of your billing limit',
+ },
+]
+
+export const SOURCE_ALERT_DESTINATIONS: WizardDestination[] = [
+ {
+ key: 'slack',
+ name: 'Slack',
+ description: 'Send a message to a channel',
+ icon: '/static/services/slack.png',
+ templateId: 'template-slack',
+ },
+ {
+ key: 'discord',
+ name: 'Discord',
+ description: 'Post a notification via webhook',
+ icon: '/static/services/discord.png',
+ templateId: 'template-discord',
+ },
+ {
+ key: 'microsoft-teams',
+ name: 'Teams',
+ description: 'Send a message to a channel',
+ icon: '/static/services/microsoft-teams.png',
+ templateId: 'template-microsoft-teams',
+ },
+ {
+ key: 'webhook',
+ name: 'Webhook',
+ description: 'Send an HTTP request to any URL',
+ icon: '/static/services/webhook.svg',
+ templateId: 'template-webhook',
+ },
+]
diff --git a/products/data_warehouse/frontend/shared/sourceAlerts/sourceAlertsLogic.ts b/products/data_warehouse/frontend/shared/sourceAlerts/sourceAlertsLogic.ts
new file mode 100644
index 000000000000..774d28e1cdd3
--- /dev/null
+++ b/products/data_warehouse/frontend/shared/sourceAlerts/sourceAlertsLogic.ts
@@ -0,0 +1,24 @@
+import { LogicWrapper, MakeLogicType, afterMount, kea, key, path, props } from 'kea'
+import posthog from 'posthog-js'
+
+export interface SourceAlertsLogicProps {
+ sourceId?: string
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface sourceAlertsLogicMeta {
+ key: string
+}
+
+export type sourceAlertsLogicType = MakeLogicType<{}, {}, SourceAlertsLogicProps, sourceAlertsLogicMeta>
+
+export const sourceAlertsLogic: LogicWrapper<sourceAlertsLogicType> = kea<sourceAlertsLogicType>([
+ props({} as SourceAlertsLogicProps),
+ key((props) => props.sourceId ?? 'project'),
+ path((key) => ['products', 'dataWarehouse', 'sourceAlerts', 'sourceAlertsLogic', key]),
+ afterMount(({ props }) => {
+ posthog.capture('data_warehouse_alerts_viewed', {
+ surface: props.sourceId ? 'source_tab' : 'sources_page',
+ })
+ }),
+])