Skip to content

Commit 0d285da

Browse files
authored
Fix ClickHouse outage crashing all dashboard pages (#151)
* Fix ClickHouse outage crashing all dashboard pages * fix betterer * add logging on warehouse error to let back-end know. given empty returns are to prevent front-end issues
1 parent 027ba66 commit 0d285da

File tree

18 files changed

+282
-128
lines changed

18 files changed

+282
-128
lines changed

.betterer.results

Lines changed: 45 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/graphql/generated.ts

Lines changed: 71 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/webpages/dashboard/mrt/visualization/ManualReviewDashboardInsightsCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ const ManualReviewDashboardInsightsCard = (
156156
) : null}
157157
</div>
158158
) : (
159-
<div className="text-coop-alert-red">Error finding value</div>
159+
<div className="text-sm text-slate-400">No data available.</div>
160160
)}
161161
</div>
162162
<div className="pl-2 rounded">{icon}</div>

client/src/webpages/dashboard/mrt/visualization/ManualReviewDashboardInsightsChart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,8 @@ export default function ManualReviewDashboardInsightsChart(props: {
10731073

10741074
const emptyChart = (
10751075
<div className="flex flex-col items-center justify-center p-6 rounded gap-3 bg-slate-100">
1076-
<div className="text-xl">
1077-
We didn't find any results for this query. Try another one!
1076+
<div className="text-sm text-slate-400">
1077+
No data available for the selected time period.
10781078
</div>
10791079
<CoopButton
10801080
title="Reset Filters"

client/src/webpages/dashboard/mrt/visualization/TimeToActionChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export default function TimeToActionByQueueChart({
219219

220220
const emptyChart = (
221221
<div className="flex flex-col items-center justify-center h-full gap-3 p-6 bg-indigo-100 rounded">
222-
<div className="text-xl">We didn't find any results for this query.</div>
222+
<div className="text-sm text-slate-400">No data available for the selected time period.</div>
223223
<CoopButton
224224
title="Reset Filters"
225225
onClick={() => getEmptyFilterState(timeWindow)}

client/src/webpages/dashboard/overview/Overview.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import {
77
SelectTrigger,
88
SelectValue,
99
} from '@/coop-ui/Select';
10-
import { useGQLDashboardOrgQuery } from '@/graphql/generated';
10+
import {
11+
useGQLDashboardOrgQuery,
12+
useGQLIsWarehouseAvailableQuery,
13+
} from '@/graphql/generated';
14+
import { TriangleAlert } from 'lucide-react';
1115
import {
1216
FileExclamationFilled,
1317
FlowChartAltFilled,
@@ -16,6 +20,7 @@ import {
1620
UsersFilled,
1721
} from '@/icons';
1822
import { LookbackLength } from '@/utils/time';
23+
import { gql } from '@apollo/client';
1924
import { makeEnumLike } from '@roostorg/types';
2025
import { startOfHour, subDays } from 'date-fns';
2126
import { useState } from 'react';
@@ -44,8 +49,18 @@ export function getDisplayNameForTimeDivision(
4449
}
4550
}
4651

52+
gql`
53+
query IsWarehouseAvailable {
54+
isWarehouseAvailable
55+
}
56+
`;
57+
4758
export default function Overview() {
4859
const { loading, error } = useGQLDashboardOrgQuery();
60+
const { data: warehouseData } = useGQLIsWarehouseAvailableQuery({
61+
fetchPolicy: 'cache-first',
62+
pollInterval: 60_000,
63+
});
4964
const [timeDivision, setTimeDivision] = useState<TimeDivisionOptions>('DAY');
5065
const [customTimeWindow, setCustomTimeWindow] = useState({
5166
start: startOfHour(subDays(new Date(), 7)),
@@ -197,6 +212,16 @@ export default function Overview() {
197212
<FullScreenLoading />
198213
) : (
199214
<div className="flex flex-col w-full gap-4 mb-12">
215+
{warehouseData?.isWarehouseAvailable === false && (
216+
<div className="flex items-center gap-3 p-3 border border-solid rounded-lg bg-amber-50 border-amber-200 text-amber-800">
217+
<TriangleAlert className="w-5 h-5 text-amber-500 shrink-0" />
218+
<span className="text-sm">
219+
The analytics database is currently unavailable. Some charts and
220+
statistics may show incomplete data until the service is
221+
restored.
222+
</span>
223+
</div>
224+
)}
200225
<div className="flex flex-col w-full gap-4 sm:flex-row">{cards}</div>
201226
<div className="flex w-full">
202227
<ErrorBoundary

client/src/webpages/dashboard/overview/OverviewCard.tsx

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -368,30 +368,16 @@ export default function OverviewCard(props: {
368368
? sum(previousManualActions.map((it) => it.count))
369369
: undefined;
370370

371-
if (
372-
totalActionsError ||
373-
previousTotalActionsError ||
374-
jobsPendingError ||
375-
violationsPerPolicyError ||
376-
automatedVsManualError ||
377-
previousAutomatedVsManualError ||
378-
policiesError ||
379-
rulesError ||
380-
totalActionsByRuleError
381-
) {
382-
throw (
383-
totalActionsError ??
384-
previousTotalActionsError ??
385-
jobsPendingError ??
386-
violationsPerPolicyError ??
387-
automatedVsManualError ??
388-
previousAutomatedVsManualError ??
389-
policiesError ??
390-
rulesError ??
391-
// eslint-disable-next-line
392-
totalActionsByRuleError!
393-
);
394-
}
371+
const hasError =
372+
totalActionsError ??
373+
previousTotalActionsError ??
374+
jobsPendingError ??
375+
violationsPerPolicyError ??
376+
automatedVsManualError ??
377+
previousAutomatedVsManualError ??
378+
policiesError ??
379+
rulesError ??
380+
totalActionsByRuleError;
395381

396382
const loading =
397383
totalActionsLoading ||
@@ -534,7 +520,7 @@ export default function OverviewCard(props: {
534520
);
535521

536522
const errorComponent = (
537-
<div className="py-4 text-coop-alert-red">Error finding value</div>
523+
<div className="py-4 text-sm text-slate-400">No data available.</div>
538524
);
539525

540526
const component = useMemo(() => {
@@ -591,7 +577,11 @@ export default function OverviewCard(props: {
591577
<div className="text-base font-bold">{title}</div>
592578
<Icon className={`flex w-6 h-6 ${iconColor}`} />
593579
</div>
594-
{loading ? (
580+
{hasError ? (
581+
<div className="py-4 text-sm text-slate-400">
582+
Analytics data is temporarily unavailable.
583+
</div>
584+
) : loading ? (
595585
<div className="self-start pt-4">
596586
<ComponentLoading />
597587
</div>

client/src/webpages/dashboard/overview/OverviewChart.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ export default function OverviewChart(props: {
180180

181181
const emptyChart = (
182182
<div className="flex flex-col items-center justify-center gap-3 p-6 rounded bg-slate-100">
183-
<div className="text-xl">We didn't find any results for this query</div>
183+
<div className="text-sm text-slate-400">
184+
No data available for the selected time period.
185+
</div>
184186
</div>
185187
);
186188

@@ -417,7 +419,21 @@ export default function OverviewChart(props: {
417419
));
418420

419421
if (error || decisionsError || actionStatsError) {
420-
throw error ?? decisionsError ?? actionStatsError!;
422+
return (
423+
<div className="flex flex-col w-full p-6 bg-white border border-solid rounded-lg border-slate-200">
424+
<div className="flex pb-6">
425+
<div className="flex items-start gap-2">
426+
<Icon className={`flex w-6 h-6 ${iconColor}`} />
427+
<div className="pb-2 text-lg font-bold">{title}</div>
428+
</div>
429+
</div>
430+
<div className="flex flex-col items-center justify-center gap-3 p-6 rounded bg-slate-100">
431+
<div className="text-sm text-slate-400">
432+
Analytics data is temporarily unavailable.
433+
</div>
434+
</div>
435+
</div>
436+
);
421437
}
422438

423439
const loading = decisionsLoading || actionStatsLoading;

client/src/webpages/dashboard/overview/OverviewTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default function OverviewTable(props: {
9797

9898
const emptyChart = (
9999
<div className="flex flex-col items-center justify-center gap-3 p-6 rounded bg-slate-100">
100-
<div className="text-xl">We didn't find any results for this query</div>
100+
<div className="text-sm text-slate-400">No data available for the selected time period.</div>
101101
</div>
102102
);
103103

client/src/webpages/dashboard/rules/dashboard/visualization/RulesDashboardInsights.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import './recharts.css';
22

33
import { DateRangePicker } from '@/coop-ui/DateRangePicker';
44
import { InvestmentFilled, PieChartAltFilled } from '@/icons';
5+
import { TriangleAlert } from 'lucide-react';
56
import { truncateAndFormatLargeNumber } from '@/utils/number';
67
import {
78
BarChartOutlined,
@@ -880,7 +881,13 @@ export default function RulesDashboardInsights() {
880881
);
881882

882883
if (error || policiesError) {
883-
throw error ?? policiesError!;
884+
return (
885+
<RuleInsightsEmptyCard
886+
icon={<TriangleAlert />}
887+
title="Analytics Unavailable"
888+
subtitle="We couldn't load the analytics data. The analytics service may be temporarily down. Other parts of Coop are unaffected."
889+
/>
890+
);
884891
}
885892

886893
return (

0 commit comments

Comments
 (0)