: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(flags): show one no-response bucket in flag evaluations usage (#109631)
Phil Haackc34b74b53098
diff --git a/frontend/src/scenes/feature-flags/featureFlagUsageQueries.test.ts b/frontend/src/scenes/feature-flags/featureFlagUsageQueries.test.tsindex a898bcf00104..fe03087d19c1 100644--- a/frontend/src/scenes/feature-flags/featureFlagUsageQueries.test.ts+++ b/frontend/src/scenes/feature-flags/featureFlagUsageQueries.test.ts@@ -1,4 +1,5 @@import { dateMapping } from 'lib/utils/dateFilters'+import { BREAKDOWN_NULL_DISPLAY } from 'scenes/insights/utils'import { Noun } from '~/models/groupsModel'import { DataVisualizationNode, DateRange, InsightVizNode, TrendsQuery } from '~/queries/schema/schema-general'@@ -179,6 +180,19 @@ describe('featureFlagUsageQueries', () => {expect(query.source.query).toContain("flag_key = 'o\\'brien-flag'")})+ it.each(flagEvaluationsBuilders)(+ '%s puts JSON-null and missing responses in one bucket with the events-mode label',+ (_name, build) => {+ // The raw column holds 'null' for one case and '' for the other, so grouping on it shows two+ // series with their own labels where the events mode shows one.+ const { query } = build(personFlagOptions)++ expect(query.source.query).toContain(+ `if(response IN ('', 'null'), '${BREAKDOWN_NULL_DISPLAY}', response) AS`+ )+ }+ )+it('buildFlagEvaluationsTotalVolumeChart breaks the line graph down by response over the date range interval', () => {const { query } = buildFlagEvaluationsTotalVolumeChart({...personFlagOptions,diff --git a/frontend/src/scenes/feature-flags/featureFlagUsageQueries.ts b/frontend/src/scenes/feature-flags/featureFlagUsageQueries.tsindex bb4e832d2cc1..d79d29b3f060 100644--- a/frontend/src/scenes/feature-flags/featureFlagUsageQueries.ts+++ b/frontend/src/scenes/feature-flags/featureFlagUsageQueries.ts@@ -7,6 +7,7 @@// rather than the template's fixed "day".import { dayjs } from 'lib/dayjs'import { dateMapping, dateStringToDayJs, getDefaultInterval } from 'lib/utils/dateFilters'+import { BREAKDOWN_NULL_DISPLAY } from 'scenes/insights/utils'import { Noun } from '~/models/groupsModel'import {@@ -185,6 +186,13 @@ function enrichedSeries(event: '$feature_view' | '$feature_interaction', seriesL// the flag-evaluations-hogql-table flag has no such table, and these queries fail to resolve for it.const FLAG_EVALUATIONS_TABLE = 'posthog.flag_evaluations'+// The table stores a JSON-null $feature_flag_response as 'null' and a missing one as ''. The events-mode+// breakdown puts both cases in one bucket labelled BREAKDOWN_NULL_DISPLAY, so these charts do the same.+// The label is in the query because the SQL line chart names a NULL series "[No value]" and the SQL+// table draws a NULL cell as a dash. A variant whose key equals the label merges into this bucket. The flag+// editor rejects that key, but the API accepts it.+const FLAG_EVALUATIONS_VARIANT = `if(response IN ('', 'null'), ${escapeHogQLString(BREAKDOWN_NULL_DISPLAY)}, response)`+/** How long a row stays in flag_evaluations. The events table keeps $feature_flag_called forever. */export const FLAG_EVALUATIONS_RETENTION_DAYS = 90@@ -294,7 +302,7 @@ export function buildFlagEvaluationsTotalVolumeChart(FROM (SELECTdateTrunc('${interval}', timestamp) AS period,- response AS variant,+ ${FLAG_EVALUATIONS_VARIANT} AS variant,count() AS totalFROM ${FLAG_EVALUATIONS_TABLE}WHERE ${flagEvaluationsConditions(options, ' ')}@@ -331,7 +339,7 @@ export function buildFlagEvaluationsUniqueCallersChart(query: buildFlagEvaluationsQuery(options,`SELECT- response AS \`Variant\`,+ ${FLAG_EVALUATIONS_VARIANT} AS \`Variant\`,uniq(${caller}) AS \`Unique callers\`FROM ${FLAG_EVALUATIONS_TABLE}WHERE ${flagEvaluationsConditions(options)}