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(experiments): Move cache health panel to its own tab (#68455)

Juraj Majerik6577fc44f726
diff --git a/frontend/src/scenes/instance/QueryPerformance/CacheHealth.tsx b/frontend/src/scenes/instance/QueryPerformance/CacheHealth.tsx
index 33e0cdf1a207..dbdae970614e 100644
--- a/frontend/src/scenes/instance/QueryPerformance/CacheHealth.tsx
+++ b/frontend/src/scenes/instance/QueryPerformance/CacheHealth.tsx
@@ -112,8 +112,11 @@ export function CacheHealth(): JSX.Element {
return (
<>
- <div className="flex items-center gap-2">
- <h2 className="mb-0">Cache health</h2>
+ <div className="flex items-center justify-between gap-2 mb-2">
+ <p className="text-muted text-sm mb-0">
+ Physical footprint of the experiment preaggregation tables (active parts across all shards, from
+ ClickHouse system.parts).
+ </p>
<LemonButton
type="secondary"
size="small"
@@ -123,10 +126,6 @@ export function CacheHealth(): JSX.Element {
Refresh
</LemonButton>
</div>
- <p className="text-muted text-sm mt-1 mb-2">
- Physical footprint of the experiment preaggregation tables — active parts across all shards, from
- ClickHouse system.parts.
- </p>
<div className="flex flex-wrap gap-4 mb-4">
{!cacheHealth && cacheHealthLoading
? [0, 1].map((i) => (
diff --git a/frontend/src/scenes/instance/QueryPerformance/QueryPerformance.tsx b/frontend/src/scenes/instance/QueryPerformance/QueryPerformance.tsx
index 80827f45d25a..2c053b817c41 100644
--- a/frontend/src/scenes/instance/QueryPerformance/QueryPerformance.tsx
+++ b/frontend/src/scenes/instance/QueryPerformance/QueryPerformance.tsx
@@ -152,6 +152,7 @@ export function QueryPerformance(): JSX.Element {
experimentIdFilter,
metricTypeFilter,
exceptionCodeFilter,
+ experimentsTab,
} = useValues(queryPerformanceLogic)
const {
setSearch,
@@ -162,6 +163,7 @@ export function QueryPerformance(): JSX.Element {
setExperimentIdFilter,
setMetricTypeFilter,
setExceptionCodeFilter,
+ setExperimentsTab,
} = useActions(queryPerformanceLogic)
if (!user?.is_staff) {
@@ -497,155 +499,194 @@ export function QueryPerformance(): JSX.Element {
key: 'experiments',
label: 'Experiments',
content: (
- <>
- <CacheHealth />
- <h2>Slowest queries</h2>
- <div className="flex flex-wrap gap-2 mb-4 items-center">
- {TIME_RANGE_OPTIONS.map(({ label, hours }) => (
- <LemonButton
- key={hours}
- type={hoursBack === hours ? 'primary' : 'tertiary'}
- size="small"
- onClick={() => setHoursBack(hours)}
- >
- {label}
- </LemonButton>
- ))}
- <LemonInput
- type="number"
- min={1}
- size="small"
- placeholder="Team ID"
- value={teamIdFilter ? Number(teamIdFilter) : undefined}
- onChange={(value) => setTeamIdFilter(value != null ? String(value) : '')}
- className="w-32"
- />
- <LemonInput
- type="number"
- min={1}
- size="small"
- placeholder="Experiment ID"
- value={experimentIdFilter ? Number(experimentIdFilter) : undefined}
- onChange={(value) => setExperimentIdFilter(value != null ? String(value) : '')}
- className="w-36"
- />
- <LemonSelect
- size="small"
- value={metricTypeFilter}
- onChange={(value) => setMetricTypeFilter(value ?? '')}
- options={METRIC_TYPE_OPTIONS}
- className="w-44"
- />
- <LemonSelect
- size="small"
- value={exceptionCodeFilter}
- onChange={(value) => setExceptionCodeFilter(value ?? '')}
- options={EXCEPTION_CODE_OPTIONS}
- className="w-44"
- />
- <LemonButton
- type="secondary"
- size="small"
- onClick={() => loadSlowestQueries()}
- disabledReason={slowestQueriesLoading ? 'Loading...' : undefined}
- >
- Refresh
- </LemonButton>
- </div>
- <LemonTable
- columns={slowestQueryColumns}
- dataSource={slowestQueries}
- loading={slowestQueriesLoading}
- emptyState="No queries found in this time range"
- pagination={{ pageSize: 20 }}
- className="overflow-visible! flex-none!"
- expandable={{
- expandedRowRender: function ExpandedQuery(item) {
- return (
- <div className="flex flex-col gap-2 p-2">
- <QueryStats {...item} />
- <div className="font-mono text-xs text-muted flex flex-wrap items-center gap-x-3 gap-y-1">
- <span>
- query_id:{' '}
- <CopyToClipboardInline description="query ID">
- {item.query_id}
- </CopyToClipboardInline>
- </span>
- {item.experiment_query_group_id && (
- <span>
- group:{' '}
- <CopyToClipboardInline description="group ID">
- {item.experiment_query_group_id}
- </CopyToClipboardInline>
- </span>
- )}
- <LinkMetabaseQuery queryId={item.query_id} />
- </div>
- {item.sub_queries && item.sub_queries.length > 0 && (
- <div>
- <h4 className="mb-1">Sub-queries (precompute builds)</h4>
- <LemonTable
- size="small"
- columns={subQueryColumns}
- dataSource={item.sub_queries}
- expandable={{
- expandedRowRender: function ExpandedSubQuery(sub) {
- return (
- <div className="flex flex-col gap-2 p-2">
- <QueryStats {...sub} />
- <CodeSnippet
- language={Language.SQL}
- thing="query"
- maxLinesWithoutExpansion={10}
- >
- {sub.query}
- </CodeSnippet>
- </div>
- )
- },
- }}
- />
- </div>
- )}
- {item.exception && (
- <CodeSnippet
- language={Language.Text}
- thing="error"
- maxLinesWithoutExpansion={5}
+ <LemonTabs
+ activeKey={experimentsTab}
+ onChange={setExperimentsTab}
+ tabs={[
+ {
+ key: 'slowest_queries',
+ label: 'Slowest queries',
+ content: (
+ <>
+ <div className="flex flex-wrap gap-2 mb-4 items-center">
+ {TIME_RANGE_OPTIONS.map(({ label, hours }) => (
+ <LemonButton
+ key={hours}
+ type={hoursBack === hours ? 'primary' : 'tertiary'}
+ size="small"
+ onClick={() => setHoursBack(hours)}
>
- {item.exception}
- </CodeSnippet>
- )}
- <CodeSnippet
- language={Language.SQL}
- thing="query"
- maxLinesWithoutExpansion={10}
+ {label}
+ </LemonButton>
+ ))}
+ <LemonInput
+ type="number"
+ min={1}
+ size="small"
+ placeholder="Team ID"
+ value={teamIdFilter ? Number(teamIdFilter) : undefined}
+ onChange={(value) =>
+ setTeamIdFilter(value != null ? String(value) : '')
+ }
+ className="w-32"
+ />
+ <LemonInput
+ type="number"
+ min={1}
+ size="small"
+ placeholder="Experiment ID"
+ value={
+ experimentIdFilter ? Number(experimentIdFilter) : undefined
+ }
+ onChange={(value) =>
+ setExperimentIdFilter(value != null ? String(value) : '')
+ }
+ className="w-36"
+ />
+ <LemonSelect
+ size="small"
+ value={metricTypeFilter}
+ onChange={(value) => setMetricTypeFilter(value ?? '')}
+ options={METRIC_TYPE_OPTIONS}
+ className="w-44"
+ />
+ <LemonSelect
+ size="small"
+ value={exceptionCodeFilter}
+ onChange={(value) => setExceptionCodeFilter(value ?? '')}
+ options={EXCEPTION_CODE_OPTIONS}
+ className="w-44"
+ />
+ <LemonButton
+ type="secondary"
+ size="small"
+ onClick={() => loadSlowestQueries()}
+ disabledReason={
+ slowestQueriesLoading ? 'Loading...' : undefined
+ }
>
- {item.query}
- </CodeSnippet>
+ Refresh
+ </LemonButton>
</div>
- )
- },
- }}
- />
+ <LemonTable
+ columns={slowestQueryColumns}
+ dataSource={slowestQueries}
+ loading={slowestQueriesLoading}
+ emptyState="No queries found in this time range"
+ pagination={{ pageSize: 20 }}
+ className="overflow-visible! flex-none!"
+ expandable={{
+ expandedRowRender: function ExpandedQuery(item) {
+ return (
+ <div className="flex flex-col gap-2 p-2">
+ <QueryStats {...item} />
+ <div className="font-mono text-xs text-muted flex flex-wrap items-center gap-x-3 gap-y-1">
+ <span>
+ query_id:{' '}
+ <CopyToClipboardInline description="query ID">
+ {item.query_id}
+ </CopyToClipboardInline>
+ </span>
+ {item.experiment_query_group_id && (
+ <span>
+ group:{' '}
+ <CopyToClipboardInline description="group ID">
+ {item.experiment_query_group_id}
+ </CopyToClipboardInline>
+ </span>
+ )}
+ <LinkMetabaseQuery queryId={item.query_id} />
+ </div>
+ {item.sub_queries &&
+ item.sub_queries.length > 0 && (
+ <div>
+ <h4 className="mb-1">
+ Sub-queries (precompute builds)
+ </h4>
+ <LemonTable
+ size="small"
+ columns={subQueryColumns}
+ dataSource={item.sub_queries}
+ expandable={{
+ expandedRowRender:
+ function ExpandedSubQuery(
+ sub
+ ) {
+ return (
+ <div className="flex flex-col gap-2 p-2">
+ <QueryStats
+ {...sub}
+ />
+ <CodeSnippet
+ language={
+ Language.SQL
+ }
+ thing="query"
+ maxLinesWithoutExpansion={
+ 10
+ }
+ >
+ {sub.query}
+ </CodeSnippet>
+ </div>
+ )
+ },
+ }}
+ />
+ </div>
+ )}
+ {item.exception && (
+ <CodeSnippet
+ language={Language.Text}
+ thing="error"
+ maxLinesWithoutExpansion={5}
+ >
+ {item.exception}
+ </CodeSnippet>
+ )}
+ <CodeSnippet
+ language={Language.SQL}
+ thing="query"
+ maxLinesWithoutExpansion={10}
+ >
+ {item.query}
+ </CodeSnippet>
+ </div>
+ )
+ },
+ }}
+ />
- <h2 className="mt-8">Precomputation</h2>
- <LemonInput
- type="search"
- placeholder="Search by organization name..."
- value={search}
- onChange={setSearch}
- className="mb-4 max-w-md"
- />
- <LemonTable
- columns={precomputationColumns}
- dataSource={precomputationTeams}
- loading={precomputationTeamsLoading}
- emptyState={search ? 'No teams found' : 'No teams have precomputation enabled'}
- pagination={{ pageSize: 20 }}
- className="overflow-visible! flex-none!"
- />
- </>
+ <h2 className="mt-8">Precomputation</h2>
+ <LemonInput
+ type="search"
+ placeholder="Search by organization name..."
+ value={search}
+ onChange={setSearch}
+ className="mb-4 max-w-md"
+ />
+ <LemonTable
+ columns={precomputationColumns}
+ dataSource={precomputationTeams}
+ loading={precomputationTeamsLoading}
+ emptyState={
+ search
+ ? 'No teams found'
+ : 'No teams have precomputation enabled'
+ }
+ pagination={{ pageSize: 20 }}
+ className="overflow-visible! flex-none!"
+ />
+ </>
+ ),
+ },
+ {
+ key: 'cache_health',
+ label: 'Cache health',
+ content: <CacheHealth />,
+ },
+ ]}
+ />
),
},
]}
diff --git a/frontend/src/scenes/instance/QueryPerformance/queryPerformanceLogic.ts b/frontend/src/scenes/instance/QueryPerformance/queryPerformanceLogic.ts
index 2f417842041e..b833418c6bba 100644
--- a/frontend/src/scenes/instance/QueryPerformance/queryPerformanceLogic.ts
+++ b/frontend/src/scenes/instance/QueryPerformance/queryPerformanceLogic.ts
@@ -15,6 +15,8 @@ export interface PrecomputationTeam {
experiment_precomputation_enabled: boolean
}
+export type ExperimentsTab = 'slowest_queries' | 'cache_health'
+
export interface CachePartitionStats {
partition: string // YYYYMMDD — the expiry day of the partition (tables partition by toYYYYMMDD(expires_at))
rows: number
@@ -89,6 +91,7 @@ export const queryPerformanceLogic = kea<queryPerformanceLogicType>([
setExperimentIdFilter: (experimentId: string) => ({ experimentId }),
setMetricTypeFilter: (metricType: string) => ({ metricType }),
setExceptionCodeFilter: (exceptionCode: string) => ({ exceptionCode }),
+ setExperimentsTab: (tab: ExperimentsTab) => ({ tab }),
}),
reducers({
search: [
@@ -127,6 +130,12 @@ export const queryPerformanceLogic = kea<queryPerformanceLogicType>([
setExceptionCodeFilter: (_, { exceptionCode }) => exceptionCode,
},
],
+ experimentsTab: [
+ 'slowest_queries' as ExperimentsTab,
+ {
+ setExperimentsTab: (_, { tab }) => tab,
+ },
+ ],
}),
loaders(({ values }) => ({
precomputationTeams: [