: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(metrics): show overview load errors and align the last datapoint time (#116671)
Daniel Visca731b09877795
diff --git a/products/metrics/frontend/components/MetricsOverview.tsx b/products/metrics/frontend/components/MetricsOverview.tsxindex 1cc5f207ed9b..3a5fa2b7841d 100644--- a/products/metrics/frontend/components/MetricsOverview.tsx+++ b/products/metrics/frontend/components/MetricsOverview.tsx@@ -66,6 +66,9 @@ const MetricsOverviewSkeleton = (): JSX.Element => (</div>)+// TZLabel sets align-middle, which drops the relative time below the baseline of the sentence around it.+const InlineTime = ({ time }: { time: string }): JSX.Element => <TZLabel time={time} className="align-baseline" />+const IngestionStatus = ({ lastSeen }: { lastSeen: string | null }): JSX.Element => {if (lastSeen === null) {return (@@ -88,7 +91,7 @@ const IngestionStatus = ({ lastSeen }: { lastSeen: string | null }): JSX.Elementchildren: 'Troubleshoot setup',}}>- No metrics received in the last 15 minutes. The last datapoint arrived <TZLabel time={lastSeen} />.+ No metrics received in the last 15 minutes. The last datapoint arrived <InlineTime time={lastSeen} />.Check that your exporters and agents are still running.</LemonBanner>)@@ -101,15 +104,33 @@ const IngestionStatus = ({ lastSeen }: { lastSeen: string | null }): JSX.Element<div className="w-2 h-2 bg-accent rounded-full" /></div><span className="text-sm">- Receiving metrics. Last datapoint <TZLabel time={lastSeen} />.+ Receiving metrics. Last datapoint <InlineTime time={lastSeen} />.</span></div>)}export const MetricsOverview = (): JSX.Element => {- const { overview, overviewLoading } = useValues(metricsOverviewLogic)- const { viewService } = useActions(metricsOverviewLogic)+ const { overview, overviewLoading, overviewLoadFailed } = useValues(metricsOverviewLogic)+ const { viewService, loadOverview } = useActions(metricsOverviewLogic)++ // A failed poll after a good load keeps the last data on screen, so the banner only+ // replaces the skeleton when nothing has loaded yet.+ if (!overview && overviewLoadFailed) {+ return (+ <LemonBanner+ type="error"+ action={{+ children: 'Try again',+ onClick: () => loadOverview(),+ loading: overviewLoading,+ 'data-attr': 'metrics-overview-retry',+ }}+ >+ Couldn't load the metrics overview. Try again in a moment.+ </LemonBanner>+ )+ }if (!overview) {return <MetricsOverviewSkeleton />diff --git a/products/metrics/frontend/components/metricsOverviewLogic.test.ts b/products/metrics/frontend/components/metricsOverviewLogic.test.tsindex bc8cdd38ce12..3debf8a387b1 100644--- a/products/metrics/frontend/components/metricsOverviewLogic.test.ts+++ b/products/metrics/frontend/components/metricsOverviewLogic.test.ts@@ -63,6 +63,23 @@ describe('metricsOverviewLogic', () => {})})+ it('flags a failed load and clears the flag when a retry succeeds', async () => {+ jest.mocked(metricsOverviewRetrieve).mockRejectedValueOnce(new Error('network down'))+ logic = metricsOverviewLogic()+ logic.mount()++ await expectLogic(logic).toDispatchActions(['loadOverviewFailure']).toMatchValues({+ overview: null,+ overviewLoadFailed: true,+ })++ await expectLogic(logic, () => {+ logic.actions.loadOverview()+ })+ .toDispatchActions(['loadOverviewSuccess'])+ .toMatchValues({ overview: OVERVIEW_FIXTURE, overviewLoadFailed: false })+ })+// The row click is the overview -> viewer handoff. Asserting the chip alone is not// enough: the viewer drops filter values it cannot send, so a chip can render while// the query goes out unfiltered. These assert `queryFilters` — what actually reachesdiff --git a/products/metrics/frontend/components/metricsOverviewLogic.tsx b/products/metrics/frontend/components/metricsOverviewLogic.tsxindex 766fe00afbd1..91d85f1200a0 100644--- a/products/metrics/frontend/components/metricsOverviewLogic.tsx+++ b/products/metrics/frontend/components/metricsOverviewLogic.tsx@@ -1,4 +1,4 @@-import { MakeLogicType, actions, afterMount, connect, kea, listeners, path } from 'kea'+import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers } from 'kea'import { loaders } from 'kea-loaders'import { teamLogic } from 'scenes/teamLogic'@@ -23,6 +23,7 @@ export const STALE_AFTER_MS = 15 * 60 * 1000export interface metricsOverviewLogicValues {currentTeamId: number | null // teamLogicoverview: _MetricsOverviewResponseApi | null+ overviewLoadFailed: booleanoverviewLoading: boolean}@@ -97,6 +98,18 @@ export const metricsOverviewLogic = kea<metricsOverviewLogicType>([},},})),+ reducers({+ // Only a success clears the flag. The poll and the retry button both call+ // loadOverview, and clearing on each call would swap the error banner for the+ // skeleton every 30 seconds while the endpoint keeps failing.+ overviewLoadFailed: [+ false,+ {+ loadOverviewFailure: () => true,+ loadOverviewSuccess: () => false,+ },+ ],+ }),listeners(({ actions }) => ({// A service row click lands in the viewer with that service already// selected. The viewer reuses the filter to scope its metric picker.