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.

fix(help-menu): only poll the status page on US and EU cloud (#94756)

posthog[bot]ef648316b3eb
diff --git a/frontend/src/lib/components/HelpMenu/incidentStatusLogic.test.ts b/frontend/src/lib/components/HelpMenu/incidentStatusLogic.test.ts
new file mode 100644
index 000000000000..b9ccb48ca71a
--- /dev/null
+++ b/frontend/src/lib/components/HelpMenu/incidentStatusLogic.test.ts
@@ -0,0 +1,45 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { preflightLogic } from 'lib/logic/preflightLogic'
+
+import preflightJson from '~/mocks/fixtures/_preflight.json'
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+import { Region } from '~/types'
+
+import { STATUS_PAGE_BASE, incidentStatusLogic } from './incidentStatusLogic'
+
+describe('incidentStatusLogic', () => {
+ let logic: ReturnType<typeof incidentStatusLogic.build>
+ let fetchSpy: jest.SpyInstance
+
+ afterEach(() => {
+ logic?.unmount()
+ jest.restoreAllMocks()
+ })
+
+ function statusPageRequestCount(): number {
+ return fetchSpy.mock.calls.filter((call) => String(call[0]).startsWith(STATUS_PAGE_BASE)).length
+ }
+
+ it.each([
+ ['once on US cloud', Region.US, 1],
+ ['never on a self-hosted deployment', null, 0],
+ ['never on local dev', Region.DEV, 0],
+ ])('fetches the status page %s', async (_name, region, expectedRequests) => {
+ // Preflight resolves after mount here. That is the case which decides whether gating the
+ // poll on the region also stops US and EU cloud from ever polling.
+ useMocks({ get: { '/_preflight': [200, { ...preflightJson, region }] } })
+ initKeaTests()
+ fetchSpy = jest.spyOn(global, 'fetch')
+
+ logic = incidentStatusLogic()
+ logic.mount()
+
+ await expectLogic(preflightLogic).toDispatchActions(['loadPreflightSuccess'])
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(statusPageRequestCount()).toBe(expectedRequests)
+ expect(logic.values.summary === null).toBe(expectedRequests === 0)
+ })
+})
diff --git a/frontend/src/lib/components/HelpMenu/incidentStatusLogic.tsx b/frontend/src/lib/components/HelpMenu/incidentStatusLogic.tsx
index 80751d7313fb..5c737df7b124 100644
--- a/frontend/src/lib/components/HelpMenu/incidentStatusLogic.tsx
+++ b/frontend/src/lib/components/HelpMenu/incidentStatusLogic.tsx
@@ -273,11 +273,21 @@ export const incidentStatusLogic = kea<incidentStatusLogicType>([
setPageVisibility: (visible: boolean) => ({ visible }),
}),
- loaders(() => ({
+ loaders(({ values }) => ({
summary: [
null as Summary | null,
{
loadSummary: async () => {
+ // Only a deployment with a region group can act on the summary. Everywhere else
+ // (see getRelevantGroupName) every selector below discards it, so the request buys
+ // nothing. Skipping it also removes the `TypeError: Failed to fetch` that a
+ // deployment without egress to posthogstatus.com reports on every poll.
+ // `relevantGroupName` is null until preflight resolves, so the loadPreflightSuccess
+ // listener starts the poll when the region arrives late.
+ if (!values.relevantGroupName) {
+ return null
+ }
+
// The incident.io status page is external (posthogstatus.com), so the fetch can fail
// for reasons outside our control: ad blockers, tracking-protection extensions, DNS
// hiccups, brief status-page outages. Swallow the failure (degrading to 'operational'
@@ -372,6 +382,11 @@ export const incidentStatusLogic = kea<incidentStatusLogicType>([
loadSummarySuccess: () => {
setIncidentStatus(values.status)
+ if (!values.relevantGroupName) {
+ // The loader fetched nothing, so there is nothing to refresh.
+ return
+ }
+
cache.disposables.add(() => {
const timerId = setTimeout(() => actions.loadSummary(), REFRESH_INTERVAL)
return () => clearTimeout(timerId)
@@ -384,6 +399,13 @@ export const incidentStatusLogic = kea<incidentStatusLogicType>([
cache.disposables.dispose('refreshTimeout')
}
},
+ // The afterMount load can run before preflight resolves, and the region is unknown until then.
+ // Start the poll once preflight says which deployment this is.
+ [preflightLogic.actionTypes.loadPreflightSuccess]: () => {
+ if (!values.summary && !values.summaryLoading) {
+ actions.loadSummary()
+ }
+ },
})),
afterMount(({ actions, cache }) => {