: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
fix(alerts): allow one-sided thresholds (#72965)
Matt Puad94e4dbc7bd1
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 5d8119d64439..11f2f2f8b41b 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -4709,7 +4709,7 @@ snapshots:products-alerts-alert-modal--create-wizard--dark:hash: v1.k794b7964.e3efb1235db76f2fe8b3ccff465df9b84263211b8648d57a725cfcf3a92c08c9.mTtZUY5-gkDVf9yjhBIR_Cx1_5arKEIEJh-2g-cLQBQproducts-alerts-alert-modal--create-wizard--light:- hash: v1.k794b7964.5d3e5771de5e54394886c7912e522f324add97132f71b60692b5d6efaeb8fdd3.mki0HDX74WZcOqtylWsX2ebTI-U1tVS9-5XcmKpY-bo+ hash: v1.k794b7964.494bd726adc6e478744c5418538e1e5bc6e3afdffd7ffc6ee5db7f9447736ad8.XrOtsQ190MyCOe3g_QspkQn_2iNZXZmb0QaWh1xt-t8products-alerts-alert-modal--edit-alert--dark:hash: v1.k794b7964.1b0b3ec51cc999c02f8442559b676a2e2f352998c0f3d4a9b10da7da8fc3aac1.ZktPS8oprYMZQ-rLsncCgMlyidqF97zUzqDfKjQGo1Aproducts-alerts-alert-modal--edit-alert--light:diff --git a/products/alerts/frontend/logic/alertFormLogic.test.ts b/products/alerts/frontend/logic/alertFormLogic.test.tsindex 1193fe41d9d3..508a3cfbfe19 100644--- a/products/alerts/frontend/logic/alertFormLogic.test.ts+++ b/products/alerts/frontend/logic/alertFormLogic.test.ts@@ -196,7 +196,7 @@ describe('alertFormLogic', () => {it.each([['legacy', 'legacy' as const, '', {}],- ['redesigned', 'redesigned' as const, 'Weekly signups alert', { upper: 1 }],+ ['redesigned', 'redesigned' as const, 'Weekly signups alert', {}],])('keeps %s creation defaults scoped to its UI', (_name, uiVersion, expectedName, expectedBounds) => {const logic = alertFormLogic({alert: null,diff --git a/products/alerts/frontend/logic/alertFormLogic.ts b/products/alerts/frontend/logic/alertFormLogic.tsindex c1568506df55..9fb974ae3b2c 100644--- a/products/alerts/frontend/logic/alertFormLogic.ts+++ b/products/alerts/frontend/logic/alertFormLogic.ts@@ -250,12 +250,9 @@ function defaultAlertName(props: AlertFormLogicProps, goalLines?: GoalLine[] | nreturn goalLines && goalLines.length > 0 ? `Crossed ${goalLines[0].label}` : ''}-const getThresholdBounds = (- goalLines?: GoalLine[] | null,- uiVersion: AlertFormLogicProps['uiVersion'] = 'legacy'-): InsightsThresholdBounds => {+const getThresholdBounds = (goalLines?: GoalLine[] | null): InsightsThresholdBounds => {if (goalLines == null || goalLines.length == 0) {- return uiVersion === 'redesigned' ? { upper: 1 } : {}+ return {}}// Simple assumption that the alert should be triggered when the first/smallest goal line is crossed@@ -537,7 +534,7 @@ export const alertFormLogic = kea<alertFormLogicType>([threshold: {configuration: {type: InsightThresholdType.ABSOLUTE,- bounds: getThresholdBounds(values.goalLines, props.uiVersion),+ bounds: getThresholdBounds(values.goalLines),},},condition: {diff --git a/products/alerts/frontend/logic/thresholdPercent.test.ts b/products/alerts/frontend/logic/thresholdPercent.test.tsindex 336e7b44d1fa..0c641038f39a 100644--- a/products/alerts/frontend/logic/thresholdPercent.test.ts+++ b/products/alerts/frontend/logic/thresholdPercent.test.ts@@ -2,12 +2,22 @@ import { AlertConditionType, InsightThresholdType } from '~/queries/schema/schemimport {fractionToPercentInput,+ inputToStoredBound,rescaleThresholdBound,thresholdForConditionChange,thresholdForUnitChange,} from './thresholdPercent'describe('thresholdPercent', () => {+ it.each([+ [undefined, InsightThresholdType.ABSOLUTE, undefined],+ [NaN, InsightThresholdType.ABSOLUTE, undefined],+ [100, InsightThresholdType.ABSOLUTE, 100],+ [100, InsightThresholdType.PERCENTAGE, 1],+ ])('stores input %p with %s units as %p', (value, type, expected) => {+ expect(inputToStoredBound(value, type)).toBe(expected)+ })+// Stored 0–1 fractions render as percentage inputs without float noise — guards the ×100// round-trip surfacing values like 7.000000000000001 (regresses if the rounding is dropped).it.each([diff --git a/products/alerts/frontend/logic/thresholdPercent.ts b/products/alerts/frontend/logic/thresholdPercent.tsindex cc89600a7292..b2fdf53c2ee0 100644--- a/products/alerts/frontend/logic/thresholdPercent.ts+++ b/products/alerts/frontend/logic/thresholdPercent.ts@@ -11,7 +11,7 @@ export const fractionToPercentInput = (fraction: number | undefined): number | utypeof fraction === 'number' ? roundPercent(fraction * 100) : undefinedexport const inputToStoredBound = (value: number | undefined, type: InsightThresholdType): number | undefined => {- if (value === undefined) {+ if (value === undefined || Number.isNaN(value)) {return undefined}return type === InsightThresholdType.PERCENTAGE ? value / 100 : value