Skip to content

Commit 6b1cac8

Browse files
authored
feat(HealthcheckPreview): manual fetch for ydb_ru (#1937)
1 parent 40b803c commit 6b1cac8

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

src/components/AutoRefreshControl/AutoRefreshControl.tsx

+3-1
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

+7-1
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

+36-9
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,8 +44,11 @@ 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,
@@ -53,23 +58,44 @@ export function HealthcheckPreview(props: HealthcheckPreviewProps) {
5358
{database: tenantName},
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,
62+
skip: healthcheckPreviewDisabled,
5963
},
6064
);
6165

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

6490
const renderHeader = () => {
6591
return (
6692
<div className={b('preview-header')}>
6793
<div className={b('preview-title-wrapper')}>
6894
<div className={b('preview-title')}>{i18n('title.healthcheck')}</div>
6995
{/* FIXME https://github.com/ydb-platform/ydb-embedded-ui/issues/1889 */}
70-
{autoRefreshInterval && healthcheckPreviewAutorefreshDisabled ? (
96+
{healthcheckPreviewDisabled ? (
7197
<Popover
72-
content={'Autorefresh is disabled. Please update healthcheck manually.'}
98+
content={'Healthcheck is disabled. Please update healthcheck manually.'}
7399
placement={['top']}
74100
className={b('icon-wrapper')}
75101
>
@@ -96,7 +122,8 @@ export function HealthcheckPreview(props: HealthcheckPreviewProps) {
96122
return <Loader size="m" />;
97123
}
98124

99-
const selfCheckResult = data?.self_check_result || SelfCheckResult.UNSPECIFIED;
125+
const selfCheckResult =
126+
data?.self_check_result || manualData?.self_check_result || SelfCheckResult.UNSPECIFIED;
100127
const modifier = selfCheckResult.toLowerCase();
101128
return (
102129
<div className={b('preview-content')}>

0 commit comments

Comments
 (0)