: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): offer group by on a team's first logs alert (#127858)
Jimmy Zhu3631a2f49264
diff --git a/products/logs/frontend/components/LogsAlerting/__tests__/logsAlertFormLogic.test.ts b/products/logs/frontend/components/LogsAlerting/__tests__/logsAlertFormLogic.test.tsindex 9e79ccade74b..fbe6deeff892 100644--- a/products/logs/frontend/components/LogsAlerting/__tests__/logsAlertFormLogic.test.ts+++ b/products/logs/frontend/components/LogsAlerting/__tests__/logsAlertFormLogic.test.ts@@ -546,6 +546,7 @@ describe('logsAlertFormLogic', () => {['alert the source owns in a team that has cut over', MOCK_ALERT, [PLATFORM_ALERT], false],['alert the platform owns', PLATFORM_ALERT, [], true],['alert that already groups', GROUPED_BY_SERVICE_ALERT, [], true],+ ['new alert in a team that has no alerts', null, [], true],['new alert in a team that has not cut over', null, [MOCK_ALERT], false],['new alert in a team that has cut over', null, [MOCK_ALERT, PLATFORM_ALERT], true],])('can group for %s', async (_, alert, teamAlerts, expected) => {diff --git a/products/logs/frontend/components/LogsAlerting/logsAlertFormLogic.ts b/products/logs/frontend/components/LogsAlerting/logsAlertFormLogic.tsindex 56d2a6a860eb..081811733137 100644--- a/products/logs/frontend/components/LogsAlerting/logsAlertFormLogic.ts+++ b/products/logs/frontend/components/LogsAlerting/logsAlertFormLogic.ts@@ -126,6 +126,8 @@ export interface logsAlertFormLogicValues {featureFlags: FeatureFlagsSet // featureFlagLogicpendingNotifications: PendingLogsAlertNotification[] // logsAlertNotificationLogicalerts: LogsAlertConfigurationApi[] // logsAlertingLogic+ alertsLoaded: boolean // logsAlertingLogic+ createdByFilter: string | null // logsAlertingLogiccurrentTeamId: number | null // teamLogicalertForm: LogsAlertFormTypealertFormAllErrors: Record<string, any>@@ -266,7 +268,13 @@ export interface logsAlertFormLogicMeta {__keaTypeGenInternalSelectorTypes: {isEditing: (arg: any) => booleangroupingFlagEnabled: (featureFlags: FeatureFlagsSet) => boolean- canGroup: (arg: any, alerts: LogsAlertConfigurationApi[], groupingFlagEnabled: boolean) => boolean+ canGroup: (+ arg: any,+ alerts: LogsAlertConfigurationApi[],+ alertsLoaded: boolean,+ createdByFilter: string | null,+ groupingFlagEnabled: boolean+ ) => booleanlockedGroupBy: (arg: any, groupingFlagEnabled: boolean) => LogsAlertGroupBy | nullregroupConfirmation: (arg: any) => stringneedsRegroupConfirmation: (arg: any, canGroup: boolean, alertForm: LogsAlertFormType) => boolean@@ -291,7 +299,7 @@ export const logsAlertFormLogic = kea<logsAlertFormLogicType>([teamLogic,['currentTeamId'],logsAlertingLogic,- ['alerts'],+ ['alerts', 'alertsLoaded', 'createdByFilter'],featureFlagLogic,['featureFlags'],logsAlertNotificationLogic({ alertId: alert?.id }),@@ -408,12 +416,19 @@ export const logsAlertFormLogic = kea<logsAlertFormLogicType>([(featureFlags: FeatureFlagsSet): boolean => !!featureFlags[FEATURE_FLAGS.LOGS_ALERTS_GROUPING],],canGroup: [- (s) => [(_, props) => props.alert, s.alerts, s.groupingFlagEnabled],+ (s) => [(_, props) => props.alert, s.alerts, s.alertsLoaded, s.createdByFilter, s.groupingFlagEnabled],(alert: LogsAlertConfigurationApi | null,alerts: LogsAlertConfigurationApi[],+ alertsLoaded: boolean,+ createdByFilter: string | null,groupingFlagEnabled: boolean- ): boolean => canGroupAlert(alert, alerts, groupingFlagEnabled),+ ): boolean =>+ canGroupAlert(+ alert,+ alertsLoaded ? { alerts, complete: createdByFilter === null } : null,+ groupingFlagEnabled+ ),],lockedGroupBy: [(s) => [(_, props) => props.alert, s.groupingFlagEnabled],diff --git a/products/logs/frontend/components/LogsAlerting/logsAlertGrouping.ts b/products/logs/frontend/components/LogsAlerting/logsAlertGrouping.tsindex 638b8beb3084..f11ed01c0ec1 100644--- a/products/logs/frontend/components/LogsAlerting/logsAlertGrouping.ts+++ b/products/logs/frontend/components/LogsAlerting/logsAlertGrouping.ts@@ -77,14 +77,22 @@ export function isRegroup(alert: LogsAlertConfigurationApi | null, groupBy: Logsreturn alert !== null && groupByOf(alert.grouping) !== groupBy}+/** The team's logs alerts as the alert list loaded them. A created-by filter on the list hides some of them. */+export interface LoadedTeamAlerts {+ alerts: LogsAlertConfigurationApi[]+ complete: boolean+}+/**- * Only an alert the alerts platform evaluates can group. A new alert goes to the platform once the- * team has any logs alert there, which mirrors the backend's cutover check. An alert that already- * groups keeps the field even with the flag off, so its grouping stays visible and can be removed.+ * Only an alert the alerts platform evaluates can group. A new alert goes to the platform when the+ * platform owns another of the team's alerts, or when the team has no other alert, which mirrors the+ * backend's cutover check. Until the team's alerts load, an empty list says nothing, so a new alert+ * can't group yet. An alert that already groups keeps the field even with the flag off, so its+ * grouping stays visible and can be removed.*/export function canGroupAlert(alert: LogsAlertConfigurationApi | null,- teamAlerts: LogsAlertConfigurationApi[],+ teamAlerts: LoadedTeamAlerts | null,groupingFlagEnabled: boolean): boolean {if (alert?.grouping?.mode === GroupingModeEnumApi.ByResultLabels) {@@ -93,7 +101,16 @@ export function canGroupAlert(if (!groupingFlagEnabled) {return false}- return alert ? alert.platform_owned : teamAlerts.some((candidate) => candidate.platform_owned)+ if (alert) {+ return alert.platform_owned+ }+ if (!teamAlerts) {+ return false+ }+ return (+ teamAlerts.alerts.some((candidate) => candidate.platform_owned) ||+ (teamAlerts.complete && teamAlerts.alerts.length === 0)+ )}/** What a save that changes the grouping does to the state the alert tracks now. */diff --git a/products/logs/frontend/components/LogsAlerting/logsAlertingLogic.ts b/products/logs/frontend/components/LogsAlerting/logsAlertingLogic.tsindex 9bf5ba6314b4..cefc33639a68 100644--- a/products/logs/frontend/components/LogsAlerting/logsAlertingLogic.ts+++ b/products/logs/frontend/components/LogsAlerting/logsAlertingLogic.ts@@ -27,6 +27,7 @@ const ALERT_POLL_INTERVAL_MS = 30_000export interface logsAlertingLogicValues {currentTeamId: number | null // teamLogicalerts: LogsAlertConfigurationApi[]+ alertsLoaded: booleanalertsLoading: booleancreatedByFilter: string | nulleditingAlert: LogsAlertConfigurationApi | null@@ -143,6 +144,14 @@ export const logsAlertingLogic = kea<logsAlertingLogicType>([}),reducers({+ // An empty list only means the team has no alerts once a load for the current filter succeeds.+ alertsLoaded: [+ false,+ {+ setCreatedByFilter: () => false,+ loadAlertsSuccess: () => true,+ },+ ],createdByFilter: [null as string | null,{