Skip to content

Commit

Permalink
Progress auto refreshing restore status, adding indexList (#297)
Browse files Browse the repository at this point in the history
* Change alignment of Snapshot Management panels in pages/Main/Main.tsx

Signed-off-by: Chris Hesterman <[email protected]>

* Unify vertical button alignment across panels, ContentPanel.tsx

Signed-off-by: Chris Hesterman <[email protected]>

* Update jest snapshots, add ROUTE_STYLE variable

Signed-off-by: Chris Hesterman <[email protected]>

* Add placeholder restore button to Snapshots panel

Signed-off-by: Chris Hesterman <[email protected]>

* Comment out line 20 rollups_spec.js in cypress/integration/

Signed-off-by: Chris Hesterman <[email protected]>

* Remove unused code and comment cypress/integration/rollups_spec.js

Signed-off-by: Chris Hesterman <[email protected]>

* Starting adaptation/use of existing code for Restore functionality

Signed-off-by: Chris Hesterman <[email protected]>

* Adapt Snapshots.tsx to include RestoreSnapshotFlyout

Signed-off-by: Chris Hesterman <[email protected]>

* Add restoreSnapshot method to SMservice,RestoreSnapshotResponse int

Signed-off-by: Chris Hesterman <[email protected]>

* Implement RestoreSnapshotFlyout open/close

Signed-off-by: Chris Hesterman <[email protected]>

* Make Snapshot name appear on RestoreSnapshotFlyout

Signed-off-by: Chris Hesterman <[email protected]>

* Add/adapt restoreSnapshot to server/SnapshotManagementService

Signed-off-by: Chris Hesterman <[email protected]>

* Add route for restoreSnapshot in server/routes.ts

Signed-off-by: Chris Hesterman <[email protected]>

* Rudimentary restore from snapshot functionality reached, buggy

Signed-off-by: Chris Hesterman <[email protected]>

* Fix index list-snapshot restore, restrict restore to single selection

Signed-off-by: Chris Hesterman <[email protected]>

* Remove console.logs, commented out code

Signed-off-by: Chris Hesterman <[email protected]>

* Create Advanced options accordion for Snapshot restore.

Signed-off-by: Chris Hesterman <[email protected]>

Currently only visually functional. TODO - make it apply the options

Signed-off-by: Chris Hesterman <[email protected]>

* Add initial restore/rename options to ui. Only visual functionality

Signed-off-by: Chris Hesterman <[email protected]>

* Resolve radio button events not firing

Signed-off-by: Chris Hesterman <[email protected]>

Split radio buttons into SnapshotRestoreOption and SnapshotRenameOptions

Signed-off-by: Chris Hesterman <[email protected]>

Move 'restore' button between 'delete' and 'take snapshot'

Signed-off-by: Chris Hesterman <[email protected]>

Set default rename option to 'add prefix'

Signed-off-by: Chris Hesterman <[email protected]>

* Add AddPrefixInput, remove unused component RestoreSnapshotInitialOptions

Signed-off-by: Chris Hesterman <[email protected]>

* Fix issues with restore specific indices

Signed-off-by: Chris Hesterman <[email protected]>

Implement first 4 Advanced restore options functionality

Signed-off-by: Chris Hesterman <[email protected]>

* Begin cypress testing for snapshots

Signed-off-by: Chris Hesterman <[email protected]>

Passing tests for create repo and create snapshot

Signed-off-by: Chris Hesterman <[email protected]>

* Begin cypress testing Snapshots. Create repo and Create snapshot done

Signed-off-by: Chris Hesterman <[email protected]>

* Implement add_prefix functionality for snapshot restore

Signed-off-by: Chris Hesterman <[email protected]>

* Implement rename indices option for restore snapshot

Signed-off-by: Chris Hesterman <[email protected]>

* Remove console.logs, unusted variables in SnapshotFlyout, SMservice

Signed-off-by: Chris Hesterman <[email protected]>

* Add full stop to help text/errors, add RESTORE_OPTIONS enum

Signed-off-by: Chris Hesterman <[email protected]>

* Progress on IndexList component, using cat.index.

Signed-off-by: Chris Hesterman <[email protected]>

* IndexList with pagination fully functional, todo: styling

Signed-off-by: Chris Hesterman <[email protected]>

* Add RestoreActivitiesPanel component folder, files (starter)

Signed-off-by: Chris Hesterman <[email protected]>

* Complete IndexList with pagination, sorting.

Signed-off-by: Chris Hesterman <[email protected]>

* Add maxWidth to RestoreSnapshotFlyout

Signed-off-by: Chris Hesterman <[email protected]

* Implement tabs on Snapshots page: Snapshots, Restore activities...

Signed-off-by: Chris Hesterman <[email protected]>

Implement skeleton Restore activities panel, panel switching in Snapshots

Signed-off-by: Chris Hesterman <[email protected]>

* Progress on catIndexRecovery, TODO - debug

Signed-off-by: Chris Hesterman <[email protected]>

* Fix syntax bug - server/services/SnapshotManagementService.ts

Signed-off-by: Chris Hesterman <[email protected]>

* Resolved some errors, getting a response but not correct response.

Signed-off-by: Chris Hesterman <[email protected]>

* Add back line 20 in rollups_spec, required by changes in 2.3 release.

Signed-off-by: Chris Hesterman <[email protected]>

* Implement code to use Index Recovery api. successful.

Signed-off-by: Chris Hesterman <[email protected]>

* Current progress extracting data and displaying in Restore activities

Signed-off-by: Chris Hesterman <[email protected]>

* Implement Restore Activities with self updating until restore done

Signed-off-by: Chris Hesterman <[email protected]>

* Add clickable indexes link and hello world click handler

Signed-off-by: Chris Hesterman <[email protected]>

* Add toast if no snapshot selected upon restore activities click

Signed-off-by: Chris Hesterman <[email protected]>

Add empty flyout where restoring indices will be listed

Signed-off-by: Chris Hesterman <[email protected]>

* Change danger toast to warning when no snapshot selected

Signed-off-by: Chris Hesterman <[email protected]>

* Add refresh button to restore activities page, remove auto refreshing

Signed-off-by: Chris Hesterman <[email protected]>

* Remove unused getRepos func, add repo prop, trim state in RestoreFlyout

Signed-off-by: Chris Hesterman <[email protected]>

* Add increment to 2.3.0

Signed-off-by: Chris Hesterman <[email protected]>

* Create CatSnapshotIndex in server/models/interfaces, apply in IndexList

Signed-off-by: Chris Hesterman <[email protected]>

* Changes to RestoreActivitesPanel to prep for listing indice

Signed-off-by: Chris Hesterman <[email protected]>

* Re do merge commit - forgot to save file.

Signed-off-by: Chris Hesterman <[email protected]>

* Snapshots testing in progress

Signed-off-by: Chris Hesterman <[email protected]>

* Change 'Indices' to 'Index' if only 1 index.

Signed-off-by: Chris Hesterman <[email protected]>

* Auto populate prefix field initially with "restored_"

Signed-off-by: Chris Hesterman <[email protected]>

* Change Restore button to color="primary" (blue)

Signed-off-by: Chris Hesterman <[email protected]>

* Make flyout close on restore, direct user to activities tab

Signed-off-by: Chris Hesterman <[email protected]>

* Title case flyout 'status', use EuiHealth for status color dot

Signed-off-by: Chris Hesterman <[email protected]>

* Add auto status check until 'DONE', RestoreActivities

Signed-off-by: Chris Hesterman <[email protected]>

* Add auto status update until 'SUCCESS', Snapshots panel

Signed-off-by: Chris Hesterman <[email protected]>

* Change tab implementation to be consistent with other plugins

Signed-off-by: Chris Hesterman <[email protected]>

* Minor text and styling fixes, Snapshots panel

Signed-off-by: Chris Hesterman <[email protected]>

* Fix styling to match main Snapshot page, RestoreFlyout

Signed-off-by: Chris Hesterman <[email protected]>

* Update text to match mocks in Snapshots, RestoreSnapshotFlyout

Signed-off-by: Chris Hesterman <[email protected]>

* Change to title case for status in Restore activities panel

Signed-off-by: Chris Hesterman <[email protected]>

* Fix behavior of IndexList, include size when active, else unknown

Signed-off-by: Chris Hesterman <[email protected]>

* Functioning start/stop times in RestoreActivities

Signed-off-by: Chris Hesterman <[email protected]>

Accurate listing of indices being restored from snapshot

Signed-off-by: Chris Hesterman <[email protected]>

* Restore start/stop working. Auto updating working.

Signed-off-by: Chris Hesterman <[email protected]>

* Version bump 2.3.0 to 2.3 1

Signed-off-by: Chris Hesterman <[email protected]>

* Add version bump 2.3.1 for OS in cypress-workflow.yml

Signed-off-by: Chris Hesterman <[email protected]>

* Remove 2.3.1 bump

Signed-off-by: Chris Hesterman <[email protected]>

* Change 2.3 to 2.3.0 cypress-workflow.yml

Signed-off-by: Chris Hesterman <[email protected]>

* Select indices individually to fix test, line62 snapshots_spec

Signed-off-by: Chris Hesterman <[email protected]>

* Change "Sample" to "sample", rollups_spec line20

Signed-off-by: Chris Hesterman <[email protected]>

* Add 5s wait line 19 rollups_spec to wait for page load

Signed-off-by: Chris Hesterman <[email protected]>

* Change 2.4 to 2.4.0 opensearch_dashboards.json

Signed-off-by: Chris Hesterman <[email protected]>

* Resolve 1 leftover merge conflict, snapshots_spec

Signed-off-by: Chris Hesterman <[email protected]>

* Fix one test which is newer than code at this point.

Signed-off-by: Chris Hesterman <[email protected]>

* Update AddPrefixInput.test for pre populated text field

Signed-off-by: Chris Hesterman <[email protected]>

* Remove comment from AddPrefixInput.test

Signed-off-by: Chris Hesterman <[email protected]>

* Remove unneeded new lines, AddPrefixInput.test

Signed-off-by: Chris Hesterman <[email protected]>

* Remove unneeded cy.wait(), snapshots_spec

Signed-off-by: Chris Hesterman <[email protected]>

* Add React.FC to RestoreActivitiesPanel

Signed-off-by: Chris Hesterman <[email protected]>

* Remove commented code Snapshots.tsx

Signed-off-by: Chris Hesterman <[email protected]>

* Remove console log from Snapshots

Signed-off-by: Chris Hesterman <[email protected]>

* Change let to const - RestoreSnapshotFlyout/getSnapshotIndices

Signed-off-by: Chris Hesterman <[email protected]>

* Simplify conditional rendering, RestoreSnapshotFlyout

Signed-off-by: Chris Hesterman <[email protected]>

Signed-off-by: Chris Hesterman <[email protected]>
Signed-off-by: Chris Hesterman <[email protected]
  • Loading branch information
phestecAMZN authored Oct 26, 2022
1 parent 233e52c commit fa09afb
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("AddPrefixInput component", () => {
it("accepts user input", () => {
userEvent.type(screen.getByTestId("prefixInput"), "test_prefix_");

expect(screen.getByTestId("prefixInput")).toHaveValue("test_prefix_");
expect(screen.getByTestId("prefixInput")).toHaveValue("restored_test_prefix_");
});

it("sends user input to parent component via getPrefix", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface AddPrefixesInputProps {
}

const AddPrefixesInput = ({ getPrefix }: AddPrefixesInputProps) => {
const [prefix, setPrefix] = useState("");
const [prefix, setPrefix] = useState("restored_");

const onPrefixChange = (e: ChangeEvent<HTMLInputElement>) => {
setPrefix(e.target.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ exports[`AddPrefixInput component renders without error 1`] = `
data-test-subj="prefixInput"
id="some_html_id"
type="text"
value=""
value="restored_"
/>
</div>
</div>
Expand Down
51 changes: 51 additions & 0 deletions public/pages/Snapshots/components/IndexList/IndexList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiInMemoryTable, EuiIcon, EuiFlyoutHeader, EuiTitle } from "@elastic/eui";
import React from "react";
import { CatSnapshotIndex } from "../../../../../server/models/interfaces";

interface IndexListProps {
indices: CatSnapshotIndex[];
snapshot: string;
title: string
onClick: (e: React.MouseEvent) => void;
}

const IndexList = ({ indices, snapshot, onClick, title }: IndexListProps) => {
indices = indices.filter((index) => index.index?.substring(0, 7) !== ".kibana");

const columns = [
{
field: "index",
name: "Index",
width: "70%",
sortable: true,
},
{
field: "store.size",
name: "Total size",
sortable: true,
},
];

return (
<>
<EuiFlyoutHeader hasBorder>
<EuiTitle size="m">
<h2 id="flyoutTitle">
<EuiIcon onClick={onClick} size="xl" color="primary" type="arrowLeft" style={{ cursor: "pointer", padding: "0 0 5px 0" }} />{" "}
{title} {snapshot} ({indices.length})
</h2>
</EuiTitle>
</EuiFlyoutHeader>
<div style={{ padding: "1rem 1.5rem" }}>
<EuiInMemoryTable tableCaption="Indices" items={indices} columns={columns} tableLayout="auto" pagination={true} sorting={true} />
</div>
</>
);
};

export default IndexList;
8 changes: 8 additions & 0 deletions public/pages/Snapshots/components/IndexList/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import IndexList from "./IndexList";

export default IndexList;
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import { getErrorMessage } from "../../../../utils/helpers";
import { GetIndexRecoveryResponse, CatSnapshotIndex } from "../../../../../server/models/interfaces";
import { BREADCRUMBS } from "../../../../utils/constants";
import { ContentPanel } from "../../../../components/ContentPanel";
import IndexList from "../IndexList";

interface RestoreActivitiesPanelProps {
snapshotManagementService: SnapshotManagementService;
snapshotId: string;
repository: string;
restoreStartRef: number;
}

export const RestoreActivitiesPanel: React.FC<RestoreActivitiesPanelProps> = ({ snapshotManagementService, snapshotId }: RestoreActivitiesPanelProps) => {
export const RestoreActivitiesPanel: React.FC<RestoreActivitiesPanelProps> = ({ snapshotManagementService, snapshotId, restoreStartRef }: RestoreActivitiesPanelProps) => {
const context = useContext(CoreServicesContext);
const [startTime, setStartTime] = useState("");
const [stopTime, setStopTime] = useState("");
Expand All @@ -28,17 +30,32 @@ export const RestoreActivitiesPanel: React.FC<RestoreActivitiesPanelProps> = ({
const [flyout, setFlyout] = useState(false);

useEffect(() => {
context?.chrome.setBreadcrumbs([BREADCRUMBS.SNAPSHOT_MANAGEMENT, BREADCRUMBS.SNAPSHOTS, BREADCRUMBS.SNAPSHOT_RESTORE]);
getRestoreStatus();
}, []);
context!.chrome.setBreadcrumbs([BREADCRUMBS.SNAPSHOT_MANAGEMENT, BREADCRUMBS.SNAPSHOTS, BREADCRUMBS.SNAPSHOT_RESTORE]);

let getStatusInterval: ReturnType<typeof setInterval>;

if (stage.slice(0, 4) !== "Done") {
getStatusInterval = setInterval(() => {
getRestoreStatus();
}, 1000);
return () => {
clearInterval(getStatusInterval)
}
}
}, [stage]);

const getRestoreStatus = async () => {
if (stage.indexOf("DONE") >= 0) {
if (!restoreStartRef) {
return;
}

try {
const res = await snapshotManagementService.getIndexRecovery();

if (stage.indexOf("Done") >= 0) {
return;
}

if (res.ok) {
const response: GetIndexRecoveryResponse = res.response;

Expand Down Expand Up @@ -86,18 +103,18 @@ export const RestoreActivitiesPanel: React.FC<RestoreActivitiesPanelProps> = ({
minStartTime = minStartTime && minStartTime < time.start_time ? minStartTime : time.start_time;
maxStopTime = maxStopTime && maxStopTime > time.stop_time ? maxStopTime : time.stop_time;

if (info.source.index) {
if (info.source.index && info.source.snapshot === snapshotId) {
indexes.push({ index: info.source.index, "store.size": size });
}
}
}
let percent = Math.floor((doneCount / indices.length) * 100);
percent = stageIndex === stages.length - 1 ? 100 : percent;
percent = stageIndex === 4 ? 100 : percent;

setStartTime(new Date(minStartTime).toLocaleString().replace(",", " "));
setStopTime(new Date(maxStopTime).toLocaleString().replace(",", " "));
setIndices(indexes);
setStage(`${stages[stageIndex]} (${percent}%)`);
setStartTime(new Date(minStartTime).toLocaleString().replace(",", " "));
setStopTime(new Date(maxStopTime).toLocaleString().replace(",", " ") || "In progress");
setStage(`${stages[stageIndex][0] + stages[stageIndex].toLowerCase().slice(1)} (${percent}%)`);
};

const actions = useMemo(() => {
Expand All @@ -108,7 +125,9 @@ export const RestoreActivitiesPanel: React.FC<RestoreActivitiesPanelProps> = ({
];
}, [])

const indexes = `${indices.length} ${indices.length === 1 ? "Index" : "Indices"}`;
const indexText = `${indices.length === 1 && Object.keys(indices[0]).length > 0 ? "Index" : "Indices"}`
const indexes = `${indices.length === 1 && Object.keys(indices[0]).length === 0 ? "0" : indices.length} ${indexText}`;

const restoreStatus = [
{
start_time: startTime,
Expand Down Expand Up @@ -144,7 +163,7 @@ export const RestoreActivitiesPanel: React.FC<RestoreActivitiesPanelProps> = ({

return (
<>
{flyout && <EuiFlyout ownFocus={false} maxWidth={600} onClose={onCloseFlyout} size="m"></EuiFlyout>}
{flyout && <EuiFlyout ownFocus={false} maxWidth={600} onClose={onCloseFlyout} size="m"><IndexList indices={indices} snapshot={snapshotId} onClick={onCloseFlyout} title="Indices being restored in" /></EuiFlyout>}
<ContentPanel title="Restore activities in progress" actions={actions}>
<EuiInMemoryTable items={restoreStatus} columns={columns} pagination={false} />
<EuiSpacer size="xxl" />
Expand Down
Loading

0 comments on commit fa09afb

Please sign in to comment.