Skip to content

Commit 241923b

Browse files
committed
feat(HealthcheckPreview): manual fetch for ydb_ru
1 parent 40b803c commit 241923b

File tree

4 files changed

+54
-13
lines changed

4 files changed

+54
-13
lines changed

src/components/AutoRefreshControl/AutoRefreshControl.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ const b = cn('auto-refresh-control');
1313

1414
interface AutoRefreshControlProps {
1515
className?: string;
16+
onManualRefresh?: () => void;
1617
}
1718

18-
export function AutoRefreshControl({className}: AutoRefreshControlProps) {
19+
export function AutoRefreshControl({className, onManualRefresh}: AutoRefreshControlProps) {
1920
const dispatch = useTypedDispatch();
2021
const [autoRefreshInterval, setAutoRefreshInterval] = useAutoRefreshInterval();
2122
return (
@@ -24,6 +25,7 @@ export function AutoRefreshControl({className}: AutoRefreshControlProps) {
2425
view="flat-secondary"
2526
onClick={() => {
2627
dispatch(api.util.invalidateTags(['All']));
28+
onManualRefresh?.();
2729
}}
2830
extraProps={{'aria-label': i18n('Refresh')}}
2931
>

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,13 @@ function Diagnostics(props: DiagnosticsProps) {
174174
}}
175175
allowNotSelected={true}
176176
/>
177-
<AutoRefreshControl />
177+
<AutoRefreshControl
178+
onManualRefresh={() => {
179+
//this is needed to collect healthcheck if it is disabled by default https://github.com/ydb-platform/ydb-embedded-ui/issues/1889
180+
const event = new CustomEvent('diagnosticsRefresh');
181+
document.dispatchEvent(event);
182+
}}
183+
/>
178184
</div>
179185
</div>
180186
);

src/containers/Tenant/Diagnostics/TenantOverview/Healthcheck/HealthcheckPreview.tsx

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import React from 'react';
2+
13
import {
24
CircleCheck,
35
CircleInfo,
@@ -15,7 +17,7 @@ import {useClusterBaseInfo} from '../../../../../store/reducers/cluster/cluster'
1517
import {healthcheckApi} from '../../../../../store/reducers/healthcheckInfo/healthcheckInfo';
1618
import {SelfCheckResult} from '../../../../../types/api/healthcheck';
1719
import {cn} from '../../../../../utils/cn';
18-
import {useAutoRefreshInterval} from '../../../../../utils/hooks';
20+
import {useAutoRefreshInterval, useTypedSelector} from '../../../../../utils/hooks';
1921

2022
import i18n from './i18n';
2123

@@ -42,34 +44,57 @@ export function HealthcheckPreview(props: HealthcheckPreviewProps) {
4244
const {tenantName, active} = props;
4345
const [autoRefreshInterval] = useAutoRefreshInterval();
4446

47+
const {metricsTab} = useTypedSelector((state) => state.tenant);
48+
4549
const {name} = useClusterBaseInfo();
46-
const healthcheckPreviewAutorefreshDisabled = name === 'ydb_ru';
50+
51+
const healthcheckPreviewDisabled = name === 'ydb_ru';
4752

4853
const {
4954
currentData: data,
5055
isFetching,
5156
error,
5257
} = healthcheckApi.useGetHealthcheckInfoQuery(
53-
{database: tenantName},
58+
{database: tenantName, disabled: healthcheckPreviewDisabled},
5459
{
5560
//FIXME https://github.com/ydb-platform/ydb-embedded-ui/issues/1889
56-
pollingInterval: healthcheckPreviewAutorefreshDisabled
57-
? undefined
58-
: autoRefreshInterval,
61+
pollingInterval: healthcheckPreviewDisabled ? undefined : autoRefreshInterval,
5962
},
6063
);
6164

62-
const loading = isFetching && data === undefined;
65+
const [getHealthcheckQuery, {currentData: manualData, isFetching: isFetchingManually}] =
66+
healthcheckApi.useLazyGetHealthcheckInfoQuery();
67+
68+
React.useEffect(() => {
69+
if (metricsTab === 'healthcheck' && healthcheckPreviewDisabled) {
70+
getHealthcheckQuery({database: tenantName});
71+
}
72+
}, [metricsTab, healthcheckPreviewDisabled, tenantName, getHealthcheckQuery]);
73+
74+
React.useEffect(() => {
75+
const fetchHealthcheck = () => {
76+
if (healthcheckPreviewDisabled) {
77+
getHealthcheckQuery({database: tenantName});
78+
}
79+
};
80+
document.addEventListener('diagnosticsRefresh', fetchHealthcheck);
81+
return () => {
82+
document.removeEventListener('diagnosticsRefresh', fetchHealthcheck);
83+
};
84+
}, [tenantName, healthcheckPreviewDisabled, getHealthcheckQuery]);
85+
86+
const loading =
87+
(isFetching && data === undefined) || (isFetchingManually && manualData === undefined);
6388

6489
const renderHeader = () => {
6590
return (
6691
<div className={b('preview-header')}>
6792
<div className={b('preview-title-wrapper')}>
6893
<div className={b('preview-title')}>{i18n('title.healthcheck')}</div>
6994
{/* FIXME https://github.com/ydb-platform/ydb-embedded-ui/issues/1889 */}
70-
{autoRefreshInterval && healthcheckPreviewAutorefreshDisabled ? (
95+
{healthcheckPreviewDisabled ? (
7196
<Popover
72-
content={'Autorefresh is disabled. Please update healthcheck manually.'}
97+
content={'Healthcheck is disabled. Please update healthcheck manually.'}
7398
placement={['top']}
7499
className={b('icon-wrapper')}
75100
>
@@ -96,7 +121,8 @@ export function HealthcheckPreview(props: HealthcheckPreviewProps) {
96121
return <Loader size="m" />;
97122
}
98123

99-
const selfCheckResult = data?.self_check_result || SelfCheckResult.UNSPECIFIED;
124+
const selfCheckResult =
125+
data?.self_check_result || manualData?.self_check_result || SelfCheckResult.UNSPECIFIED;
100126
const modifier = selfCheckResult.toLowerCase();
101127
return (
102128
<div className={b('preview-content')}>

src/store/reducers/healthcheckInfo/healthcheckInfo.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ export const healthcheckApi = api.injectEndpoints({
1010
endpoints: (builder) => ({
1111
getHealthcheckInfo: builder.query({
1212
queryFn: async (
13-
{database, maxLevel}: {database: string; maxLevel?: number},
13+
{
14+
database,
15+
maxLevel,
16+
disabled,
17+
}: {database: string; maxLevel?: number; disabled?: boolean},
1418
{signal},
1519
) => {
20+
if (disabled) {
21+
return {data: undefined};
22+
}
1623
try {
1724
const data = await window.api.viewer.getHealthcheckInfo(
1825
{database, maxLevel},

0 commit comments

Comments
 (0)