Skip to content

Commit

Permalink
[Upgrade Assistant] Backport show on prem backup step when found-snap…
Browse files Browse the repository at this point in the history
…shots repository not found (elastic#121375) (elastic#121450)

* [Upgrade Assistant] Show on prem backup step when found-snapshots repository not found (elastic#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 <[email protected]>

* commit using @elastic.co

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Ignacio Rivas <[email protected]>
  • Loading branch information
kibanamachine and sabarasaba authored Dec 17, 2021
1 parent 8735b2a commit afcdc9b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -22,24 +22,29 @@ interface Props extends OverviewStepProps {
cloud?: CloudSetup;
}

export const getBackupStep = ({ cloud, isComplete, setIsComplete }: Props): EuiStepProps => {
const status = isComplete ? 'complete' : 'incomplete';

if (cloud?.isCloudEnabled) {
return {
status,
title,
'data-test-subj': `backupStep-${status}`,
children: (
<CloudBackup cloudSnapshotsUrl={cloud!.snapshotsUrl!} setIsComplete={setIsComplete} />
),
};
const BackupStep = ({ cloud, setIsComplete }: Omit<Props, 'isComplete'>) => {
const [forceOnPremStep, setForceOnPremStep] = useState(false);

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} />,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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} />;
Expand Down

0 comments on commit afcdc9b

Please sign in to comment.