Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reindex operation into indices page #513

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 225 additions & 0 deletions cypress/integration/reindex_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { PLUGIN_NAME } from "../support/constants";
const REINDEX_DEST = "test-ecomm-rdx";
const REINDEX_DEST_NO_SOURCE = "test-reindex-nosource";
const REINDEX_NEW_CREATED = "test-logs-new";

describe("Reindex", () => {
beforeEach(() => {
// Set welcome screen tracking to false
localStorage.setItem("home:welcome:show", "false");

// Visit ISM OSD
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/indices`);

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

describe("Reindex validation error", () => {
before(() => {
cy.deleteAllIndices();
// Load ecommerce data
cy.request({
method: "POST",
url: `${Cypress.env("opensearch_dashboards")}/api/sample_data/ecommerce`,
headers: {
"osd-xsrf": true,
},
}).then((response) => {
expect(response.status).equal(200);
});

cy.createIndex(REINDEX_DEST_NO_SOURCE, null, {
mappings: {
_source: {
enabled: false,
},
properties: {
name: {
type: "keyword",
},
},
},
});
});

it("source validation failed", () => {
// Confirm we have our initial index
cy.contains(REINDEX_DEST_NO_SOURCE);

cy.get(`[data-test-subj="checkboxSelectRow-${REINDEX_DEST_NO_SOURCE}"]`).check({ force: true });

// Click actions button
cy.get('[data-test-subj="moreAction"]').click();
// Reindex should show as activate
cy.get('[data-test-subj="Reindex Action"]').should("exist").should("not.have.class", "euiContextMenuItem-isDisabled").click();

cy.contains(/_sources is not enabled/);
});
});

describe("Reindex successfully", () => {
before(() => {
cy.deleteAllIndices();
// Load ecommerce data
cy.request({
method: "POST",
url: `${Cypress.env("opensearch_dashboards")}/api/sample_data/ecommerce`,
headers: {
"osd-xsrf": true,
},
}).then((response) => {
expect(response.status).equal(200);
});

cy.createIndex(REINDEX_DEST, null, { settings: { "index.number_of_replicas": 0 } });

cy.createPipeline("bumpOrderId", {
description: "sample description",
processors: [
{
set: {
field: "order_id",
value: "200{{order_id}}",
},
},
],
});
});

it("successfully", () => {
// Confirm we have our initial index
cy.contains("opensearch_dashboards_sample_data_ecommerce");

// Click actions button
cy.get('[data-test-subj="moreAction"]').click();
// Reindex should show as activate
cy.get('[data-test-subj="Reindex Action"]').should("exist").should("not.have.class", "euiContextMenuItem-isDisabled").click();

cy.get(`div[data-test-subj="sourceSelector"]`)
.find(`input[data-test-subj="comboBoxSearchInput"]`)
.type(`opensearch_dashboards_sample_data_ecommerce{downArrow}{enter}`);

cy.get(`div[data-test-subj="destinationSelector"]`)
.find(`input[data-test-subj="comboBoxSearchInput"]`)
.type(`${REINDEX_DEST}{downArrow}{enter}`);

// open advance option
cy.get('[data-test-subj="advanceOptionToggle"]').click();

// enable subset query
cy.get('[data-test-subj="subsetOption"] #subset').click({ force: true });

// input query to reindex subset
cy.get('[data-test-subj="queryJsonEditor"] textarea')
.focus()
.clear()
.type('{"query":{"match":{"category":"Men\'s Clothing"}}}', { parseSpecialCharSequences: false });

// set slices to auto
cy.get('[data-test-subj="sliceEnabled"]').click({ force: true });

// input pipeline
cy.get(`div[data-test-subj="pipelineCombobox"]`).find(`input[data-test-subj="comboBoxSearchInput"]`).type("bumpOrderId{enter}");

// click to perform reindex
cy.get('[data-test-subj="reindexConfirmButton"]').click();
cy.wait(10);
cy.contains(/Successfully started reindexing/);

cy.wait(10000);
// Type in REINDEX_DEST in search input
cy.get(`input[type="search"]`).focus().type(REINDEX_DEST);

// Confirm we only see REINDEX_DEST in table
cy.get("tbody > tr").should(($tr) => {
expect($tr, "1 row").to.have.length(1);
expect($tr, "item").to.contain(REINDEX_DEST);
});
});
});

describe("Reindex successfully for newly created index", () => {
before(() => {
cy.deleteAllIndices();
// Load logs data
cy.request({
method: "POST",
url: `${Cypress.env("opensearch_dashboards")}/api/sample_data/logs`,
headers: {
"osd-xsrf": true,
},
}).then((response) => {
expect(response.status).equal(200);
});
});

it("successfully", () => {
// search
cy.get(`input[type="search"]`).focus().type("opensearch_dashboards_sample_data_logs");

cy.wait(1000);

// Confirm we have our initial index
cy.contains("opensearch_dashboards_sample_data_logs");

// select logs index
cy.get("#_selection_column_opensearch_dashboards_sample_data_logs-checkbox").click();

// Click actions button
cy.get('[data-test-subj="moreAction"]').click();
// Reindex should show as activate
cy.get('[data-test-subj="Reindex Action"]').click();

// open advance option
cy.get('[data-test-subj="advanceOptionToggle"]').click();

// enable subset query
cy.get('[data-test-subj="subsetOption"] #subset').click({ force: true });

// input query to reindex subset
cy.get('[data-test-subj="queryJsonEditor"] textarea')
.focus()
.clear()
.type('{"query":{"match":{"ip":"135.201.60.64"}}}', { parseSpecialCharSequences: false });

// create destination
cy.get('[data-test-subj="createIndexButton"]').click();
cy.contains("Create Index");

cy.get('[placeholder="Specify a name for the new index."]').type(REINDEX_NEW_CREATED).blur();
cy.wait(1000);

// import setting and mapping
cy.get('[data-test-subj="importSettingMappingBtn"]').click();
cy.get('[data-test-subj="import-settings-opensearch_dashboards_sample_data_logs"]').click();

cy.wait(10);
cy.contains(/have been import successfully/);

cy.get('[data-test-subj="flyout-footer-action-button"]').click({ force: true });

// click to perform reindex
cy.get('[data-test-subj="reindexConfirmButton"]').click();
cy.wait(10);
cy.contains(/Successfully started reindexing/);

cy.wait(10000);
// Type in REINDEX_DEST in search input
cy.get(`input[type="search"]`).focus().type(REINDEX_NEW_CREATED);

// Confirm we only see REINDEX_DEST in table
cy.get("tbody > tr").should(($tr) => {
expect($tr, "1 row").to.have.length(1);
expect($tr, "item").to.contain(REINDEX_NEW_CREATED);
// subset data number
expect($tr, "item").to.contain(13);
});
});
});
});
1 change: 0 additions & 1 deletion cypress/integration/transforms_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe("Transforms", () => {

beforeEach(() => {
// delete test transform and index
cy.request("DELETE", `${Cypress.env("opensearch")}/test_transform*`);
cy.request({
method: "POST",
url: `${Cypress.env("opensearch")}/_plugins/_transform/${TRANSFORM_ID}/_stop`,
Expand Down
117 changes: 117 additions & 0 deletions public/pages/CreateIndex/components/AliasSelect/AliasSelect.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useState } from "react";
import { render, waitFor } from "@testing-library/react";
import AliasSelect, { AliasSelectProps } from "./index";
import userEvent from "@testing-library/user-event";

const onChangeMock = jest.fn();

const AliasSelectWithOnchange = (props: AliasSelectProps) => {
const [tempValue, setTempValue] = useState(props.value);
return (
<AliasSelect
{...props}
value={tempValue}
onChange={(val) => {
onChangeMock(val);
setTempValue(val);
}}
/>
);
};

describe("<AliasSelect /> spec", () => {
it("renders the component and remove duplicate aliases", async () => {
const onOptionsChange = jest.fn();
const { container } = render(
<AliasSelect
refreshOptions={() =>
Promise.resolve({
ok: true,
response: [
{
alias: "a",
index: "a",
},
{
alias: "a",
index: "b",
},
],
})
}
onChange={() => {}}
onOptionsChange={onOptionsChange}
/>
);
await waitFor(
() => {
expect(onOptionsChange).toBeCalledWith([
{
label: "a",
},
]);
expect(container.firstChild).toMatchSnapshot();
},
{
timeout: 3000,
}
);
});

it("renders with error", async () => {
const onOptionsChange = jest.fn();
const { container } = render(
<AliasSelect
refreshOptions={() =>
Promise.resolve({
ok: false,
error: "Some error",
})
}
onChange={() => {}}
onOptionsChange={onOptionsChange}
/>
);
await waitFor(() => {});
expect(container).toMatchSnapshot();
});

it("it should choose options or create one", async () => {
const { getByTestId } = render(
<AliasSelectWithOnchange
refreshOptions={() => Promise.resolve({ ok: true, response: [{ alias: "test", index: "123", query: "test" }] })}
/>
);
await waitFor(() => {
expect(getByTestId("comboBoxInput")).toBeInTheDocument();
});
await userEvent.click(getByTestId("comboBoxInput"));
await waitFor(() => {
expect(document.querySelector('button[title="test"]')).toBeInTheDocument();
});
await userEvent.click(document.querySelector('button[title="test"]') as Element);
await waitFor(() => {
expect(onChangeMock).toBeCalledTimes(1);
expect(onChangeMock).toBeCalledWith({
test: {},
});
});
await userEvent.type(getByTestId("comboBoxInput"), "test2{enter}");
await waitFor(() => {
expect(onChangeMock).toBeCalledTimes(2);
expect(onChangeMock).toBeCalledWith({
test: {},
test2: {},
});
});
await userEvent.type(getByTestId("comboBoxInput"), " {enter}");
await waitFor(() => {
expect(onChangeMock).toBeCalledTimes(2);
});
});
});
Loading