: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(dashboards): scope filter controls per tile and add metric label filters (#113182)
Frank Hamand25c8e093f915
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex 5e5b415ec165..b39f460850df 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -433,6 +433,7 @@ export const FEATURE_FLAGS = {METRICS_DASHBOARD_PANELS: 'metrics-dashboard-panels', // owner: #team-apm — gates the stat/gauge/bargauge/table panel picker entriesMETRICS_ERROR_OVERLAYS: 'metrics-error-overlays', // owner: #team-apm — gates the error-spike overlay PoC on metrics chartsMETRICS_FUNDAMENTALS: 'metrics-fundamentals', // owner: #team-apm (@jonmcwest, @frankh), gates the Fundamentals tab and the explain API behind it, which check the metrics viewer's own reductions+ METRICS_DASHBOARD_CONTROLS: 'metrics-dashboard-controls', // owner: #team-apm — shows each dashboard filter only for the tiles it changes, and adds the metric label filterMETRICS_INSIGHT_BUILDER: 'metrics-insight-builder', // owner: #team-apm — offers Metrics in the new insight menu and the metrics builder in insight edit modeML_INFERENCE_DECISIONS: 'ml-inference-decisions', // owner: #team-ai-research, gates the decisions playground; the API checks the same flag server sideNEW_TAB_PROJECT_EXPLORER: 'new-tab-project-explorer', // owner: #team-platform-uxdiff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.tsindex 3f3ea1549d81..1adc594f42d4 100644--- a/frontend/src/lib/utils/eventUsageLogic.ts+++ b/frontend/src/lib/utils/eventUsageLogic.ts@@ -99,7 +99,14 @@ export enum DashboardEventSource {DashboardVariableOverride = 'dashboard_variable_override',}-export type DashboardFilterChangeType = 'date' | 'properties' | 'breakdown' | 'variable' | 'interval' | 'test_accounts'+export type DashboardFilterChangeType =+ | 'date'+ | 'properties'+ | 'breakdown'+ | 'variable'+ | 'interval'+ | 'test_accounts'+ | 'metric_labels'export enum InsightEventSource {LongPress = 'long_press',diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 437af55413ad..7c44d455928e 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -18669,6 +18669,20 @@],"description": "Time granularity forced onto every insight that supports one. Absent/null = inherit."},+ "metricFilters": {+ "anyOf": [+ {+ "items": {+ "$ref": "#/definitions/MetricsQueryFilter"+ },+ "type": "array"+ },+ {+ "type": "null"+ }+ ],+ "description": "Metric label matchers ANDed into every metrics tile. Other tiles ignore them."+ },"properties": {"anyOf": [{diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex ec2adef8778b..32801259e952 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -6781,6 +6781,8 @@ export interface DashboardFilter {interval?: IntervalType | null/** Tri-state test-account override. Null/absent = inherit; true = force on; false = force off. */filterTestAccounts?: boolean | null+ /** Metric label matchers ANDed into every metrics tile. Other tiles ignore them. */+ metricFilters?: MetricsQueryFilter[] | null}export interface TileFilters {diff --git a/frontend/src/scenes/dashboard/DashboardEditBar.tsx b/frontend/src/scenes/dashboard/DashboardEditBar.tsxindex 40602a2e8afd..18642ffdfab1 100644--- a/frontend/src/scenes/dashboard/DashboardEditBar.tsx+++ b/frontend/src/scenes/dashboard/DashboardEditBar.tsx@@ -1,16 +1,23 @@import clsx from 'clsx'import { BindLogic, useActions, useValues } from 'kea'+import type { ReactNode } from 'react'-import { IconCalendar } from '@posthog/icons'-import { LemonSelect } from '@posthog/lemon-ui'+import { IconCalendar, IconLive } from '@posthog/icons'+import { LemonSelect, Tooltip } from '@posthog/lemon-ui'import { DateFilter } from 'lib/components/DateFilter/DateFilter'import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'import { Shortcut } from 'lib/components/Shortcuts/Shortcut'import { keyBinds } from 'lib/components/Shortcuts/shortcuts'import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { DashboardEventSource } from 'lib/utils/eventUsageLogic'import { getProjectEventExistence } from 'lib/utils/getAppContext'+import {+ DashboardControl,+ dashboardControlScopeText,+ isDashboardControlHidden,+} from 'scenes/dashboard/dashboardControls'import { DashboardEditBarAdvancedFilters } from 'scenes/dashboard/DashboardEditBarAdvancedFilters'import { dashboardLogic } from 'scenes/dashboard/dashboardLogic'import { TaxonomicBreakdownFilter } from 'scenes/insights/filters/BreakdownFilter/TaxonomicBreakdownFilter'@@ -22,11 +29,43 @@ import { VariablesForDashboard } from '~/queries/nodes/DataVisualization/Componeimport { BreakdownFilter, NodeKind } from '~/queries/schema/schema-general'import { InsightLogicProps, IntervalType } from '~/types'+import { DashboardMetricLabelFilter } from 'products/metrics/frontend/components/DashboardMetricLabelFilter'+interface DashboardEditBarProps {showDateFilter?: booleanclassName?: string}+/** Wraps one filter control: hides it when it changes no insight, and says in a tooltip how many insights it changes. */+function DashboardControlSlot({+ control,+ hasValue,+ className,+ children,+}: {+ control: DashboardControl+ hasValue: boolean+ className?: string+ children: ReactNode+}): JSX.Element | null {+ const { dashboardControlScopes } = useValues(dashboardLogic)+ const controlsEnabled = useFeatureFlag('METRICS_DASHBOARD_CONTROLS')++ if (!controlsEnabled) {+ return <div className={className}>{children}</div>+ }+ const scope = dashboardControlScopes[control]+ if (isDashboardControlHidden(scope, hasValue)) {+ return null+ }+ const scopeText = dashboardControlScopeText(scope)+ return (+ <Tooltip title={scopeText} placement="top" delayMs={300}>+ <div className={className}>{children}</div>+ </Tooltip>+ )+}+export function DashboardIntervalFilter(): JSX.Element {const { dashboardEditing, effectiveEditBarFilters } = useValues(dashboardLogic)const { setInterval, setDashboardEditing } = useActions(dashboardLogic)@@ -58,7 +97,9 @@ export function DashboardIntervalFilter(): JSX.Element {export function DashboardEditBar({ showDateFilter = true, className }: DashboardEditBarProps): JSX.Element {const { dashboard, dashboardEditing, hasVariables, effectiveEditBarFilters } = useValues(dashboardLogic)- const { setDates, setProperties, setBreakdownFilter, setDashboardEditing } = useActions(dashboardLogic)+ const { setDates, setProperties, setBreakdownFilter, setMetricFilters, setDashboardEditing } =+ useActions(dashboardLogic)+ const controlsEnabled = useFeatureFlag('METRICS_DASHBOARD_CONTROLS')const { groupsTaxonomicTypes } = useValues(groupsModel)const { hasPageview, hasScreen } = getProjectEventExistence()@@ -89,7 +130,11 @@ export function DashboardEditBar({ showDateFilter = true, className }: Dashboard}>{showDateFilter && (- <div className={clsx('content-end min-w-0', { 'h-[61px]': hasVariables })}>+ <DashboardControlSlot+ control="dateRange"+ hasValue={!!effectiveEditBarFilters.date_from || !!effectiveEditBarFilters.date_to}+ className={clsx('content-end min-w-0', { 'h-[61px]': hasVariables })}+ ><Shortcutname="DashboardDateFilter"keybind={[keyBinds.dateFilter]}@@ -122,14 +167,22 @@ export function DashboardEditBar({ showDateFilter = true, className }: Dashboard)}/></Shortcut>- </div>+ </DashboardControlSlot>)}{showDateFilter && (- <div className={clsx('content-end', { 'h-[61px]': hasVariables })}>+ <DashboardControlSlot+ control="interval"+ hasValue={effectiveEditBarFilters.interval != null}+ className={clsx('content-end', { 'h-[61px]': hasVariables })}+ ><DashboardIntervalFilter />- </div>+ </DashboardControlSlot>)}- <div className={clsx('content-end', { 'h-[61px]': hasVariables })}>+ <DashboardControlSlot+ control="properties"+ hasValue={(effectiveEditBarFilters.properties?.length ?? 0) > 0}+ className={clsx('content-end', { 'h-[61px]': hasVariables })}+ ><PropertyFiltersonChange={(properties) => {if (!dashboardEditing?.filters) {@@ -155,8 +208,12 @@ export function DashboardEditBar({ showDateFilter = true, className }: DashboardTaxonomicFilterGroupType.DataWarehousePersonProperties,]}/>- </div>- <div className={clsx('content-end', { 'h-[61px]': hasVariables })}>+ </DashboardControlSlot>+ <DashboardControlSlot+ control="breakdown"+ hasValue={!!effectiveEditBarFilters.breakdown_filter}+ className={clsx('content-end', { 'h-[61px]': hasVariables })}+ ><BindLogic logic={insightLogic} props={insightProps}><TaxonomicBreakdownFilterinsightProps={insightProps}@@ -183,12 +240,38 @@ export function DashboardEditBar({ showDateFilter = true, className }: Dashboardsize="small"/></BindLogic>- </div>+ </DashboardControlSlot><VariablesForDashboard /><div className={clsx('content-end', { 'h-[61px]': hasVariables })}><DashboardEditBarAdvancedFilters /></div>+ {controlsEnabled && (+ <DashboardControlSlot+ control="metricLabels"+ hasValue={(effectiveEditBarFilters.metricFilters?.length ?? 0) > 0}+ className={clsx('content-end', { 'h-[61px]': hasVariables })}+ >+ <div className="flex min-h-[30px] flex-wrap items-center gap-1 border-l border-primary pl-2">+ <span className="flex items-center gap-1 text-xs font-semibold text-secondary">+ <IconLive className="text-sm" />+ Metrics+ </span>+ <DashboardMetricLabelFilter+ metricFilters={effectiveEditBarFilters.metricFilters}+ onChange={(metricFilters) => {+ if (!dashboardEditing?.filters) {+ setDashboardEditing(+ { filters: true, layout: false },+ DashboardEventSource.DashboardFilters+ )+ }+ setMetricFilters(metricFilters)+ }}+ />+ </div>+ </DashboardControlSlot>+ )}</div>)}diff --git a/frontend/src/scenes/dashboard/DashboardEditBarAdvancedFilters.tsx b/frontend/src/scenes/dashboard/DashboardEditBarAdvancedFilters.tsxindex bffa59ef8876..b68b7ebf5955 100644--- a/frontend/src/scenes/dashboard/DashboardEditBarAdvancedFilters.tsx+++ b/frontend/src/scenes/dashboard/DashboardEditBarAdvancedFilters.tsx@@ -7,6 +7,7 @@ import { LemonBadge, LemonButton, LemonDivider, LemonLabel, LemonSegmentedButtonimport { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { Popover } from 'lib/lemon-ui/Popover'import { DashboardEventSource } from 'lib/utils/eventUsageLogic'+import { dashboardControlScopeText } from 'scenes/dashboard/dashboardControls'import { dashboardInsightColorsModalLogic } from 'scenes/dashboard/dashboardInsightColorsModalLogic'import { dashboardLogic } from 'scenes/dashboard/dashboardLogic'import { teamLogic } from 'scenes/teamLogic'@@ -34,8 +35,18 @@ const CHOICE_HINTS: Record<TestAccountFilterChoice, string> = {* breakdown color override.*/export function DashboardEditBarAdvancedFilters(): JSX.Element {- const { dashboard, dashboardEditing, placement, canEditDashboard, effectiveEditBarFilters } =- useValues(dashboardLogic)+ const {+ dashboard,+ dashboardEditing,+ placement,+ canEditDashboard,+ effectiveEditBarFilters,+ dashboardControlScopes,+ } = useValues(dashboardLogic)+ const controlsEnabled = useFeatureFlag('METRICS_DASHBOARD_CONTROLS')+ const testAccountsScopeText = controlsEnabled+ ? dashboardControlScopeText(dashboardControlScopes.testAccounts)+ : nullconst { setFilterTestAccounts, setDashboardEditing } = useActions(dashboardLogic)const { showInsightColorsModal } = useActions(dashboardInsightColorsModalLogic)const { currentTeam } = useValues(teamLogic)@@ -117,6 +128,7 @@ export function DashboardEditBarAdvancedFilters(): JSX.Element {]}/><p className="mb-0 text-xs text-secondary">{CHOICE_HINTS[choice]}</p>+ {testAccountsScopeText && <p className="mb-0 text-xs text-secondary">{testAccountsScopeText}.</p>}{showColors && (<><LemonDivider className="my-0" />diff --git a/frontend/src/scenes/dashboard/dashboardControls.test.ts b/frontend/src/scenes/dashboard/dashboardControls.test.tsnew file mode 100644index 000000000000..6bdbca92517e--- /dev/null+++ b/frontend/src/scenes/dashboard/dashboardControls.test.ts@@ -0,0 +1,57 @@+import { NodeKind } from '~/queries/schema/schema-general'+import { DashboardTile } from '~/types'++import {+ dashboardControlScopeText,+ dashboardControlsForQuery,+ getDashboardControlScopes,+ isDashboardControlHidden,+} from './dashboardControls'++const insightTile = (query: Record<string, any>): DashboardTile => ({ insight: { query } }) as unknown as DashboardTile++const trendsTile = insightTile({ kind: NodeKind.InsightVizNode, source: { kind: NodeKind.TrendsQuery, series: [] } })+const retentionTile = insightTile({ kind: NodeKind.InsightVizNode, source: { kind: NodeKind.RetentionQuery } })+const metricsTile = insightTile({ kind: NodeKind.MetricsQuery, clauses: [] })++describe('dashboardControls', () => {+ it.each([+ ['a trends insight', trendsTile, ['dateRange', 'interval', 'properties', 'breakdown', 'testAccounts']],+ ['a retention insight', retentionTile, ['dateRange', 'properties', 'breakdown', 'testAccounts']],+ ['a metrics insight', metricsTile, ['dateRange', 'metricLabels']],+ [+ 'a SQL insight',+ insightTile({ kind: NodeKind.DataVisualizationNode, source: { kind: NodeKind.HogQLQuery, query: '' } }),+ ['dateRange', 'interval', 'properties', 'breakdown', 'testAccounts'],+ ],+ ])('lists the controls of %s', (_name, tile, expected) => {+ expect(dashboardControlsForQuery(tile.insight?.query)).toEqual(expected)+ })++ it('counts the insights that each control changes', () => {+ const scopes = getDashboardControlScopes([trendsTile, retentionTile, metricsTile])++ expect(scopes.dateRange).toEqual({ applies: 3, total: 3 })+ expect(scopes.interval).toEqual({ applies: 1, total: 3 })+ expect(scopes.properties).toEqual({ applies: 2, total: 3 })+ expect(scopes.metricLabels).toEqual({ applies: 1, total: 3 })+ })++ it.each([+ [{ applies: 4, total: 9 }, 'Applies to 4 of 9 insights'],+ [{ applies: 9, total: 9 }, null],+ [{ applies: 0, total: 9 }, null],+ [{ applies: 0, total: 0 }, null],+ ])('shows scope text for %o', (scope, expected) => {+ expect(dashboardControlScopeText(scope)).toEqual(expected)+ })++ it.each([+ ['changes no insight', { applies: 0, total: 3 }, false, true],+ ['changes no insight but has a value', { applies: 0, total: 3 }, true, false],+ ['changes some insights', { applies: 1, total: 3 }, false, false],+ ['is on a dashboard with no insights', { applies: 0, total: 0 }, false, false],+ ])('hides a control that %s', (_name, scope, hasValue, expected) => {+ expect(isDashboardControlHidden(scope, hasValue)).toEqual(expected)+ })+})diff --git a/frontend/src/scenes/dashboard/dashboardControls.ts b/frontend/src/scenes/dashboard/dashboardControls.tsnew file mode 100644index 000000000000..42ec545253a0--- /dev/null+++ b/frontend/src/scenes/dashboard/dashboardControls.ts@@ -0,0 +1,70 @@+import { Node, NodeKind } from '~/queries/schema/schema-general'+import { isNodeWithSource } from '~/queries/utils'+import { DashboardTile } from '~/types'++/** A filter control in the dashboard filter bar. */+export type DashboardControl = 'dateRange' | 'interval' | 'properties' | 'breakdown' | 'testAccounts' | 'metricLabels'++export interface DashboardControlScope {+ /** Insight tiles that the control changes. */+ applies: number+ /** All insight tiles on the dashboard. */+ total: number+}++const ALL_CONTROLS: DashboardControl[] = [+ 'dateRange',+ 'interval',+ 'properties',+ 'breakdown',+ 'testAccounts',+ 'metricLabels',+]++// Matches what each query runner's `apply_dashboard_filters` changes. A kind that is not listed keeps+// the controls every tile had before tiles declared their controls.+const DEFAULT_CONTROLS: DashboardControl[] = ['dateRange', 'interval', 'properties', 'breakdown', 'testAccounts']++const CONTROLS_BY_QUERY_KIND: Partial<Record<NodeKind, DashboardControl[]>> = {+ [NodeKind.RetentionQuery]: ['dateRange', 'properties', 'breakdown', 'testAccounts'],+ [NodeKind.PathsQuery]: ['dateRange', 'properties', 'testAccounts'],+ [NodeKind.PathsV2Query]: ['dateRange', 'properties', 'testAccounts'],+ [NodeKind.StickinessQuery]: ['dateRange', 'interval', 'properties', 'testAccounts'],+ [NodeKind.LifecycleQuery]: ['dateRange', 'interval', 'properties', 'testAccounts'],+ [NodeKind.CalendarHeatmapQuery]: ['dateRange', 'interval', 'properties', 'testAccounts'],+ [NodeKind.MetricsQuery]: ['dateRange', 'metricLabels'],+ [NodeKind.MetricsHistogramQuery]: ['dateRange', 'metricLabels'],+}++export function dashboardControlsForQuery(query: Node | null | undefined): DashboardControl[] {+ const source = isNodeWithSource(query) ? query.source : query+ return (source?.kind && CONTROLS_BY_QUERY_KIND[source.kind as NodeKind]) || DEFAULT_CONTROLS+}++export function getDashboardControlScopes(+ insightTiles: DashboardTile[]+): Record<DashboardControl, DashboardControlScope> {+ const queries = insightTiles.map((tile) => tile.insight?.query)+ const scopes = Object.fromEntries(+ ALL_CONTROLS.map((control) => [control, { applies: 0, total: queries.length }])+ ) as Record<DashboardControl, DashboardControlScope>+ for (const query of queries) {+ for (const control of dashboardControlsForQuery(query)) {+ scopes[control].applies+++ }+ }+ return scopes+}++/** Text for a control that changes only some of the insights. Null when it changes all or none of them. */+export function dashboardControlScopeText(scope: DashboardControlScope): string | null {+ if (scope.applies === 0 || scope.applies === scope.total) {+ return null+ }+ return `Applies to ${scope.applies} of ${scope.total} insights`+}++/** A control that changes no insight is hidden, unless it has a value that the user must be able to clear. */+export function isDashboardControlHidden(scope: DashboardControlScope, hasValue: boolean): boolean {+ return scope.total > 0 && scope.applies === 0 && !hasValue+}diff --git a/frontend/src/scenes/dashboard/dashboardFilterEmpty.ts b/frontend/src/scenes/dashboard/dashboardFilterEmpty.tsindex d250c0c9f16a..1a7da88b169f 100644--- a/frontend/src/scenes/dashboard/dashboardFilterEmpty.ts+++ b/frontend/src/scenes/dashboard/dashboardFilterEmpty.ts@@ -10,6 +10,7 @@ export function isDashboardFilterOverrideEmpty(filter: DashboardFilter | TileFilfilter.breakdown_filter === undefined &&filter.interval === undefined &&filter.filterTestAccounts === undefined &&+ (filter as DashboardFilter).metricFilters === undefined &&!(filter as TileFilters).ignoreDashboardFilters))}diff --git a/frontend/src/scenes/dashboard/dashboardLogic.test.ts b/frontend/src/scenes/dashboard/dashboardLogic.test.tsindex 445cbcdf9587..ad3594df38eb 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.test.ts+++ b/frontend/src/scenes/dashboard/dashboardLogic.test.ts@@ -1075,6 +1075,7 @@ describe('dashboardLogic', () => {await expectLogic(logic, () => {logic.actions.setInterval('week')logic.actions.setFilterTestAccounts(true)+ logic.actions.setMetricFilters([{ key: 'service.name', op: 'eq', value: 'checkout' }])}).toFinishAllListeners()expect(logic.values.dashboardSettingsDraft?.filters).toEqual(@@ -1084,6 +1085,7 @@ describe('dashboardLogic', () => {breakdown_filter: { breakdown: '$browser', breakdown_type: 'event' },interval: 'week',filterTestAccounts: true,+ metricFilters: [{ key: 'service.name', op: 'eq', value: 'checkout' }],}))expect(logic.values.urlFilters).toEqual(@@ -1093,6 +1095,7 @@ describe('dashboardLogic', () => {breakdown_filter: { breakdown: '$browser', breakdown_type: 'event' },interval: 'week',filterTestAccounts: true,+ metricFilters: [{ key: 'service.name', op: 'eq', value: 'checkout' }],}))diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsxindex 5990a1e18be3..d31a2cb604df 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx@@ -87,6 +87,7 @@ import {DashboardFilter,DataVisualizationNode,HogQLVariable,+ MetricsQueryFilter,NodeKind,RefreshType,} from '~/queries/schema/schema-general'@@ -141,6 +142,7 @@ import {mergeBreakdownColorConfigs,} from './dashboardBreakdownColors'import { AUTO_REFRESH_INITIAL_INTERVAL_SECONDS } from './dashboardConstants'+import { DashboardControl, DashboardControlScope, getDashboardControlScopes } from './dashboardControls'import {BREAKPOINT_COLUMN_COUNTS,DASHBOARD_MIN_REFRESH_INTERVAL_MINUTES,@@ -334,6 +336,7 @@ export interface dashboardLogicValues {currentDashboardVariables: Record<string, HogQLVariable>currentLayoutSize: 'sm' | 'xs'dashboard: DashboardType | null+ dashboardControlScopes: Record<DashboardControl, DashboardControlScope>dashboardCustomizeMenuOpen: booleandashboardEditing: DashboardEditing | nulldashboardFailedToLoad: boolean@@ -934,6 +937,9 @@ export interface dashboardLogicActions {setLoadLayoutFromServerOnPreview: (loadLayoutFromServerOnPreview: boolean) => {loadLayoutFromServerOnPreview: boolean}+ setMetricFilters: (metricFilters: MetricsQueryFilter[] | null) => {+ metricFilters: MetricsQueryFilter[] | null+ }setPageVisibility: (visible: boolean) => {visible: boolean}@@ -1243,6 +1249,7 @@ export interface dashboardLogicMeta {) => booleaninsightTiles: (tiles: DashboardTile[]) => DashboardTile[]textTiles: (tiles: DashboardTile[]) => DashboardTile[]+ dashboardControlScopes: (insightTiles: DashboardTile[]) => Record<DashboardControl, DashboardControlScope>itemsLoading: (dashboardLoading: boolean,dashboardStreaming: boolean,@@ -1492,6 +1499,7 @@ export const dashboardLogic = kea<dashboardLogicType>([setBreakdownFilter: (breakdown_filter: BreakdownFilter | null) => ({ breakdown_filter }),setInterval: (interval: IntervalType | null) => ({ interval }),setFilterTestAccounts: (filterTestAccounts: boolean | null) => ({ filterTestAccounts }),+ setMetricFilters: (metricFilters: MetricsQueryFilter[] | null) => ({ metricFilters }),setExternalFilters: (filters: DashboardFilter) => ({ filters }),setDashboardSettingsDraft: (settings: DashboardSettings | null) => ({ settings }),setPreviewedDashboardSettings: (settings: DashboardSettings | null) => ({ settings }),@@ -2053,6 +2061,7 @@ export const dashboardLogic = kea<dashboardLogicType>([setBreakdownFilter: () => false,setInterval: () => false,setFilterTestAccounts: () => false,+ setMetricFilters: () => false,overrideVariableValue: () => false,loadDashboardSuccess: () => false,loadDashboardFailure: () => false,@@ -3111,6 +3120,11 @@ export const dashboardLogic = kea<dashboardLogicType>([(tiles: DashboardTile[]) => tiles.filter((t) => !!t.insight).filter((i) => !i.insight?.deleted),],textTiles: [(s) => [s.tiles], (tiles: DashboardTile[]) => tiles.filter((t) => !!t.text)],+ dashboardControlScopes: [+ (s) => [s.insightTiles],+ (insightTiles: DashboardTile[]): Record<DashboardControl, DashboardControlScope> =>+ getDashboardControlScopes(insightTiles),+ ],itemsLoading: [(s) => [s.dashboardLoading, s.dashboardStreaming, s.refreshStatus, s.initialVariablesLoaded],(@@ -4949,6 +4963,23 @@ export const dashboardLogic = kea<dashboardLogicType>([})}},+ setMetricFilters: ({ metricFilters }) => {+ actions.setDashboardSettingsDraft({+ ...values.currentDashboardSettings,+ filters: { ...values.currentDashboardSettings.filters, metricFilters },+ })+ eventUsageLogic.actions.reportDashboardFiltersChanged(values.dashboard, 'metric_labels', {+ metric_filter_count: metricFilters?.length ?? 0,+ })++ if (values.canAutoPreview) {+ actions.refreshDashboardItems({+ action: RefreshDashboardItemsAction.Preview,+ forceRefresh: false,+ previewUnsavedFilters: true,+ })+ }+ },setExternalFilters: () => {if (values.tiles.length > 0) {actions.refreshDashboardItems({@@ -5212,6 +5243,25 @@ export const dashboardLogic = kea<dashboardLogicType>([currentLocation.hashParams,]},+ setMetricFilters: ({ metricFilters }) => {+ const { currentLocation } = router.values++ const urlFilters = parseURLFilters(currentLocation.searchParams)+ const newUrlFilters: DashboardFilter = {+ ...urlFilters,+ metricFilters,+ }++ return [+ currentLocation.pathname,+ searchParamsWithUrlFilters(+ currentLocation.searchParams,+ newUrlFilters,+ combineDashboardFilters(values.dashboard?.persisted_filters || {}, values.externalFilters)+ ),+ currentLocation.hashParams,+ ]+ },overrideVariableValue: ({ variableId, value, isNull }) => {const { currentLocation } = router.valuesdiff --git a/posthog/schema.py b/posthog/schema.pyindex 56b0890bbe18..3fda240c40a3 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -27276,6 +27276,10 @@ class DashboardFilter(BaseModel):default=None,description=("Time granularity forced onto every insight that supports one. Absent/null = inherit."),)+ metricFilters: list[MetricsQueryFilter] | None = Field(+ default=None,+ description=("Metric label matchers ANDed into every metrics tile. Other tiles ignore them."),+ )properties: list[AnyPropertyFilterDiscriminated] | None = Nonediff --git a/products/customer_analytics/frontend/generated/api.schemas.ts b/products/customer_analytics/frontend/generated/api.schemas.tsindex eb0ea60dac4e..e479ada3f571 100644--- a/products/customer_analytics/frontend/generated/api.schemas.ts+++ b/products/customer_analytics/frontend/generated/api.schemas.ts@@ -2164,6 +2164,30 @@ export const IntervalTypeApi = {Year: 'year',} as const+export type MetricsFilterOpApi = (typeof MetricsFilterOpApi)[keyof typeof MetricsFilterOpApi]++export const MetricsFilterOpApi = {+ Eq: 'eq',+ Neq: 'neq',+ Regex: 'regex',+ NotRegex: 'not_regex',+} as const++export type MetricsAttributeScopeApi = (typeof MetricsAttributeScopeApi)[keyof typeof MetricsAttributeScopeApi]++export const MetricsAttributeScopeApi = {+ Resource: 'resource',+ Attribute: 'attribute',+ Auto: 'auto',+} as const++export interface MetricsQueryFilterApi {+ key: string+ op: MetricsFilterOpApi+ scope?: MetricsAttributeScopeApi | null+ value: string+}+export type PropertyOperatorApi = (typeof PropertyOperatorApi)[keyof typeof PropertyOperatorApi]export const PropertyOperatorApi = {@@ -2498,6 +2522,8 @@ export interface DashboardFilterApi {filterTestAccounts?: boolean | null/** Time granularity forced onto every insight that supports one. Absent/null = inherit. */interval?: IntervalTypeApi | null+ /** Metric label matchers ANDed into every metrics tile. Other tiles ignore them. */+ metricFilters?: MetricsQueryFilterApi[] | nullproperties?:| (| EventPropertyFilterApidiff --git a/products/dashboards/frontend/dashboardSettings/dashboardChanges.ts b/products/dashboards/frontend/dashboardSettings/dashboardChanges.tsindex 962451109aa2..c80f31ef602f 100644--- a/products/dashboards/frontend/dashboardSettings/dashboardChanges.ts+++ b/products/dashboards/frontend/dashboardSettings/dashboardChanges.ts@@ -310,5 +310,29 @@ export function getDashboardFilterChanges(})}+ if (!dashboardFilterValuesEqual(previousFilters.metricFilters, currentFilters.metricFilters)) {+ const previousLabels = formatMetricFilters(previousFilters)+ const currentLabels = formatMetricFilters(currentFilters)+ changes.push({+ label: 'Metric labels',+ previousValue: previousLabels,+ value: currentLabels,+ status: getChangeStatus(previousLabels.length > 0, currentLabels.length > 0),+ })+ }+return changes}++const METRIC_FILTER_OP_LABELS: Record<NonNullable<DashboardFilter['metricFilters']>[number]['op'], string> = {+ eq: '=',+ neq: '!=',+ regex: '=~',+ not_regex: '!~',+}++function formatMetricFilters(filters: DashboardFilter): string[] {+ return (filters.metricFilters ?? []).map(+ (filter) => `${filter.key} ${METRIC_FILTER_OP_LABELS[filter.op]} ${filter.value}`+ )+}diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.tsindex 3824f26180e3..c809f704d4a7 100644--- a/products/dashboards/frontend/generated/api.schemas.ts+++ b/products/dashboards/frontend/generated/api.schemas.ts@@ -9593,6 +9593,30 @@ export interface DashboardTileBasicApi {*/export type _InsightResultWarningsApi = (DataWarehouseSyncWarningApi | AccessControlFilterWarningApi)[]+export type MetricsFilterOpApi = (typeof MetricsFilterOpApi)[keyof typeof MetricsFilterOpApi]++export const MetricsFilterOpApi = {+ Eq: 'eq',+ Neq: 'neq',+ Regex: 'regex',+ NotRegex: 'not_regex',+} as const++export type MetricsAttributeScopeApi = (typeof MetricsAttributeScopeApi)[keyof typeof MetricsAttributeScopeApi]++export const MetricsAttributeScopeApi = {+ Resource: 'resource',+ Attribute: 'attribute',+ Auto: 'auto',+} as const++export interface MetricsQueryFilterApi {+ key: string+ op: MetricsFilterOpApi+ scope?: MetricsAttributeScopeApi | null+ value: string+}+export interface DashboardFilterApi {breakdown_filter?: BreakdownFilterApi | nulldate_from?: string | null@@ -9602,6 +9626,8 @@ export interface DashboardFilterApi {filterTestAccounts?: boolean | null/** Time granularity forced onto every insight that supports one. Absent/null = inherit. */interval?: IntervalTypeApi | null+ /** Metric label matchers ANDed into every metrics tile. Other tiles ignore them. */+ metricFilters?: MetricsQueryFilterApi[] | nullproperties?:| (| EventPropertyFilterApidiff --git a/products/endpoints/frontend/generated/api.schemas.ts b/products/endpoints/frontend/generated/api.schemas.tsindex e3e3b09f9507..9ac5a5507f38 100644--- a/products/endpoints/frontend/generated/api.schemas.ts+++ b/products/endpoints/frontend/generated/api.schemas.ts@@ -645,6 +645,30 @@ export const IntervalTypeApi = {Year: 'year',} as const+export type MetricsFilterOpApi = (typeof MetricsFilterOpApi)[keyof typeof MetricsFilterOpApi]++export const MetricsFilterOpApi = {+ Eq: 'eq',+ Neq: 'neq',+ Regex: 'regex',+ NotRegex: 'not_regex',+} as const++export type MetricsAttributeScopeApi = (typeof MetricsAttributeScopeApi)[keyof typeof MetricsAttributeScopeApi]++export const MetricsAttributeScopeApi = {+ Resource: 'resource',+ Attribute: 'attribute',+ Auto: 'auto',+} as const++export interface MetricsQueryFilterApi {+ key: string+ op: MetricsFilterOpApi+ scope?: MetricsAttributeScopeApi | null+ value: string+}+export type PropertyOperatorApi = (typeof PropertyOperatorApi)[keyof typeof PropertyOperatorApi]export const PropertyOperatorApi = {@@ -979,6 +1003,8 @@ export interface DashboardFilterApi {filterTestAccounts?: boolean | null/** Time granularity forced onto every insight that supports one. Absent/null = inherit. */interval?: IntervalTypeApi | null+ /** Metric label matchers ANDed into every metrics tile. Other tiles ignore them. */+ metricFilters?: MetricsQueryFilterApi[] | nullproperties?:| (| EventPropertyFilterApidiff --git a/products/metrics/backend/hogql_queries/metrics_histogram_query_runner.py b/products/metrics/backend/hogql_queries/metrics_histogram_query_runner.pyindex f181a3ead4ac..bfeb35e65ce7 100644--- a/products/metrics/backend/hogql_queries/metrics_histogram_query_runner.py+++ b/products/metrics/backend/hogql_queries/metrics_histogram_query_runner.py@@ -220,3 +220,5 @@ class MetricsHistogramQueryRunner(AnalyticsQueryRunner[MetricsHistogramQueryRespdate_from=dashboard_filter.date_from,date_to=dashboard_filter.date_to,)+ if dashboard_filter.metricFilters:+ self.query.filters = [*(self.query.filters or []), *dashboard_filter.metricFilters]diff --git a/products/metrics/backend/hogql_queries/metrics_query_runner.py b/products/metrics/backend/hogql_queries/metrics_query_runner.pyindex 590d05475125..af9321158afe 100644--- a/products/metrics/backend/hogql_queries/metrics_query_runner.py+++ b/products/metrics/backend/hogql_queries/metrics_query_runner.py@@ -165,10 +165,15 @@ class MetricsQueryRunner(AnalyticsQueryRunner[MetricsQueryResponse]):)def apply_dashboard_filters(self, dashboard_filter: DashboardFilter) -> None:- # Metric label predicates are not PostHog property filters, so only the- # dashboard's date range applies to this tile.+ # Metric label predicates are not PostHog property filters, so the dashboard's+ # property filters do not apply. Its date range and label filters do.if dashboard_filter.date_from or dashboard_filter.date_to:self.query.dateRange = DateRange(date_from=dashboard_filter.date_from,date_to=dashboard_filter.date_to,)+ if dashboard_filter.metricFilters:+ self.query.clauses = [+ clause.model_copy(update={"filters": [*(clause.filters or []), *dashboard_filter.metricFilters]})+ for clause in self.query.clauses+ ]diff --git a/products/metrics/backend/tests/test_metrics_histogram_query_runner.py b/products/metrics/backend/tests/test_metrics_histogram_query_runner.pyindex cbc7308f4e6f..2170a7808ff1 100644--- a/products/metrics/backend/tests/test_metrics_histogram_query_runner.py+++ b/products/metrics/backend/tests/test_metrics_histogram_query_runner.py@@ -7,7 +7,7 @@ from django.utils import timezonefrom parameterized import parameterized-from posthog.schema import MetricsHistogramQuery+from posthog.schema import DashboardFilter, MetricsHistogramQuery, MetricsQueryFilterfrom posthog.hogql.errors import ExposedHogQLError@@ -57,6 +57,17 @@ class TestMetricsHistogramQueryRunner(ClickhouseTestMixin, APIBaseTest):)return MetricsHistogramQueryRunner(query=query, team=self.team).calculate()+ def test_dashboard_metric_filters_add_to_the_query_filters(self):+ own_filter = MetricsQueryFilter(key="namespace", op="eq", value="posthog")+ dashboard_filter = MetricsQueryFilter(key="service.name", op="eq", value="checkout")+ runner = MetricsHistogramQueryRunner(+ query=MetricsHistogramQuery(metricName="latency", filters=[own_filter]), team=self.team+ )++ runner.apply_dashboard_filters(DashboardFilter(metricFilters=[dashboard_filter]))++ self.assertEqual(runner.query.filters, [own_filter, dashboard_filter])+def test_returns_a_time_by_bound_grid(self):self._seed_histogram([diff --git a/products/metrics/backend/tests/test_metrics_query_runner.py b/products/metrics/backend/tests/test_metrics_query_runner.pyindex 4a00970aaad2..572330cf6f2d 100644--- a/products/metrics/backend/tests/test_metrics_query_runner.py+++ b/products/metrics/backend/tests/test_metrics_query_runner.py@@ -11,6 +11,7 @@ from parameterized import parameterizedfrom posthog.schema import (DashboardFilter,DateRange,+ EventPropertyFilter,GoalLine,MetricsDisplaySettings,MetricsQuery,@@ -241,6 +242,32 @@ class TestMetricsQueryRunner(ClickhouseTestMixin, APIBaseTest):assert runner.query.dateRange.date_from == "-7d"assert runner.query.dateRange.date_to == "-1d"+ def test_dashboard_metric_filters_apply_to_every_clause(self) -> None:+ own_filter = MetricsQueryFilter(key="namespace", op="eq", value="posthog")+ query = MetricsQuery(+ clauses=[+ MetricsQueryClause(name="a", metricName="queue_depth", aggregation="sum", filters=[own_filter]),+ MetricsQueryClause(name="b", metricName="requests_total", aggregation="rate"),+ ],+ )+ runner = self._runner(query)+ dashboard_filter = MetricsQueryFilter(key="service.name", op="eq", value="checkout")++ runner.apply_dashboard_filters(DashboardFilter(metricFilters=[dashboard_filter]))++ assert runner.query.clauses[0].filters == [own_filter, dashboard_filter]+ assert runner.query.clauses[1].filters == [dashboard_filter]++ def test_dashboard_property_filters_do_not_apply(self) -> None:+ query = MetricsQuery(clauses=[MetricsQueryClause(name="a", metricName="queue_depth", aggregation="sum")])+ runner = self._runner(query)++ runner.apply_dashboard_filters(+ DashboardFilter(properties=[EventPropertyFilter(key="$browser", operator="exact", value="Chrome")])+ )++ assert runner.query.clauses[0].filters is None+def _cache_key_for(self, **kwargs) -> str:return self._runner(MetricsQuery(clauses=[MetricsQueryClause(name="a", metricName="queue_depth", aggregation="sum")], **kwargs)diff --git a/products/metrics/frontend/components/DashboardMetricLabelFilter.tsx b/products/metrics/frontend/components/DashboardMetricLabelFilter.tsxnew file mode 100644index 000000000000..a0f57c300f6d--- /dev/null+++ b/products/metrics/frontend/components/DashboardMetricLabelFilter.tsx@@ -0,0 +1,56 @@+import { useEffect, useState } from 'react'++import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'+import UniversalFilters from 'lib/components/UniversalFilters/UniversalFilters'+import { objectsEqual } from 'lib/utils/objects'++import type { MetricsQueryFilter } from '~/queries/schema/schema-general'+import { FilterLogicalOperator, UniversalFiltersGroup } from '~/types'++import { MetricsClauseFilterBar } from './MetricsClauseFilterBar'+import { filterGroupFromMetricFilters, metricFiltersForGroup } from './metricsViewerLogic'++const toMetricFilters = (group: UniversalFiltersGroup): MetricsQueryFilter[] =>+ metricFiltersForGroup(group) as MetricsQueryFilter[]++/** Dashboard-level metric label matchers, such as `service.name = checkout`, that every metrics tile applies. */+export function DashboardMetricLabelFilter({+ metricFilters,+ onChange,+ disabledReason = null,+}: {+ metricFilters: MetricsQueryFilter[] | null | undefined+ onChange: (metricFilters: MetricsQueryFilter[] | null) => void+ disabledReason?: string | null+}): JSX.Element {+ // A chip that is still being edited has no matcher yet, so the chips are kept here+ // and only complete matchers go to the dashboard filters.+ const [filterGroup, setFilterGroup] = useState(() => filterGroupFromMetricFilters(metricFilters ?? []))++ useEffect(() => {+ if (!objectsEqual(toMetricFilters(filterGroup), metricFilters ?? [])) {+ setFilterGroup(filterGroupFromMetricFilters(metricFilters ?? []))+ }+ }, [metricFilters]) // eslint-disable-line react-hooks/exhaustive-deps++ return (+ <UniversalFilters+ rootKey="dashboard-metric-label-filters"+ group={filterGroup.values[0] as UniversalFiltersGroup}+ taxonomicGroupTypes={[TaxonomicFilterGroupType.MetricAttributes]}+ onChange={(group) => {+ if (disabledReason) {+ return+ }+ const nextGroup: UniversalFiltersGroup = { type: FilterLogicalOperator.And, values: [group] }+ setFilterGroup(nextGroup)+ const nextFilters = toMetricFilters(nextGroup)+ if (!objectsEqual(nextFilters, metricFilters ?? [])) {+ onChange(nextFilters.length ? nextFilters : null)+ }+ }}+ >+ <MetricsClauseFilterBar disabledReason={disabledReason} addFilterTitle="Label" addFilterType="tertiary" />+ </UniversalFilters>+ )+}diff --git a/products/metrics/frontend/components/MetricsClauseFilterBar.tsx b/products/metrics/frontend/components/MetricsClauseFilterBar.tsxindex e557d1598edc..8c00a9e18759 100644--- a/products/metrics/frontend/components/MetricsClauseFilterBar.tsx+++ b/products/metrics/frontend/components/MetricsClauseFilterBar.tsx@@ -14,7 +14,15 @@ import { METRIC_FILTER_OPERATOR_ALLOWLIST } from './metricsViewerLogic'* applied-filters row: picking an attribute opens the chip for value selection, with* suggestions fed by the metrics attribute endpoints. Must render inside the row's* `UniversalFilters` provider. */-export function MetricsClauseFilterBar({ disabledReason }: { disabledReason: string | null }): JSX.Element {+export function MetricsClauseFilterBar({+ disabledReason,+ addFilterTitle = 'Filter',+ addFilterType = 'secondary',+}: {+ disabledReason: string | null+ addFilterTitle?: string+ addFilterType?: 'secondary' | 'tertiary'+}): JSX.Element {const { filterGroup } = useValues(universalFiltersLogic)const { replaceGroupValue, removeGroupValue } = useActions(universalFiltersLogic)const [allowInitiallyOpen, setAllowInitiallyOpen] = useState<boolean>(false)@@ -48,8 +56,8 @@ export function MetricsClauseFilterBar({ disabledReason }: { disabledReason: str)}<UniversalFilters.AddFilterButtonsize="small"- type="secondary"- title="Filter"+ type={addFilterType}+ title={addFilterTitle}disabledReason={disabledReason}/></div>diff --git a/products/metrics/frontend/components/metricsViewerLogic.tsx b/products/metrics/frontend/components/metricsViewerLogic.tsxindex 8e5a4c301552..fca5fca8755a 100644--- a/products/metrics/frontend/components/metricsViewerLogic.tsx+++ b/products/metrics/frontend/components/metricsViewerLogic.tsx@@ -339,6 +339,16 @@ const FILTER_OP_TO_OPERATOR: Record<MetricsQueryFilter['op'], PropertyOperator>not_regex: PropertyOperator.NotRegex,}+/** Saved label matchers as filter bar chips. A multi-value chip comes back as one regex chip. */+export const filterGroupFromMetricFilters = (filters: MetricsQueryFilter[]): UniversalFiltersGroup =>+ metricsFilterGroup(+ filters.map((filter) => ({+ key: filter.key,+ value: [filter.value],+ operator: FILTER_OP_TO_OPERATOR[filter.op],+ }))+ )+const isAutoScope = (scope: MetricsAttributeScope | undefined): boolean => !scope || scope === 'auto'/** Whether the builder can show every part of a saved node, so an edit does not drop settings it cannot show. */@@ -360,13 +370,7 @@ const viewerClauseFromNode = (clause: MetricsQueryClause): MetricsViewerClause =aggregation: isMetricAggregation(aggregation) ? aggregation : DEFAULT_AGGREGATION,// A saved aggregation is a choice, so the type backfill must not replace it.aggregationExplicitlySet: true,- filterGroup: metricsFilterGroup(- (clause.filters ?? []).map((filter) => ({- key: filter.key,- value: [filter.value],- operator: FILTER_OP_TO_OPERATOR[filter.op],- }))- ),+ filterGroup: filterGroupFromMetricFilters(clause.filters ?? []),groupByKeys: (clause.groupBy ?? []).map((groupBy) => groupBy.key),}}diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.tsindex cfe569572bcb..7e6c64ca7429 100644--- a/products/product_analytics/frontend/generated/api.schemas.ts+++ b/products/product_analytics/frontend/generated/api.schemas.ts@@ -8599,6 +8599,30 @@ export const PrivilegeLevelEnumApi = {*/export type _InsightResultWarningsApi = (DataWarehouseSyncWarningApi | AccessControlFilterWarningApi)[]+export type MetricsFilterOpApi = (typeof MetricsFilterOpApi)[keyof typeof MetricsFilterOpApi]++export const MetricsFilterOpApi = {+ Eq: 'eq',+ Neq: 'neq',+ Regex: 'regex',+ NotRegex: 'not_regex',+} as const++export type MetricsAttributeScopeApi = (typeof MetricsAttributeScopeApi)[keyof typeof MetricsAttributeScopeApi]++export const MetricsAttributeScopeApi = {+ Resource: 'resource',+ Attribute: 'attribute',+ Auto: 'auto',+} as const++export interface MetricsQueryFilterApi {+ key: string+ op: MetricsFilterOpApi+ scope?: MetricsAttributeScopeApi | null+ value: string+}+export interface DashboardFilterApi {breakdown_filter?: BreakdownFilterApi | nulldate_from?: string | null@@ -8608,6 +8632,8 @@ export interface DashboardFilterApi {filterTestAccounts?: boolean | null/** Time granularity forced onto every insight that supports one. Absent/null = inherit. */interval?: IntervalTypeApi | null+ /** Metric label matchers ANDed into every metrics tile. Other tiles ignore them. */+ metricFilters?: MetricsQueryFilterApi[] | nullproperties?:| (| EventPropertyFilterApidiff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 8a53e4d4e41f..7ce717e45a59 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -3227,6 +3227,32 @@ export namespace Schemas {Year: 'year',} as const;+ export type MetricsFilterOp = typeof MetricsFilterOp[keyof typeof MetricsFilterOp];+++ export const MetricsFilterOp = {+ Eq: 'eq',+ Neq: 'neq',+ Regex: 'regex',+ NotRegex: 'not_regex',+ } as const;++ export type MetricsAttributeScope = typeof MetricsAttributeScope[keyof typeof MetricsAttributeScope];+++ export const MetricsAttributeScope = {+ Resource: 'resource',+ Attribute: 'attribute',+ Auto: 'auto',+ } as const;++ export interface MetricsQueryFilter {+ key: string;+ op: MetricsFilterOp;+ scope?: MetricsAttributeScope | null;+ value: string;+ }+export interface EventPropertyFilter {key: string;label?: string | null;@@ -3508,6 +3534,8 @@ export namespace Schemas {filterTestAccounts?: boolean | null;/** Time granularity forced onto every insight that supports one. Absent/null = inherit. */interval?: IntervalType | null;+ /** Metric label matchers ANDed into every metrics tile. Other tiles ignore them. */+ metricFilters?: MetricsQueryFilter[] | null;properties?: (EventPropertyFilter | PersonPropertyFilter | PersonMetadataPropertyFilter | ElementPropertyFilter | EventMetadataPropertyFilter | SessionPropertyFilter | CohortPropertyFilter | RecordingPropertyFilter | LogEntryPropertyFilter | GroupPropertyFilter | FeaturePropertyFilter | FlagPropertyFilter | HogQLPropertyFilter | EmptyPropertyFilter | DataWarehousePropertyFilter | DataWarehousePersonPropertyFilter | ErrorTrackingIssueFilter | LogPropertyFilter | MetricPropertyFilter | SpanPropertyFilter | RevenueAnalyticsPropertyFilter | AccountCustomPropertyFilter | WorkflowVariablePropertyFilter | BehavioralPropertyFilter)[] | null;}@@ -55457,32 +55485,6 @@ export namespace Schemas {HistogramQuantile: 'histogram_quantile',} as const;- export type MetricsFilterOp = typeof MetricsFilterOp[keyof typeof MetricsFilterOp];--- export const MetricsFilterOp = {- Eq: 'eq',- Neq: 'neq',- Regex: 'regex',- NotRegex: 'not_regex',- } as const;-- export type MetricsAttributeScope = typeof MetricsAttributeScope[keyof typeof MetricsAttributeScope];--- export const MetricsAttributeScope = {- Resource: 'resource',- Attribute: 'attribute',- Auto: 'auto',- } as const;-- export interface MetricsQueryFilter {- key: string;- op: MetricsFilterOp;- scope?: MetricsAttributeScope | null;- value: string;- }-export interface MetricsQueryGroupBy {key: string;scope?: MetricsAttributeScope | null;diff --git a/services/mcp/src/generated/endpoints/api.ts b/services/mcp/src/generated/endpoints/api.tsindex 3b8d34035aca..d1a35f03b7d8 100644--- a/services/mcp/src/generated/endpoints/api.ts+++ b/services/mcp/src/generated/endpoints/api.ts@@ -442,6 +442,20 @@ export const EndpointsRunCreateBody = () => zod.object({]).optional().describe('Time granularity forced onto every insight that supports one. Absent\/null = inherit.'),+ metricFilters: zod+ .union([+ zod.array(+ zod.object({+ key: zod.string(),+ op: zod.enum(['eq', 'neq', 'regex', 'not_regex']),+ scope: zod.union([zod.enum(['resource', 'attribute', 'auto']), zod.null()]).optional(),+ value: zod.string(),+ })+ ),+ zod.null(),+ ])+ .optional()+ .describe('Metric label matchers ANDed into every metrics tile. Other tiles ignore them.'),properties: zod.union([zod.array(