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

Migrate query enhancement cypress tests to OSD repo #8986

Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions .github/workflows/cypress_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ jobs:
- group: 9
config: standard
test_location: ftr
# Query enhanced tests
# Dashboard tests with query enhanced
- group: 10
config: query_enhanced
test_location: ftr
# Dashboard tests
test_location: source
# Dashboard tests with no query enhanced
- group: 11
config: dashboard
test_location: source
Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/8986.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Migrate query enhancement cypress tests to OSD repo ([#8986](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8986))
23 changes: 23 additions & 0 deletions cypress/fixtures/dashboard/opensearch_dashboards/data.json.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "doc",
"value": {
"id": "3",
"index": "timestamp-nanos",
"source": {
"timestamp": "2019-01-01T12:10:30.123456789Z"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should make the file name of this not data.json.txt since that is too generic of a name and could cause confusion.

we should also have more realistic data here as in some other fields maybe even number of other timefields. the size should be more than two. this way the test results for casting a wide net of a date range will yield 2 results the same way filtering by the jan 1st of 2019 would which could maybe lead to false positives in our filtering tests

},
"type": "_doc"
}
}

{
"type": "doc",
"value": {
"id": "4",
"index": "timestamp-nanos",
"source": {
"timestamp": "2019-01-01T12:10:30.123498765Z"
},
"type": "_doc"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"type": "doc",
"value": {
"id": "index-pattern:timestamp-*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the behavior we wanna continue? i think we did this from the legacy but if we we want to add more documents to these tests to capture the cases we are running into when regressions occur

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not then we should just consider having stored the ndjson of saved objects and then we just upload them on test start.

this way if we have massive test data we dont know need to open or modify that file to modify the saved objects

"index": ".kibana",
"source": {
"index-pattern": {
"fields": "[{\"name\":\"_id\",\"type\":\"string\",\"esTypes\":[\"_id\"],\"count\":1,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"name\":\"_index\",\"type\":\"string\",\"esTypes\":[\"_index\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"name\":\"_score\",\"type\":\"number\",\"count\":0,\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"name\":\"_source\",\"type\":\"_source\",\"esTypes\":[\"_source\"],\"count\":0,\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"name\":\"_type\",\"type\":\"string\",\"esTypes\":[\"_type\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"name\":\"timestamp\",\"type\":\"date\",\"esTypes\":[\"date\",\"date_nanos\"],\"count\":2,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true}]",
"timeFieldName": "timestamp",
"title": "timestamp-*",
"fieldFormatMap": "{\"timestamp\":{\"id\":\"date_nanos\"}}"
},
"type": "index-pattern"
},
"type": "_doc"
}
}

{
"type": "doc",
"value": {
"id": "2",
"index": "timestamp-millis",
"source": {
"timestamp": "2019-01-01T12:10:30.124Z"
},
"type": "_doc"
}
}

{
"type": "doc",
"value": {
"id": "1",
"index": "timestamp-millis",
"source": {
"timestamp": "2019-01-01T12:10:30.123Z"
},
"type": "_doc"
}
}

{
"type": "doc",
"value": {
"id": "3",
"index": "timestamp-nanos",
"source": {
"timestamp": "2019-01-01T12:10:30.123456789Z"
},
"type": "_doc"
}
}

{
"type": "doc",
"value": {
"id": "4",
"index": "timestamp-nanos",
"source": {
"timestamp": "2019-01-02T12:10:30.123498765Z"
},
"type": "_doc"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"type": "index",
"value": {
"aliases": {
},
"index": "timestamp-millis",
"mappings": {
"properties": {
"timestamp": {
"type": "date"
}
}
},
"settings": {
"index": {
"number_of_replicas": "1",
"number_of_shards": "1",
"codec": "best_compression"
}
}
}
}

{
"type": "index",
"value": {
"aliases": {
},
"index": "timestamp-nanos",
"mappings": {
"properties": {
"timestamp": {
"type": "date_nanos"
}
}
},
"settings": {
"index": {
"number_of_replicas": "1",
"number_of_shards": "1",
"codec": "best_compression"
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have to keep this folder structure?

core_opensearch_dashboards is redudant now since we are in the opensearch dashboards repo. we can reduce the messiness now since we should only be our tests for our plugins

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-rowe @abbyhu2000 @ananzh did you guys before porting over want to list out what is the structure of the nested folders we should shoot for? otherwise we will just port of tech debt that is just really busy work. unless this was a drop in replacement why would be suprrising then probably we are spending the effort to keep the tech debt.

we should just quickly list out what we want the end state to kind of look like

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the file structure a little nicer by getting rid of /core-opensearch-dashboard and /plugin

EX:
/cypress
/integration
/apps
/query_enhancements
/test files
/another_plugin
/test files

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ide would be able to let us know what is a .spec file but dataset_selector_spec.js would just seem like a regular file. so please use dataset_selector.spec.js

also why not typescript? @d-rowe is this setup for tyupescript?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this package is setup for typescript. It'd be great to have these be typescript files, but actually backfilling the types would be quite an effort during this migration it seems.

Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import {
MiscUtils,
TestFixtureHandler,
} from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import { CURRENT_TENANT } from '../../../../../utils/commands';
import { clusterName, clusterConnection } from '../../../../../utils/constants';

const miscUtils = new MiscUtils(cy);
const testFixtureHandler = new TestFixtureHandler(cy, Cypress.env('openSearchUrl'));

const indexSet = ['logstash-2015.09.22', 'logstash-2015.09.21', 'logstash-2015.09.20'];

describe('dataset navigator', { scrollBehavior: false }, () => {
before(() => {
CURRENT_TENANT.newTenant = 'global';
cy.fleshTenantSettings();
});

describe('empty state', () => {
it('no index pattern', function () {
// Go to the Discover page
miscUtils.visitPage(
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
);

cy.waitForLoaderNewHeader();
cy.getElementByTestId('discoverNoIndexPatterns');
});
});

describe('select indices', () => {
before(() => {
testFixtureHandler.importJSONMapping(
'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/mappings.json.txt'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could consider a utils function that does this a little bit easier like we know we want to store in fixtures so then we just need to have the plugin define it data it wants to use.

but i dont really see why each plugin needs to define its own fixtures.

if we add a new plugin then the plugin will think it needs to keep adding more sample data that is increasing the resources taken for local development when this data could have been re-used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree on getting a utils function so importing datas can be cleaner.

Currently changing the fixture file structure so that dashboard and plugin fixtures are not seperated, instead each folder are the data name and contain one data file and one mapping file.

Ex:

/fixtures
/discover
/data.json
/mappings.json
/logstash
/data.json
/mappings.json
/timestamp
/data.json
/mappings.json
.....

);

testFixtureHandler.importJSONDoc(
'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data.json.txt'
);

// Since default cluster is removed, need to create a data source connection
miscUtils.visitPage('app/management/opensearch-dashboards/dataSources/create');
cy.intercept('POST', '/api/saved_objects/data-source').as('createDataSourceRequest');
cy.getElementByTestId(`datasource_card_opensearch`).click();
cy.get('[name="dataSourceTitle"]').type(clusterName);
cy.get('[name="endpoint"]').type(clusterConnection);
cy.getElementByTestId('createDataSourceFormAuthTypeSelect').click();
cy.get(`button[id="no_auth"]`).click();

cy.getElementByTestId('createDataSourceButton').click();
cy.wait('@createDataSourceRequest').then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
cy.location('pathname', { timeout: 6000 }).should(
'include',
'app/management/opensearch-dashboards/dataSources'
);

// Go to the Discover page
miscUtils.visitPage(`app/data-explorer/discover#/`);

cy.waitForLoaderNewHeader();
});

it('with SQL as default language', function () {
cy.getElementByTestId(`datasetSelectorButton`).click();
cy.getElementByTestId(`datasetSelectorAdvancedButton`).click();
cy.get(`[title="Indexes"]`).click();
cy.get(`[title=${clusterName}]`).click();
cy.get(`[title="timestamp-nanos"]`).click();
cy.getElementByTestId('datasetSelectorNext').click();

cy.get(`[class="euiModalHeader__title"]`).should('contain', 'Step 2: Configure data');
// should have two options: SQL and PPL
cy.getElementByTestId('advancedSelectorLanguageSelect')
.get('option')
.should('have.length', 2);

//select SQL
cy.getElementByTestId('advancedSelectorLanguageSelect').select('OpenSearch SQL');
cy.getElementByTestId('advancedSelectorConfirmButton').click();

cy.waitForLoaderNewHeader();

// SQL should already be selected
cy.getElementByTestId('queryEditorLanguageSelector').should('contain', 'OpenSearch SQL');
cy.waitForLoaderNewHeader();

// SQL query should be executed and sending back result
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');

// Switch language to PPL
cy.setQueryLanguage('PPL');
cy.waitForLoaderNewHeader();
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');
});

it('with PPL as default language', function () {
cy.getElementByTestId(`datasetSelectorButton`).click();
cy.getElementByTestId(`datasetSelectorAdvancedButton`).click();
cy.get(`[title="Indexes"]`).click();
cy.get(`[title=${clusterName}]`).click();
cy.get(`[title="timestamp-nanos"]`).click();
cy.getElementByTestId('datasetSelectorNext').click();

cy.get(`[class="euiModalHeader__title"]`).should('contain', 'Step 2: Configure data');

//select PPL
cy.getElementByTestId('advancedSelectorLanguageSelect').select('PPL');

cy.getElementByTestId(`advancedSelectorTimeFieldSelect`).select('timestamp');
cy.getElementByTestId('advancedSelectorConfirmButton').click();

cy.waitForLoaderNewHeader();

// PPL should already be selected
cy.getElementByTestId('queryEditorLanguageSelector').should('contain', 'PPL');

const fromTime = 'Sep 19, 2018 @ 00:00:00.000';
const toTime = 'Sep 21, 2019 @ 00:00:00.000';
cy.setTopNavDate(fromTime, toTime);

cy.waitForLoaderNewHeader();

// Query should finish running with timestamp and finish time in the footer
cy.getElementByTestId('queryResultCompleteMsg').should('be.visible');
cy.getElementByTestId('queryEditorFooterTimestamp').should('contain', 'timestamp');

// Switch language to SQL
cy.setQueryLanguage('OpenSearch SQL');

cy.waitForLoaderNewHeader();
cy.getElementByTestId('queryResultCompleteMsg').should('be.visible');
cy.getElementByTestId('queryEditorFooterTimestamp').should('contain', 'timestamp');
});
});

describe('index pattern', () => {
it('create index pattern and select it', function () {
// import logstash functional
testFixtureHandler.importJSONDocIfNeeded(
indexSet,
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.mappings.json.txt',
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.json.txt'
);
testFixtureHandler.importJSONMapping(
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.mappings.json.txt'
);

testFixtureHandler.importJSONDoc(
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.json.txt'
);

// Go to the Discover page
miscUtils.visitPage(
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
);

cy.get(`[class~="datasetSelector__button"]`).click();
cy.getElementByTestId(`datasetOption-logstash-*`).click();

cy.waitForLoaderNewHeader();
cy.waitForSearch();
cy.verifyHitCount('14,004');
});
});

after(() => {
cy.deleteIndex('timestamp-nanos');
// delete the data source connection
miscUtils.visitPage('app/management/opensearch-dashboards/dataSources/');
cy.get(`[class="euiTableRowCell"]`).contains(clusterName).click();
cy.getElementByTestId('editDatasourceDeleteIcon').click();
cy.getElementByTestId('confirmModalConfirmButton').click();
});
});
Loading
Loading