mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Upgrade Assistant] Backport show on prem backup step when found-snapshots repository not found (#121375)
* [Upgrade Assistant] Show on prem backup step when found-snapshots repository not found (#121060) * Show on prem stem when in cloud and missing found snapshots * Remove test code * Lets match against the error containing the missing repository instead of the full message Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> * commit using @elastic.co Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
f809278b54
commit
d1efcd23e2
3 changed files with 57 additions and 17 deletions
|
@ -5,7 +5,10 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { CLOUD_BACKUP_STATUS_POLL_INTERVAL_MS } from '../../../../common/constants';
|
||||
import {
|
||||
CLOUD_BACKUP_STATUS_POLL_INTERVAL_MS,
|
||||
CLOUD_SNAPSHOT_REPOSITORY,
|
||||
} from '../../../../common/constants';
|
||||
import { setupEnvironment, advanceTime } from '../../helpers';
|
||||
import { OverviewTestBed, setupOverviewPage } from '../overview.helpers';
|
||||
|
||||
|
@ -89,6 +92,22 @@ describe('Overview - Backup Step', () => {
|
|||
testBed.component.update();
|
||||
expect(exists('cloudBackupRetryButton')).toBe(true);
|
||||
});
|
||||
|
||||
test('loads on prem if missing found-snapshots repository', async () => {
|
||||
httpRequestsMockHelpers.setLoadCloudBackupStatusResponse(undefined, {
|
||||
statusCode: 404,
|
||||
message: `[${CLOUD_SNAPSHOT_REPOSITORY}] missing`,
|
||||
});
|
||||
|
||||
testBed = await setupCloudOverviewPage();
|
||||
|
||||
const { exists } = testBed;
|
||||
|
||||
testBed.component.update();
|
||||
|
||||
expect(exists('snapshotRestoreLink')).toBe(true);
|
||||
expect(exists('cloudBackupErrorCallout')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('success state', () => {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import type { EuiStepProps } from '@elastic/eui/src/components/steps/step';
|
||||
|
||||
|
@ -22,24 +22,29 @@ interface Props extends OverviewStepProps {
|
|||
cloud?: CloudSetup;
|
||||
}
|
||||
|
||||
export const getBackupStep = ({ cloud, isComplete, setIsComplete }: Props): EuiStepProps => {
|
||||
const status = isComplete ? 'complete' : 'incomplete';
|
||||
const BackupStep = ({ cloud, setIsComplete }: Omit<Props, 'isComplete'>) => {
|
||||
const [forceOnPremStep, setForceOnPremStep] = useState(false);
|
||||
|
||||
if (cloud?.isCloudEnabled) {
|
||||
return {
|
||||
status,
|
||||
title,
|
||||
'data-test-subj': `backupStep-${status}`,
|
||||
children: (
|
||||
<CloudBackup cloudSnapshotsUrl={cloud!.snapshotsUrl!} setIsComplete={setIsComplete} />
|
||||
),
|
||||
};
|
||||
if (cloud?.isCloudEnabled && !forceOnPremStep) {
|
||||
return (
|
||||
<CloudBackup
|
||||
setIsComplete={setIsComplete}
|
||||
cloudSnapshotsUrl={cloud!.snapshotsUrl!}
|
||||
setForceOnPremStep={setForceOnPremStep}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <OnPremBackup />;
|
||||
};
|
||||
|
||||
export const getBackupStep = ({ cloud, isComplete, setIsComplete }: Props): EuiStepProps => {
|
||||
const status = cloud?.isCloudEnabled ? (isComplete ? 'complete' : 'incomplete') : 'incomplete';
|
||||
|
||||
return {
|
||||
title,
|
||||
'data-test-subj': 'backupStep-incomplete',
|
||||
status: 'incomplete',
|
||||
children: <OnPremBackup />,
|
||||
status,
|
||||
'data-test-subj': `backupStep-${status}`,
|
||||
children: <BackupStep cloud={cloud} setIsComplete={setIsComplete} />,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -21,17 +21,25 @@ import {
|
|||
EuiCallOut,
|
||||
} from '@elastic/eui';
|
||||
|
||||
import { CLOUD_SNAPSHOT_REPOSITORY } from '../../../../../common/constants';
|
||||
import { useAppContext } from '../../../app_context';
|
||||
import { ResponseError } from '../../../../../common/types';
|
||||
import { uiMetricService, UIM_BACKUP_DATA_CLOUD_CLICK } from '../../../lib/ui_metric';
|
||||
|
||||
interface Props {
|
||||
cloudSnapshotsUrl: string;
|
||||
setIsComplete: (isComplete: boolean) => void;
|
||||
setForceOnPremStep: (forceOnPrem: boolean) => void;
|
||||
}
|
||||
|
||||
const isMissingFoundSnapshotsRepo = (error: ResponseError) => {
|
||||
return error.statusCode === 404 && error.message.toString().includes(CLOUD_SNAPSHOT_REPOSITORY);
|
||||
};
|
||||
|
||||
export const CloudBackup: React.FunctionComponent<Props> = ({
|
||||
cloudSnapshotsUrl,
|
||||
setIsComplete,
|
||||
setForceOnPremStep,
|
||||
}) => {
|
||||
const {
|
||||
services: { api },
|
||||
|
@ -46,10 +54,18 @@ export const CloudBackup: React.FunctionComponent<Props> = ({
|
|||
if (!isLoading) {
|
||||
// An error should invalidate the previous state.
|
||||
setIsComplete((!error && data?.isBackedUp) ?? false);
|
||||
// If snapshots are not enabled, as it could happen in an ECE installation, the
|
||||
// cloud backup status api will return a 404 error saying that the found-snapshots
|
||||
// repository is missing. If that were to happen, we should force the users to see
|
||||
// the on prem backup step instead.
|
||||
if (error && isMissingFoundSnapshotsRepo(error)) {
|
||||
setForceOnPremStep(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Depending upon setIsComplete would create an infinite loop.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [error, isLoading, data]);
|
||||
}, [error, isLoading, data, setForceOnPremStep]);
|
||||
|
||||
if (isInitialRequest && isLoading) {
|
||||
return <EuiLoadingContent data-test-subj="cloudBackupLoading" lines={3} />;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue