: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(health): sdk health click targets and incident status guard (#129815)
Rafael Audibert071d533779f6
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 869b5da5c872..a4d5b6b47d54 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -11975,9 +11975,9 @@ snapshots:scenes-app-health-tables--pipeline-empty--light:hash: v1.k794b7964.382ba01d63c72b1f6e6f6f07e31ef39d47ec0ef095d1c70f95017d5f93fed05e.8wzsa5YrwPhr_loOJQ7spJHZ3ArxXAbZ8MJJIxA3DD8scenes-app-health-tables--sdk-outdated-default--dark:- hash: v1.k794b7964.209b5f5da72ff378b5f992f69640eeab51c1a6cd84583035984ffcbbd8244162.ZTVhn6OOoP5_eIF_nCIeja3i67y8BzSjiktkL22uuUs+ hash: v1.k794b7964.47e606e839f3f81663bd5ae61bdc60a5cb76a1b39fffe83cc0acd0aa764ed20e.3BYZYY-P-SjZK0iU1F_UWgbHFz6Sue6W73DRp2VA3F4scenes-app-health-tables--sdk-outdated-default--light:- hash: v1.k794b7964.40f7d57daa7f460ba1574df131a2e3c66a7d0b19afa74c919c66d36f4edccc1c.KYMHzIZlocMgEFxFa_DVqILq-frRs-ihPD1Uc8zYE0I+ hash: v1.k794b7964.a51345fec1d04054b083aebb8e797264577978cddbce98c79879dd0ece532ee9.YuZS4SruZa6sQMvlp1xL6KH6lnKbTPdtOwkbhNQFSrgscenes-app-health-tables--sdk-outdated-empty--dark:hash: v1.k794b7964.b45eb7651fef791797177ea22579b5f3baebdcf223c04eaf2cc0d984bd3efc08.3rvi08JUdSMKoOeCwvxW_1FDarVJwiby8tQU1--To-wscenes-app-health-tables--sdk-outdated-empty--light:diff --git a/frontend/src/lib/components/HelpMenu/incidentStatusLogic.test.ts b/frontend/src/lib/components/HelpMenu/incidentStatusLogic.test.tsindex 85e3be9d6fe3..9aee4333beb4 100644--- a/frontend/src/lib/components/HelpMenu/incidentStatusLogic.test.ts+++ b/frontend/src/lib/components/HelpMenu/incidentStatusLogic.test.ts@@ -1,4 +1,5 @@import { expectLogic } from 'kea-test-utils'+import posthog from 'posthog-js'import { STATUS_PAGE_BASE } from 'lib/lemon-ui/LemonToast/incidentStatus'import { preflightLogic } from 'lib/logic/preflightLogic'@@ -43,4 +44,58 @@ describe('incidentStatusLogic', () => {expect(statusPageRequestCount()).toBe(expectedRequests)expect(logic.values.summary === null).toBe(expectedRequests === 0)})++ const outageInUs = {+ name: 'Outage',+ last_update_message: 'Investigating',+ current_worst_impact: 'partial_outage',+ affected_components: [{ name: 'API', group_name: '🇺🇸 US Cloud', current_status: 'partial_outage' }],+ }++ it.each([+ ['a well-formed body', { ongoing_incidents: [outageInUs], in_progress_maintenances: [] }, 'partial_outage'],+ ['a body without the incident arrays', { page_title: 'PostHog' }, 'operational'],+ [+ 'an incident that has no affected components',+ { ongoing_incidents: [{ name: 'Outage' }], in_progress_maintenances: [] },+ 'operational',+ ],+ [+ 'a maintenance that has a non-object component',+ { ongoing_incidents: [], in_progress_maintenances: [{ name: 'Upgrade', affected_components: [null] }] },+ 'operational',+ ],+ [+ 'a component whose group name is not a string',+ {+ ongoing_incidents: [{ ...outageInUs, affected_components: [{ name: 'API', group_name: 7 }] }],+ in_progress_maintenances: [],+ },+ 'operational',+ ],+ ])('resolves the status from %s', async (_name, body, expectedStatus) => {+ useMocks({ get: { '/_preflight': [200, { ...preflightJson, region: Region.US }] } })+ initKeaTests()+ const realFetch = global.fetch+ fetchSpy = jest+ .spyOn(global, 'fetch')+ .mockImplementation((input, init) =>+ String(input).startsWith(STATUS_PAGE_BASE)+ ? Promise.resolve(new Response(JSON.stringify(body), { status: 200 }))+ : realFetch(input, init)+ )+ const captureSpy = jest.spyOn(posthog, 'captureException').mockImplementation(() => undefined as any)++ logic = incidentStatusLogic()+ logic.mount()++ await expectLogic(preflightLogic).toDispatchActions(['loadPreflightSuccess'])+ await expectLogic(logic).toFinishAllListeners()++ const malformed = expectedStatus === 'operational'+ expect(statusPageRequestCount()).toBe(1)+ expect(captureSpy).toHaveBeenCalledTimes(malformed ? 1 : 0)+ expect(logic.values.summary === null).toBe(malformed)+ expect(logic.values.rawStatus).toBe(expectedStatus)+ })})diff --git a/frontend/src/lib/components/HelpMenu/incidentStatusLogic.tsx b/frontend/src/lib/components/HelpMenu/incidentStatusLogic.tsxindex e2b76e75d6e2..7416ff1f9e0e 100644--- a/frontend/src/lib/components/HelpMenu/incidentStatusLogic.tsx+++ b/frontend/src/lib/components/HelpMenu/incidentStatusLogic.tsx@@ -119,6 +119,36 @@ function hasRelevantComponents(affectedComponents: AffectedComponent[], relevantreturn affectedComponents.some((component) => normalizeGroupName(component.group_name ?? '') === relevantGroupName)}+function isObject(value: unknown): value is Record<string, unknown> {+ return typeof value === 'object' && value !== null+}++function isComponent(value: unknown): boolean {+ return (+ isObject(value) &&+ typeof value.name === 'string' &&+ (value.group_name === undefined || typeof value.group_name === 'string')+ )+}++function hasComponents(entry: unknown): entry is Record<string, unknown> {+ return isObject(entry) && Array.isArray(entry.affected_components) && entry.affected_components.every(isComponent)+}++function isIncident(entry: unknown): boolean {+ return hasComponents(entry) && typeof entry.name === 'string' && typeof entry.last_update_message === 'string'+}++function isSummary(data: unknown): data is Summary {+ return (+ isObject(data) &&+ Array.isArray(data.ongoing_incidents) &&+ Array.isArray(data.in_progress_maintenances) &&+ data.ongoing_incidents.every(isIncident) &&+ data.in_progress_maintenances.every(hasComponents)+ )+}+function getWorstStatusForRegion(summary: Summary, relevantGroupName: string | null): NormalizedStatus {// Filter incidents to only those affecting the current regionconst relevantIncidents = summary.ongoing_incidents.filter((incident) =>@@ -300,7 +330,13 @@ export const incidentStatusLogic = kea<incidentStatusLogicType>([)return null}- const data: Summary = await response.json()+ const data: unknown = await response.json()+ if (!isSummary(data)) {+ // A 2xx body without the incident arrays would throw in every selector that+ // reads them, and that error reaches RootErrorBoundary and blanks the app.+ posthog.captureException(new Error('incident.io summary has an unexpected shape'))+ return null+ }return data} catch (error) {if (!isBrowserNetworkFailure(error)) {diff --git a/frontend/src/scenes/health/renderers/SdkOutdatedRenderer.tsx b/frontend/src/scenes/health/renderers/SdkOutdatedRenderer.tsxindex bde317a40481..ba000ea0a849 100644--- a/frontend/src/scenes/health/renderers/SdkOutdatedRenderer.tsx+++ b/frontend/src/scenes/health/renderers/SdkOutdatedRenderer.tsx@@ -1,6 +1,7 @@-import { LemonTag, Link, Tooltip } from '@posthog/lemon-ui'+import { LemonTable, LemonTableColumns, LemonTag, Link, Tooltip } from '@posthog/lemon-ui'import { TZLabel } from 'lib/components/TZLabel'+import { dayjs } from 'lib/dayjs'import { SDK_DOCS_LINKS, SDK_TYPE_READABLE_NAME } from 'scenes/onboarding/shared/sdkHealth/sdkConstants'import type { SdkType } from 'scenes/onboarding/shared/sdkHealth/sdkHealthLogic'@@ -37,6 +38,32 @@ const statusTag = (entry: UsageEntry, migrationRequired: boolean): JSX.Element =return entry.status_reason ? <Tooltip title={entry.status_reason}>{tag}</Tooltip> : tag}+const usageColumns = (migrationRequired: boolean): LemonTableColumns<UsageEntry> => [+ {+ title: 'Version',+ key: 'lib_version',+ render: (_, entry) => <code className="text-xs">{entry.lib_version}</code>,+ },+ {+ title: 'Events (7d)',+ key: 'count',+ align: 'right',+ render: (_, entry) => (entry.count ?? 0).toLocaleString(),+ sorter: (a, b) => (a.count ?? 0) - (b.count ?? 0),+ },+ {+ title: 'Last seen',+ key: 'max_timestamp',+ render: (_, entry) => <TZLabel time={entry.max_timestamp} />,+ sorter: (a, b) => dayjs(a.max_timestamp).valueOf() - dayjs(b.max_timestamp).valueOf(),+ },+ {+ title: 'Status',+ key: 'status',+ render: (_, entry) => statusTag(entry, migrationRequired),+ },+]+export const SdkOutdatedRenderer = ({ issue }: { issue: HealthIssue }): JSX.Element => {const sdkName = issue.payload.sdk_name as SdkType | undefinedconst latestVersion = issue.payload.latest_version as string | undefined@@ -70,30 +97,15 @@ export const SdkOutdatedRenderer = ({ issue }: { issue: HealthIssue }): JSX.Elem</div>{reason && <div className="text-muted mb-2">{reason}</div>}{usage && usage.length > 0 && (- <table className="w-full text-xs border-collapse">- <thead>- <tr className="text-muted">- <th className="text-left font-medium py-1 pr-2">Version</th>- <th className="text-right font-medium py-1 pr-2">Events (7d)</th>- <th className="text-left font-medium py-1 pr-2">Last seen</th>- <th className="text-left font-medium py-1">Status</th>- </tr>- </thead>- <tbody>- {usage.map((entry) => (- <tr key={entry.lib_version} className="border-t border-border-light">- <td className="py-1 pr-2">- <code className="text-xs">{entry.lib_version}</code>- </td>- <td className="text-right py-1 pr-2">{(entry.count ?? 0).toLocaleString()}</td>- <td className="py-1 pr-2">- <TZLabel time={entry.max_timestamp} />- </td>- <td className="py-1">{statusTag(entry, migrationRequired)}</td>- </tr>- ))}- </tbody>- </table>+ <LemonTable+ dataSource={usage}+ columns={usageColumns(migrationRequired)}+ rowKey="lib_version"+ // Several of these tables share the Health page, and URL sorting shares one `order` param.+ useURLForSorting={false}+ embedded+ size="small"+ />)}</div>)diff --git a/frontend/src/scenes/onboarding/shared/sdkHealth/SdkHealthComponents.tsx b/frontend/src/scenes/onboarding/shared/sdkHealth/SdkHealthComponents.tsxindex 5e54d5c222ed..acd091ca0279 100644--- a/frontend/src/scenes/onboarding/shared/sdkHealth/SdkHealthComponents.tsx+++ b/frontend/src/scenes/onboarding/shared/sdkHealth/SdkHealthComponents.tsx@@ -142,6 +142,7 @@ export function SdkSection({ sdkType }: { sdkType: SdkType }): JSX.Element {<div><h3 className="mb-0">{sdkName}</h3><Tooltip+ openOnClicktitle={<>Version number refreshed hourly.