From d172a0071ff1791fab1acc3f15f77edb4c5867bf Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Mon, 10 Jul 2023 10:40:04 -0700 Subject: [PATCH 1/8] Added support for creating cluster metrics monitors with the cat/indices, and cat/shards API. Signed-off-by: AWSHurneyt --- .../utils/clusterMetricsMonitorConstants.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/public/pages/CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorConstants.js b/public/pages/CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorConstants.js index 20532552d..88829bcd4 100644 --- a/public/pages/CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorConstants.js +++ b/public/pages/CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorConstants.js @@ -104,6 +104,25 @@ export const API_TYPES = { source: 'ctx.results[0].nodes.NODE_ID.jvm.mem.heap_used_percent > 60', }, }, + CAT_INDICES: { + type: 'CAT_INDICES', + documentation: 'https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-indices/', + exampleText: 'index1,index2...', + label: 'Indices', + paths: { + withPathParams: '_cat/indices', + withoutPathParams: '_cat/indices', + }, + get prependText() { + return this.paths.withPathParams || this.paths.withoutPathParams; + }, + appendText: '', + defaultCondition: { + ...DEFAULT_CLUSTER_METRICS_SCRIPT, + source: `for (int i = 0; i < ctx.results[0].indices.size(); ++i) + if (ctx.results[0].indices[i].health != "green") return true`, + }, + }, CAT_PENDING_TASKS: { type: 'CAT_PENDING_TASKS', documentation: 'https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-pending-tasks/', @@ -140,6 +159,25 @@ export const API_TYPES = { source: 'ctx.results[0].INDEX_NAME.shards.length <= 0', }, }, + CAT_SHARDS: { + type: 'CAT_SHARDS', + documentation: 'https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-shards/', + exampleText: 'index1,index2...', + label: 'Shards', + paths: { + withPathParams: '_cat/shards', + withoutPathParams: '_cat/shards', + }, + get prependText() { + return this.paths.withPathParams || this.paths.withoutPathParams; + }, + appendText: '', + defaultCondition: { + ...DEFAULT_CLUSTER_METRICS_SCRIPT, + source: `for (int i = 0; i < ctx.results[0].shards.size(); ++i) + if (ctx.results[0].shards[i]["unassigned.for"] != null) return true`, + }, + }, CAT_SNAPSHOTS: { type: 'CAT_SNAPSHOTS', documentation: 'https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-snapshots/', From baca7ef376fa71544466d0e7a937d4aace4fe369 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Mon, 10 Jul 2023 10:49:57 -0700 Subject: [PATCH 2/8] Updated snapshots. Signed-off-by: AWSHurneyt --- .../containers/Monitors/__snapshots__/Monitors.test.js.snap | 4 ---- 1 file changed, 4 deletions(-) diff --git a/public/pages/Monitors/containers/Monitors/__snapshots__/Monitors.test.js.snap b/public/pages/Monitors/containers/Monitors/__snapshots__/Monitors.test.js.snap index 929c0d132..5dcbfd468 100644 --- a/public/pages/Monitors/containers/Monitors/__snapshots__/Monitors.test.js.snap +++ b/public/pages/Monitors/containers/Monitors/__snapshots__/Monitors.test.js.snap @@ -74,28 +74,24 @@ exports[`Monitors renders 1`] = ` Object { "field": "active", "name": "Active", - "render": [Function], "sortable": true, "truncateText": false, }, Object { "field": "acknowledged", "name": "Acknowledged", - "render": [Function], "sortable": true, "truncateText": false, }, Object { "field": "errors", "name": "Errors", - "render": [Function], "sortable": true, "truncateText": false, }, Object { "field": "ignored", "name": "Ignored", - "render": [Function], "sortable": true, "truncateText": false, }, From c3be6680122e30db493353ea377439f6d05b89c9 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Mon, 10 Jul 2023 20:19:07 -0700 Subject: [PATCH 3/8] Updated snapshots. Signed-off-by: AWSHurneyt --- .../containers/Monitors/__snapshots__/Monitors.test.js.snap | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/pages/Monitors/containers/Monitors/__snapshots__/Monitors.test.js.snap b/public/pages/Monitors/containers/Monitors/__snapshots__/Monitors.test.js.snap index 5dcbfd468..929c0d132 100644 --- a/public/pages/Monitors/containers/Monitors/__snapshots__/Monitors.test.js.snap +++ b/public/pages/Monitors/containers/Monitors/__snapshots__/Monitors.test.js.snap @@ -74,24 +74,28 @@ exports[`Monitors renders 1`] = ` Object { "field": "active", "name": "Active", + "render": [Function], "sortable": true, "truncateText": false, }, Object { "field": "acknowledged", "name": "Acknowledged", + "render": [Function], "sortable": true, "truncateText": false, }, Object { "field": "errors", "name": "Errors", + "render": [Function], "sortable": true, "truncateText": false, }, Object { "field": "ignored", "name": "Ignored", + "render": [Function], "sortable": true, "truncateText": false, }, From 466f77b00e096551292bc01d23c91f9132d15014 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Mon, 10 Jul 2023 20:47:57 -0700 Subject: [PATCH 4/8] Fixed import. Signed-off-by: AWSHurneyt --- cypress/integration/cluster_metrics_monitor_spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/integration/cluster_metrics_monitor_spec.js b/cypress/integration/cluster_metrics_monitor_spec.js index 50d05aaf3..a664d21b4 100644 --- a/cypress/integration/cluster_metrics_monitor_spec.js +++ b/cypress/integration/cluster_metrics_monitor_spec.js @@ -3,8 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -import sampleClusterMetricsMonitor from '../fixtures/sample_cluster_metrics_monitor.json'; -import { INDEX, PLUGIN_NAME } from '../../cypress/support/constants'; +import { INDEX, PLUGIN_NAME } from '../support/constants'; +import sampleClusterMetricsMonitor from '../fixtures/sample_cluster_metrics_health_monitor.json'; const SAMPLE_CLUSTER_METRICS_HEALTH_MONITOR = 'sample_cluster_metrics_health_monitor'; const SAMPLE_CLUSTER_METRICS_NODES_STATS_MONITOR = 'sample_cluster_metrics_nodes_stats_monitor'; From c9bef9473819ecd3751136f7bcd656d7afe2f44b Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Tue, 11 Jul 2023 11:40:25 -0700 Subject: [PATCH 5/8] Adjusted label text. Signed-off-by: AWSHurneyt --- .../utils/clusterMetricsMonitorConstants.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/pages/CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorConstants.js b/public/pages/CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorConstants.js index 88829bcd4..fa66e696e 100644 --- a/public/pages/CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorConstants.js +++ b/public/pages/CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorConstants.js @@ -108,7 +108,7 @@ export const API_TYPES = { type: 'CAT_INDICES', documentation: 'https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-indices/', exampleText: 'index1,index2...', - label: 'Indices', + label: 'List indices', paths: { withPathParams: '_cat/indices', withoutPathParams: '_cat/indices', @@ -145,7 +145,7 @@ export const API_TYPES = { type: 'CAT_RECOVERY', documentation: 'https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-recovery/', exampleText: 'index1,index2...', - label: 'Recovery', + label: 'List index and shard recoveries', paths: { withPathParams: '_cat/recovery', withoutPathParams: '_cat/recovery', @@ -163,7 +163,7 @@ export const API_TYPES = { type: 'CAT_SHARDS', documentation: 'https://opensearch.org/docs/latest/opensearch/rest-api/cat/cat-shards/', exampleText: 'index1,index2...', - label: 'Shards', + label: 'List shards', paths: { withPathParams: '_cat/shards', withoutPathParams: '_cat/shards', From f1af88d0412cb2b2cfe17728a9dfa40fdf854aec Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Wed, 12 Jul 2023 12:08:55 -0700 Subject: [PATCH 6/8] Updated cypress test based on text changes. Signed-off-by: AWSHurneyt --- .../integration/cluster_metrics_monitor_spec.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cypress/integration/cluster_metrics_monitor_spec.js b/cypress/integration/cluster_metrics_monitor_spec.js index a664d21b4..b5d8f0fbe 100644 --- a/cypress/integration/cluster_metrics_monitor_spec.js +++ b/cypress/integration/cluster_metrics_monitor_spec.js @@ -101,8 +101,8 @@ describe('ClusterMetricsMonitor', () => { // Wait for the API types to load and then type in the Cluster Health API cy.get('[data-test-subj="clusterMetricsApiTypeComboBox"]').type('cluster health{enter}'); - // Confirm the Query parameters field is present and described as "optional" - cy.contains('Query parameters - optional'); + // Confirm the Path parameters field is present and described as "optional" + cy.contains('Path parameters - optional'); cy.get('[data-test-subj="clusterMetricsParamsFieldText"]'); // Press the 'Run for response' button @@ -158,8 +158,8 @@ describe('ClusterMetricsMonitor', () => { // Wait for the API types to load and then type in the Cluster Health API cy.get('[data-test-subj="clusterMetricsApiTypeComboBox"]').type('nodes stats{enter}'); - // Confirm the Query parameters field is not present - cy.contains('Query parameters').should('not.exist'); + // Confirm the Path parameters field is not present + cy.contains('Path parameters').should('not.exist'); cy.get('[data-test-subj="clusterMetricsParamsFieldText"]').should('not.exist'); // Press the 'Run for response' button @@ -200,7 +200,7 @@ describe('ClusterMetricsMonitor', () => { }); }); - describe('displays Query parameters field appropriately', () => { + describe('displays Path parameters field appropriately', () => { beforeEach(() => { cy.deleteAllMonitors(); cy.reload(); @@ -222,9 +222,9 @@ describe('ClusterMetricsMonitor', () => { // Wait for the API types to load and then type in the Cluster Health API cy.get('[data-test-subj="clusterMetricsApiTypeComboBox"]').type('list snapshots{enter}'); - // Confirm the Query parameters field is present and is not described as "optional" - cy.contains('Query parameters - optional').should('not.exist'); - cy.contains('Query parameters'); + // Confirm the Path parameters field is present and is not described as "optional" + cy.contains('Path parameters - optional').should('not.exist'); + cy.contains('Path parameters'); cy.get('[data-test-subj="clusterMetricsParamsFieldText"]'); }); }); From 43b575214d9438748254af96ae68d176530e5212 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Wed, 12 Jul 2023 12:35:41 -0700 Subject: [PATCH 7/8] Made all click() calls forced. Signed-off-by: AWSHurneyt --- .../cluster_metrics_monitor_spec.js | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/cypress/integration/cluster_metrics_monitor_spec.js b/cypress/integration/cluster_metrics_monitor_spec.js index b5d8f0fbe..366cfc48a 100644 --- a/cypress/integration/cluster_metrics_monitor_spec.js +++ b/cypress/integration/cluster_metrics_monitor_spec.js @@ -21,7 +21,7 @@ const addClusterMetricsTrigger = (triggerName, triggerIndex, actionName, isEdit, // TODO: Passing button props in EUI accordion was added in newer versions (31.7.0+). // If this ever becomes available, it can be used to pass data-test-subj for the button. // Since the above is currently not possible, referring to the accordion button using its content - cy.get('button').contains('New trigger').click(); + cy.get('button').contains('New trigger').click({ force: true }); } // Type in the trigger name @@ -90,10 +90,10 @@ describe('ClusterMetricsMonitor', () => { cy.contains('There are no existing monitors'); // Go to create monitor page - cy.contains('Create monitor').click(); + cy.contains('Create monitor').click({ force: true }); // Select ClusterMetrics radio card - cy.get('[data-test-subj="clusterMetricsMonitorRadioCard"]').click(); + cy.get('[data-test-subj="clusterMetricsMonitorRadioCard"]').click({ force: true }); // Wait for input to load and then type in the monitor name cy.get('input[name="name"]').type(SAMPLE_CLUSTER_METRICS_HEALTH_MONITOR); @@ -106,7 +106,7 @@ describe('ClusterMetricsMonitor', () => { cy.get('[data-test-subj="clusterMetricsParamsFieldText"]'); // Press the 'Run for response' button - cy.get('[data-test-subj="clusterMetricsPreviewButton"]').click(); + cy.get('[data-test-subj="clusterMetricsPreviewButton"]').click({ force: true }); // Add a trigger cy.contains('Add trigger').click({ force: true }); @@ -127,7 +127,7 @@ describe('ClusterMetricsMonitor', () => { // .type('{downarrow}{enter}'); // Click the create button - cy.get('button').contains('Create').click(); + cy.get('button').contains('Create').click({ force: true }); // Confirm we can see only one row in the trigger list by checking element cy.contains('This table contains 1 row'); @@ -136,7 +136,7 @@ describe('ClusterMetricsMonitor', () => { cy.contains(SAMPLE_TRIGGER); // Go back to the Monitors list - cy.get('a').contains('Monitors').click(); + cy.get('a').contains('Monitors').click({ force: true }); // Confirm we can see the created monitor in the list cy.contains(SAMPLE_CLUSTER_METRICS_HEALTH_MONITOR); @@ -147,10 +147,10 @@ describe('ClusterMetricsMonitor', () => { cy.contains('There are no existing monitors'); // Go to create monitor page - cy.contains('Create monitor').click(); + cy.contains('Create monitor').click({ force: true }); // Select ClusterMetrics radio card - cy.get('[data-test-subj="clusterMetricsMonitorRadioCard"]').click(); + cy.get('[data-test-subj="clusterMetricsMonitorRadioCard"]').click({ force: true }); // Wait for input to load and then type in the monitor name cy.get('input[name="name"]').type(SAMPLE_CLUSTER_METRICS_NODES_STATS_MONITOR); @@ -163,7 +163,7 @@ describe('ClusterMetricsMonitor', () => { cy.get('[data-test-subj="clusterMetricsParamsFieldText"]').should('not.exist'); // Press the 'Run for response' button - cy.get('[data-test-subj="clusterMetricsPreviewButton"]').click(); + cy.get('[data-test-subj="clusterMetricsPreviewButton"]').click({ force: true }); // Add a trigger cy.contains('Add trigger').click({ force: true }); @@ -184,7 +184,7 @@ describe('ClusterMetricsMonitor', () => { // .type('{downarrow}{enter}'); // Click the create button - cy.get('button').contains('Create').click(); + cy.get('button').contains('Create').click({ force: true }); // Confirm we can see only one row in the trigger list by checking element cy.contains('This table contains 1 row'); @@ -193,7 +193,7 @@ describe('ClusterMetricsMonitor', () => { cy.contains(SAMPLE_TRIGGER); // Go back to the Monitors list - cy.get('a').contains('Monitors').click(); + cy.get('a').contains('Monitors').click({ force: true }); // Confirm we can see the created monitor in the list cy.contains(SAMPLE_CLUSTER_METRICS_NODES_STATS_MONITOR); @@ -211,10 +211,10 @@ describe('ClusterMetricsMonitor', () => { cy.contains('There are no existing monitors'); // Go to create monitor page - cy.contains('Create monitor').click(); + cy.contains('Create monitor').click({ force: true }); // Select ClusterMetrics radio card - cy.get('[data-test-subj="clusterMetricsMonitorRadioCard"]').click(); + cy.get('[data-test-subj="clusterMetricsMonitorRadioCard"]').click({ force: true }); // Wait for input to load and then type in the monitor name cy.get('input[name="name"]').type(SAMPLE_CLUSTER_METRICS_CAT_SNAPSHOTS_MONITOR); @@ -239,10 +239,10 @@ describe('ClusterMetricsMonitor', () => { cy.contains('There are no existing monitors'); // Go to create monitor page - cy.contains('Create monitor').click(); + cy.contains('Create monitor').click({ force: true }); // Select ClusterMetrics radio card - cy.get('[data-test-subj="clusterMetricsMonitorRadioCard"]').click(); + cy.get('[data-test-subj="clusterMetricsMonitorRadioCard"]').click({ force: true }); // Wait for input to load and then type in the monitor name cy.get('input[name="name"]').type(SAMPLE_CLUSTER_METRICS_HEALTH_MONITOR); @@ -302,7 +302,7 @@ describe('ClusterMetricsMonitor', () => { describe('the modal CLOSE (i.e., the X button) button is clicked', () => { // Click the CLOSE button - cy.get('[aria-label="Closes this modal window"]').click(); + cy.get('[aria-label="Closes this modal window"]').click({ force: true }); // Confirm clearTriggersModal closed cy.get('[data-test-subj="clusterMetricsClearTriggersModal"]').should('not.exist'); @@ -319,7 +319,9 @@ describe('ClusterMetricsMonitor', () => { cy.get('[data-test-subj="clusterMetricsApiTypeComboBox"]').type('cluster stats{enter}'); // Click the KEEP button - cy.get('[data-test-subj="clusterMetricsClearTriggersModalKeepButton"]').click(); + cy.get('[data-test-subj="clusterMetricsClearTriggersModalKeepButton"]').click({ + force: true, + }); // Confirm clearTriggersModal closed cy.get('[data-test-subj="clusterMetricsClearTriggersModal"]').should('not.exist'); @@ -333,7 +335,9 @@ describe('ClusterMetricsMonitor', () => { cy.get('[data-test-subj="clusterMetricsApiTypeComboBox"]').type('cluster settings{enter}'); // Click the CLEAR button - cy.get('[data-test-subj="clusterMetricsClearTriggersModalClearButton"]').click(); + cy.get('[data-test-subj="clusterMetricsClearTriggersModalClearButton"]').click({ + force: true, + }); // Confirm clearTriggersModal closed cy.get('[data-test-subj="clusterMetricsClearTriggersModal"]').should('not.exist'); From 36f1540e655b157fcdfbeb6f2ef046a92ea0c007 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Wed, 12 Jul 2023 17:31:31 -0700 Subject: [PATCH 8/8] Adjusted check for the monitor creation button. Signed-off-by: AWSHurneyt --- .../cluster_metrics_monitor_spec.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/cypress/integration/cluster_metrics_monitor_spec.js b/cypress/integration/cluster_metrics_monitor_spec.js index 366cfc48a..897766dfa 100644 --- a/cypress/integration/cluster_metrics_monitor_spec.js +++ b/cypress/integration/cluster_metrics_monitor_spec.js @@ -86,11 +86,8 @@ describe('ClusterMetricsMonitor', () => { }); it('for the Cluster Health API', () => { - // Confirm empty monitor list is loaded - cy.contains('There are no existing monitors'); - // Go to create monitor page - cy.contains('Create monitor').click({ force: true }); + cy.contains('Create monitor', { timeout: 20000 }).click({ force: true }); // Select ClusterMetrics radio card cy.get('[data-test-subj="clusterMetricsMonitorRadioCard"]').click({ force: true }); @@ -143,11 +140,8 @@ describe('ClusterMetricsMonitor', () => { }); it('for the Nodes Stats API', () => { - // Confirm empty monitor list is loaded - cy.contains('There are no existing monitors'); - // Go to create monitor page - cy.contains('Create monitor').click({ force: true }); + cy.contains('Create monitor', { timeout: 20000 }).click({ force: true }); // Select ClusterMetrics radio card cy.get('[data-test-subj="clusterMetricsMonitorRadioCard"]').click({ force: true }); @@ -207,11 +201,8 @@ describe('ClusterMetricsMonitor', () => { }); it('for the CAT Snapshots API', () => { - // Confirm empty monitor list is loaded - cy.contains('There are no existing monitors'); - // Go to create monitor page - cy.contains('Create monitor').click({ force: true }); + cy.contains('Create monitor', { timeout: 20000 }).click({ force: true }); // Select ClusterMetrics radio card cy.get('[data-test-subj="clusterMetricsMonitorRadioCard"]').click({ force: true }); @@ -235,11 +226,9 @@ describe('ClusterMetricsMonitor', () => { cy.visit(`${Cypress.env('opensearch_dashboards')}/app/${PLUGIN_NAME}#/monitors`); // Begin monitor creation - // Confirm empty monitor list is loaded - cy.contains('There are no existing monitors'); // Go to create monitor page - cy.contains('Create monitor').click({ force: true }); + cy.contains('Create monitor', { timeout: 20000 }).click({ force: true }); // Select ClusterMetrics radio card cy.get('[data-test-subj="clusterMetricsMonitorRadioCard"]').click({ force: true });