Skip to content

Commit

Permalink
Feature: rollover (opensearch-project#607)
Browse files Browse the repository at this point in the history
* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: add write index in aliases

Signed-off-by: suzhou <[email protected]>

* feat: remove conditions section

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: merge data streams

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: add rollover cypress test

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: make cypress run

Signed-off-by: suzhou <[email protected]>

* feat cypress optimize

Signed-off-by: suzhou <[email protected]>

* fix: rollover with mappings

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: make rollover works in index form

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: add placeholder

Signed-off-by: suzhou <[email protected]>

* feat: alignment

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update rollover description

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update snapshot

Signed-off-by: suzhou <[email protected]>

* feat: make cypress and unit test run

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

* feat: update

Signed-off-by: suzhou <[email protected]>

---------

Signed-off-by: suzhou <[email protected]>
(cherry picked from commit 497d5f1)
  • Loading branch information
SuZhou-Joe committed Feb 22, 2023
1 parent a901f75 commit 6291eaa
Show file tree
Hide file tree
Showing 94 changed files with 5,563 additions and 163 deletions.
90 changes: 90 additions & 0 deletions cypress/integration/data_streams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { PLUGIN_NAME } from "../support/constants";

describe("Data stream", () => {
before(() => {
// Set welcome screen tracking to false
localStorage.setItem("home:welcome:show", "false");
cy.deleteTemplate("index-common-template");
cy.createIndexTemplate("index-common-template", {
index_patterns: ["ds-*"],
data_stream: {},
template: {
aliases: {
alias_for_common_1: {},
alias_for_common_2: {},
},
settings: {
number_of_shards: 2,
number_of_replicas: 1,
},
},
});
cy.request({
url: `${Cypress.env("opensearch")}/_data_stream/*`,
method: "DELETE",
failOnStatusCode: false,
});
});

beforeEach(() => {
// Visit ISM OSD
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/data-streams`);

// Common text to wait for to confirm page loaded, give up to 60 seconds for initial load
cy.contains("Data streams", { timeout: 60000 });
});

describe("can create a data stream", () => {
it("successfully", () => {
cy.get('[data-test-subj="Create data streamButton"]').click();
cy.get('[data-test-subj="form-row-name"]').type(`ds-{enter}`);
cy.get('[data-test-subj="CreateDataStreamCreateButton"]').click();
cy.contains("ds- has been successfully created.");
});
});

describe("can be searched / sorted / paginated", () => {
it("successfully", () => {
cy.contains("ds-");
cy.contains("index-common-template");
});
});

describe("can delete a data stream", () => {
it("successfully", () => {
cy.get('[data-test-subj="moreAction"] button')
.click()
.get('[data-test-subj="deleteAction"]')
.should("be.disabled")
.get(`#_selection_column_ds--checkbox`)
.click()
.get('[data-test-subj="moreAction"] button')
.click()
.get('[data-test-subj="deleteAction"]')
.click();
// The confirm button should be disabled
cy.get('[data-test-subj="deleteConfirmButton"]').should("be.disabled");
// type delete
cy.wait(500).get('[data-test-subj="deleteInput"]').type("delete");
cy.get('[data-test-subj="deleteConfirmButton"]').should("not.be.disabled");
// click to delete
cy.get('[data-test-subj="deleteConfirmButton"]').click();
// the alias should not exist
cy.wait(500);
cy.get(`#_selection_column_ds--checkbox`).should("not.exist");
});
});

after(() => {
cy.request({
url: `${Cypress.env("opensearch")}/_data_stream`,
method: "DELETE",
failOnStatusCode: false,
});
cy.deleteTemplate("index-common-template");
});
});
100 changes: 100 additions & 0 deletions cypress/integration/rollover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { PLUGIN_NAME } from "../support/constants";

const rolloverValidAlias = "rollover-valid-alias";
const rolloverAliasNeedTargetIndex = "rollover-alias-need-target-index";
const rolloverDataStream = "data-stream-rollover";
const validIndex = "index-000001";
const invalidIndex = "index-test-rollover";

describe("Rollover", () => {
before(() => {
// Set welcome screen tracking to false
localStorage.setItem("home:welcome:show", "false");
cy.deleteTemplate("index-common-template");
cy.deleteAllIndices();
cy.request({
url: `${Cypress.env("opensearch")}/_data_stream/*`,
method: "DELETE",
failOnStatusCode: false,
});
cy.createIndex(validIndex);
cy.createIndex(invalidIndex);
cy.addAlias(rolloverValidAlias, validIndex);
cy.addAlias(rolloverAliasNeedTargetIndex, invalidIndex);
cy.createIndexTemplate("index-common-template", {
index_patterns: ["data-stream-*"],
data_stream: {},
template: {
aliases: {
alias_for_common_1: {},
alias_for_common_2: {},
},
settings: {
number_of_shards: 2,
number_of_replicas: 1,
},
},
});
cy.request({
url: `${Cypress.env("opensearch")}/_data_stream/${rolloverDataStream}`,
method: "PUT",
failOnStatusCode: false,
});
});

describe("rollover", () => {
it("rollover data stream successfully", () => {
// Visit ISM OSD
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/rollover/${rolloverDataStream}`);
cy.contains("Configure source", { timeout: 60000 });

// click create
cy.get('[data-test-subj="rolloverSubmitButton"]').click({ force: true });

cy.contains(/has been successfully rollover./);
});

it("rollover valid alias successfully", () => {
// Visit ISM OSD
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/rollover/${rolloverValidAlias}`);
cy.contains("Configure new rollover index", { timeout: 60000 });

// click create
cy.get('[data-test-subj="rolloverSubmitButton"]').click({ force: true });

cy.contains(/has been successfully rollover./);
});

it("rollover invalid alias successfully", () => {
// Visit ISM OSD
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/rollover/${rolloverAliasNeedTargetIndex}`);
cy.contains("Configure new rollover index", { timeout: 60000 });

// click create
cy.get('[data-test-subj="rolloverSubmitButton"]').click({ force: true });

cy.contains("Invalid index name.");

cy.get('[data-test-subj="form-name-index"] input').type("index-test-rollover-target");

// click create
cy.get('[data-test-subj="rolloverSubmitButton"]').click({ force: true });

cy.contains(/has been successfully rollover./);
});
});

after(() => {
cy.deleteTemplate("index-common-template");
cy.deleteAllIndices();
cy.request({
url: `${Cypress.env("opensearch")}/_data_stream/*`,
method: "DELETE",
failOnStatusCode: false,
});
});
});
1 change: 1 addition & 0 deletions models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ export interface IAPICaller {
endpoint: string;
method?: string;
data?: any;
hideLog?: boolean;
}

export interface IRecoveryItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import React, { forwardRef, useRef } from "react";
import { EuiComboBoxProps } from "@elastic/eui";
import RemoteSelect, { RemoteSelectProps } from "../../../../components/RemoteSelect";
import { ServerResponse } from "../../../../../server/models/types";
import { filterByMinimatch } from "../../../../../utils/helper";
import { SYSTEM_ALIAS } from "../../../../../utils/constants";
import RemoteSelect, { RemoteSelectProps } from "../RemoteSelect";
import { ServerResponse } from "../../../server/models/types";
import { filterByMinimatch } from "../../../utils/helper";
import { SYSTEM_ALIAS } from "../../../utils/constants";

export interface AliasSelectProps extends Omit<EuiComboBoxProps<{ label: string; value: string }>, "value" | "onChange"> {
value?: Record<string, {}>;
Expand Down
10 changes: 5 additions & 5 deletions public/components/DescriptionListHoz/DescriptionListHoz.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EuiDescriptionList, EuiDescriptionListProps, EuiFlexGroup, EuiFlexItem } from "@elastic/eui";
import { EuiDescriptionList, EuiDescriptionListProps, EuiFlexGrid, EuiFlexGridProps, EuiFlexGroup, EuiFlexItem } from "@elastic/eui";
import React from "react";

const DisplayItem = (
Expand All @@ -20,15 +20,15 @@ const DisplayItem = (
);
};

export default function DescriptionListHoz(props: EuiDescriptionListProps) {
const { listItems, ...others } = props;
export default function DescriptionListHoz(props: EuiDescriptionListProps & Pick<EuiFlexGridProps, "columns">) {
const { listItems, columns = 4, ...others } = props;
return (
<EuiFlexGroup>
<EuiFlexGrid columns={columns}>
{listItems?.map((item) => (
<EuiFlexItem key={item.title as string}>
<DisplayItem listItem={item} {...others} />
</EuiFlexItem>
))}
</EuiFlexGroup>
</EuiFlexGrid>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`<DescriptionListHoz /> spec renders the component 1`] = `
<div>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
class="euiFlexGrid euiFlexGrid--gutterLarge euiFlexGrid--fourths euiFlexGrid--responsive"
>
<div
class="euiFlexItem"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ const componentMap: Record<ComponentMapEnum, React.ComponentType<IFieldComponent
return (
<EuiComboBox
onCreateOption={(searchValue) => {
const findItem = options.find((item: { label: string }) => item.label === searchValue);
const allOptions = (options as { label: string; options?: { label: string }[] }[]).reduce((total, current) => {
if (current.options) {
return [...total, ...current.options];
} else {
return [...total, current];
}
}, [] as { label: string }[]);
const findItem = allOptions.find((item: { label: string }) => item.label === searchValue);
if (findItem) {
onChange(searchValue);
}
Expand Down
10 changes: 5 additions & 5 deletions public/components/FormGenerator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { forwardRef, useRef, useImperativeHandle, useEffect, useMemo } fr
import { EuiForm, EuiFormProps, EuiSpacer } from "@elastic/eui";
import { isEqual, omit, pick } from "lodash";
import AllBuiltInComponents, { IFieldComponentProps } from "./built_in_components";
import useField, { InitOption, FieldOption, Rule, FieldInstance, FieldName } from "../../lib/field";
import useField, { InitOption, FieldOption, Rule, FieldInstance, FieldName, transformNameToString } from "../../lib/field";
import AdvancedSettings, { IAdvancedSettingsProps, IAdvancedSettingsRef } from "../AdvancedSettings";
import CustomFormRow, { CustomFormRowProps } from "../CustomFormRow";

Expand All @@ -23,7 +23,7 @@ interface IFormGeneratorAdvancedSettings<T> extends IAdvancedSettingsProps<T> {

export interface IField {
rowProps: Pick<CustomFormRowProps, "label" | "helpText" | "fullWidth" | "position" | "direction" | "style">;
name: string;
name: FieldName;
type?: keyof typeof AllBuiltInComponents;
component?: React.ComponentType<IFieldComponentProps>;
options?: Omit<IInitOption, "name">;
Expand Down Expand Up @@ -129,10 +129,10 @@ function FormGenerator<T>(props: IFormGeneratorProps<T>, ref: React.Ref<IFormGen
return (
<CustomFormRow
data-test-subj={`form-name-${item.name}`}
key={item.name}
key={transformNameToString(item.name)}
{...item.rowProps}
error={errorMessage[item.name]}
isInvalid={!!errorMessage[item.name]}
error={errorMessage[transformNameToString(item.name)]}
isInvalid={!!errorMessage[transformNameToString(item.name)]}
>
<RenderComponent
{...field.registerField({
Expand Down
Loading

0 comments on commit 6291eaa

Please sign in to comment.