Skip to content

Commit b2e2498

Browse files
authored
Add functional test for UI Metric (#1267)
Signed-off-by: Suchit Sahoo <[email protected]>
1 parent 2881c0f commit b2e2498

File tree

6 files changed

+180
-6
lines changed

6 files changed

+180
-6
lines changed

.github/workflows/cypress-workflow-bundle-snapshot-based.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ jobs:
1616
uses: ./.github/workflows/release-e2e-workflow-template.yml
1717
with:
1818
test-name: Core Dashboards using Bundle Snapshot
19-
test-command: env CYPRESS_NO_COMMAND_LOG=1 CYPRESS_ML_COMMONS_DASHBOARDS_ENABLED=true CYPRESS_VISBUILDER_ENABLED=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/**/*.js'
20-
osd-serve-args: --data_source.enabled=true --data_source.ssl.verificationMode=none --vis_builder.enabled=true --ml_commons_dashboards.enabled=true
19+
test-command: env CYPRESS_NO_COMMAND_LOG=1 CYPRESS_ML_COMMONS_DASHBOARDS_ENABLED=true CYPRESS_VISBUILDER_ENABLED=true CYPRESS_UIMETRIC_ENABLED=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/**/*.js'
20+
osd-serve-args: --data_source.enabled=true --data_source.ssl.verificationMode=none --vis_builder.enabled=true --ml_commons_dashboards.enabled=true --usageCollection.uiMetric.enabled=true
2121

2222
tests-without-security:
2323
uses: ./.github/workflows/release-e2e-workflow-template.yml
2424
with:
2525
test-name: Core Dashboards using Bundle Snapshot
26-
test-command: env CYPRESS_NO_COMMAND_LOG=1 CYPRESS_ML_COMMONS_DASHBOARDS_ENABLED=true CYPRESS_VISBUILDER_ENABLED=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true yarn cypress:run-without-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/**/*.js'
27-
osd-serve-args: --data_source.enabled=true --data_source.ssl.verificationMode=none --vis_builder.enabled=true --ml_commons_dashboards.enabled=true
26+
test-command: env CYPRESS_NO_COMMAND_LOG=1 CYPRESS_ML_COMMONS_DASHBOARDS_ENABLED=true CYPRESS_VISBUILDER_ENABLED=true CYPRESS_UIMETRIC_ENABLED=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true yarn cypress:run-without-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/**/*.js'
27+
osd-serve-args: --data_source.enabled=true --data_source.ssl.verificationMode=none --vis_builder.enabled=true --ml_commons_dashboards.enabled=true --usageCollection.uiMetric.enabled=true
2828
security-enabled: false
2929

3030
tests-with-multiple-data-source-and-disabled-local-cluster:

cypress.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"DISABLE_LOCAL_CLUSTER": false,
3333
"browserPermissions": {
3434
"clipboard": "allow"
35-
}
35+
},
36+
"UIMETRIC_ENABLED": false
3637
}
3738
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"report":{"reportVersion":1,"uiStatsMetrics":{"console-count-GET_cat.indices":{"key":"console-count-GET_cat.indices","appName":"console","eventName":"GET_cat.indices","type":"count","stats":{"min":0,"max":1,"avg":0.5,"sum":21}}}}}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { CURRENT_TENANT } from '../../../../../utils/commands';
7+
import report from '../../../../../fixtures/dashboard/opensearch_dashboards/telemetry/uiReport.json';
8+
9+
describe('server', () => {
10+
before(() => {
11+
CURRENT_TENANT.newTenant = 'global';
12+
});
13+
14+
if (Cypress.env('UIMETRIC_ENABLED')) {
15+
it('test server side batching', function () {
16+
cy.wait(60000); // Intentional Wait to burst previous batching
17+
// verify we don't have any entries forGET_cat.indices
18+
cy.request(
19+
'GET',
20+
`${
21+
Cypress.config().baseUrl
22+
}/api/stats?extended=true&legacy=true&exclude_usage=false`
23+
).then((res) => {
24+
expect(res.status).to.eq(200);
25+
const usageMetric = res.body.usage.ui_metric.console || [];
26+
expect(usageMetric).to.not.include({ key: 'GET_cat.indices' });
27+
});
28+
29+
// Send the first UI metric report
30+
cy.request({
31+
method: 'POST',
32+
url: `${Cypress.config().baseUrl}/api/ui_metric/report`,
33+
headers: {
34+
'Osd-Xsrf': 'osd-fetch',
35+
},
36+
body: report,
37+
}).then((res) => {
38+
expect(res.status).to.eq(200);
39+
});
40+
41+
// Verify that the above report has been written
42+
cy.request(
43+
'GET',
44+
`${
45+
Cypress.config().baseUrl
46+
}/api/stats?extended=true&legacy=true&exclude_usage=false`
47+
).then((res) => {
48+
expect(res.status).to.eq(200);
49+
const usageMetric = res.body.usage.ui_metric.console || []; // eslint-disable-line no-console
50+
expect(usageMetric).to.deep.include({
51+
key: 'GET_cat.indices',
52+
value: 21,
53+
});
54+
});
55+
56+
// Send the second UI metric report
57+
cy.request({
58+
method: 'POST',
59+
url: `${Cypress.config().baseUrl}/api/ui_metric/report`,
60+
headers: {
61+
'Osd-Xsrf': 'osd-fetch',
62+
},
63+
body: report,
64+
}).then((res) => {
65+
expect(res.status).to.eq(200);
66+
});
67+
68+
// Verify that the above report has not been written and count is same as before
69+
cy.request(
70+
'GET',
71+
`${
72+
Cypress.config().baseUrl
73+
}/api/stats?extended=true&legacy=true&exclude_usage=false`
74+
).then((res) => {
75+
expect(res.status).to.eq(200);
76+
const usageMetric = res.body.usage.ui_metric.console || []; // eslint-disable-line no-console
77+
expect(usageMetric).to.deep.include({
78+
key: 'GET_cat.indices',
79+
value: 21,
80+
});
81+
});
82+
83+
cy.wait(60000); // Intentional wait to exceed batching interval
84+
85+
// Send the third UI metric report, since the time interval is greater than batching interval it will write this and previous report
86+
cy.request({
87+
method: 'POST',
88+
url: `${Cypress.config().baseUrl}/api/ui_metric/report`,
89+
headers: {
90+
'Osd-Xsrf': 'osd-fetch',
91+
},
92+
body: report,
93+
}).then((res) => {
94+
expect(res.status).to.eq(200);
95+
});
96+
97+
// Verify all the 3 Ui metric report have been written
98+
cy.request(
99+
'GET',
100+
`${
101+
Cypress.config().baseUrl
102+
}/api/stats?extended=true&legacy=true&exclude_usage=false`
103+
).then((res) => {
104+
expect(res.status).to.eq(200);
105+
const usageMetric = res.body.usage.ui_metric.console || []; // eslint-disable-line
106+
expect(usageMetric).to.deep.include({
107+
key: 'GET_cat.indices',
108+
value: 63,
109+
});
110+
});
111+
});
112+
}
113+
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
7+
import { CURRENT_TENANT } from '../../../../../utils/commands';
8+
9+
const miscUtils = new MiscUtils(cy);
10+
describe('dev_console_ui_metric', () => {
11+
before(() => {
12+
CURRENT_TENANT.newTenant = 'global';
13+
miscUtils.visitPage('app/dev_tools#/console');
14+
15+
cy.get('[data-test-subj="help-close-button"]', { timeout: 30000 }).then(
16+
($btn) => {
17+
if ($btn.is(':visible')) {
18+
cy.wrap($btn).click({ force: true });
19+
} else {
20+
cy.get('[type="button"]').contains('Console').click({ force: true });
21+
}
22+
}
23+
);
24+
25+
cy.intercept('POST', 'api/ui_metric/report').as('reportreq');
26+
27+
cy.wait(5000); // Intentional wait
28+
});
29+
if (Cypress.env('UIMETRIC_ENABLED')) {
30+
it('check UI Metric are being recorded', function () {
31+
miscUtils.visitPage('app/home#/');
32+
33+
cy.wait('@reportreq', { timeout: 100000 })
34+
.its('response.statusCode')
35+
.should('equal', 200);
36+
37+
// Now verify the response of api/stat
38+
39+
cy.request(
40+
'GET',
41+
`${
42+
Cypress.config().baseUrl
43+
}/api/stats?extended=true&legacy=true&exclude_usage=false`
44+
).then((res) => {
45+
expect(res.status).to.eq(200);
46+
expect(res.body)
47+
.to.have.property('usage')
48+
.that.has.property('application_usage')
49+
.that.has.property('dev_tools');
50+
expect(res.body)
51+
.to.have.property('usage')
52+
.that.has.property('ui_metric')
53+
.that.has.property('console')
54+
.that.has.property('length')
55+
.that.is.gt(0);
56+
});
57+
});
58+
}
59+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"osd:ciGroup1": "echo \"apps/vis_builder/*.js\"",
2929
"osd:ciGroup2": "echo \"apps/vis_type_table/*.js\"",
3030
"osd:ciGroup3": "echo \"apps/vis-augmenter/*.js\"",
31-
"osd:ciGroup4": "echo \"dashboard_sample_data_with_datasource_spec.js,dashboard_sanity_test_spec.js\"",
31+
"osd:ciGroup4": "echo \"dashboard_sample_data_with_datasource_spec.js,dashboard_sanity_test_spec.js,apps/telemetry/*.js\"",
3232
"osd:ciGroup5": "echo \"datasource-management-plugin/*.js\"",
3333
"osd:ciGroup6": "echo \"apps/data_explorer/aaa_before.spec.js,apps/data_explorer/data_source_selector.spec.js,apps/data_explorer/date_nanos_mixed.spec.js,apps/data_explorer/date_nanos.spec.js,apps/data_explorer/discover_histogram.spec.js,apps/data_explorer/discover.spec.js,apps/data_explorer/zzz_after.spec.js\"",
3434
"osd:ciGroup7": "echo \"apps/data_explorer/aaa_before.spec.js,apps/data_explorer/doc_navigation.spec.js,apps/data_explorer/doc_table.spec.js,apps/data_explorer/errors.spec.js,apps/data_explorer/field_data.spec.js,apps/data_explorer/zzz_after.spec.js\"",

0 commit comments

Comments
 (0)