From 1158b74c5bd44c69f850e4de03a4dd106b32ad41 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Fri, 12 Apr 2024 22:13:15 -0700 Subject: [PATCH] [Backport 2.13] Removed cross cluster monitor experimental banner, and fixed bugs. (#933) (#938) * Removed cross cluster monitor experimental banner, and fixed bugs. (#933) * Fixed validation bug for cross cluster monitors. Signed-off-by: AWSHurneyt * Adding check for whether user can call an API used to configure cross cluster monitors. Signed-off-by: AWSHurneyt * Removed experimental banner. Updated zips. Signed-off-by: AWSHurneyt * Adjusted setting path to align with backend. Signed-off-by: AWSHurneyt * Deleted unused experimental banner file. Signed-off-by: AWSHurneyt * Revised based on feedback. Signed-off-by: AWSHurneyt --------- Signed-off-by: AWSHurneyt (cherry picked from commit 5da08a45ad2738c29151c040b91c96e4610f5c0a) Signed-off-by: github-actions[bot] * Adjusted OSD version used by tests. Signed-off-by: AWSHurneyt --------- Signed-off-by: AWSHurneyt Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .github/workflows/cypress-workflow.yml | 4 +- .github/workflows/unit-tests-workflow.yml | 2 +- .../components/ExperimentalBanner.js | 34 ------------- .../containers/CrossClusterConfiguration.js | 3 -- .../utils/helpers.js | 3 ++ .../containers/DataSource/DataSource.js | 3 +- .../containers/DefineMonitor/DefineMonitor.js | 51 ++++++++++++++----- .../__snapshots__/DefineMonitor.test.js.snap | 1 + .../containers/MonitorIndex/MonitorIndex.js | 4 +- public/utils/validate.js | 2 +- 10 files changed, 51 insertions(+), 56 deletions(-) delete mode 100644 public/pages/CreateMonitor/components/CrossClusterConfigurations/components/ExperimentalBanner.js diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index 6e2c1049e..5d3638a4e 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -7,8 +7,8 @@ on: branches: - "**" env: - OPENSEARCH_DASHBOARDS_VERSION: '2.x' - ALERTING_PLUGIN_BRANCH: '2.x' + OPENSEARCH_DASHBOARDS_VERSION: '2.13.0' + ALERTING_PLUGIN_BRANCH: '2.13' jobs: tests: name: Run Cypress E2E tests diff --git a/.github/workflows/unit-tests-workflow.yml b/.github/workflows/unit-tests-workflow.yml index 9bdf19122..ac4fcb10c 100644 --- a/.github/workflows/unit-tests-workflow.yml +++ b/.github/workflows/unit-tests-workflow.yml @@ -7,7 +7,7 @@ on: branches: - "**" env: - OPENSEARCH_DASHBOARDS_VERSION: '2.x' + OPENSEARCH_DASHBOARDS_VERSION: '2.13.0' jobs: Get-CI-Image-Tag: uses: opensearch-project/opensearch-build/.github/workflows/get-ci-image-tag.yml@main diff --git a/public/pages/CreateMonitor/components/CrossClusterConfigurations/components/ExperimentalBanner.js b/public/pages/CreateMonitor/components/CrossClusterConfigurations/components/ExperimentalBanner.js deleted file mode 100644 index e5f58fb90..000000000 --- a/public/pages/CreateMonitor/components/CrossClusterConfigurations/components/ExperimentalBanner.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import React from 'react'; -import { EuiCallOut, EuiLink, EuiSpacer } from '@elastic/eui'; - -export const REMOTE_MONITORING_ENABLED_SETTING_PATH = 'plugins.alerting.remote_monitoring_enabled'; - -export const ExperimentalBanner = () => { - return ( - <> - -

- The feature is experimental and should not be used in a production environment. Any index - patterns, visualization, and observability panels will be impacted if the feature is - deactivated. For more information see  - - Alerting documentation - - . To leave feedback, visit  - - forum.opensearch.org - -

-
- - - ); -}; diff --git a/public/pages/CreateMonitor/components/CrossClusterConfigurations/containers/CrossClusterConfiguration.js b/public/pages/CreateMonitor/components/CrossClusterConfigurations/containers/CrossClusterConfiguration.js index 14a2067cd..5b5527739 100644 --- a/public/pages/CreateMonitor/components/CrossClusterConfigurations/containers/CrossClusterConfiguration.js +++ b/public/pages/CreateMonitor/components/CrossClusterConfigurations/containers/CrossClusterConfiguration.js @@ -10,8 +10,6 @@ import { FormikComboBox } from '../../../../../components/FormControls'; import { MONITOR_TYPE } from '../../../../../utils/constants'; import { connect } from 'formik'; import { validateIndex } from '../../../../../utils/validate'; -import { ExperimentalBanner } from '../components/ExperimentalBanner'; - export const CROSS_CLUSTER_SETUP_LINK = 'https://opensearch.org/docs/latest/security/access-control/cross-cluster-search/'; @@ -323,7 +321,6 @@ export class CrossClusterConfiguration extends Component { return ( <> - { let localClusterName = DEFAULT_EMPTY_DATA; try { diff --git a/public/pages/CreateMonitor/containers/DataSource/DataSource.js b/public/pages/CreateMonitor/containers/DataSource/DataSource.js index fa9029863..96be121df 100644 --- a/public/pages/CreateMonitor/containers/DataSource/DataSource.js +++ b/public/pages/CreateMonitor/containers/DataSource/DataSource.js @@ -33,7 +33,7 @@ class DataSource extends Component { } render() { - const { isMinimal, remoteMonitoringEnabled } = this.props; + const { isMinimal, canCallGetRemoteIndexes, remoteMonitoringEnabled } = this.props; const { monitor_type, searchType } = this.props.values; const displayTimeField = searchType === SEARCH_TYPE.GRAPH && @@ -44,6 +44,7 @@ class DataSource extends Component { diff --git a/public/pages/CreateMonitor/containers/DefineMonitor/DefineMonitor.js b/public/pages/CreateMonitor/containers/DefineMonitor/DefineMonitor.js index 64fdc91fb..6a2af98d4 100644 --- a/public/pages/CreateMonitor/containers/DefineMonitor/DefineMonitor.js +++ b/public/pages/CreateMonitor/containers/DefineMonitor/DefineMonitor.js @@ -39,7 +39,8 @@ import ConfigureDocumentLevelQueries from '../../components/DocumentLevelMonitor import FindingsDashboard from '../../../Dashboard/containers/FindingsDashboard'; import { validDocLevelGraphQueries } from '../../components/DocumentLevelMonitorQueries/utils/helpers'; import { validateWhereFilters } from '../../components/MonitorExpressions/expressions/utils/whereHelpers'; -import { REMOTE_MONITORING_ENABLED_SETTING_PATH } from '../../components/CrossClusterConfigurations/components/ExperimentalBanner'; + +import { CROSS_CLUSTER_MONITORING_ENABLED_SETTING } from '../../components/CrossClusterConfigurations/utils/helpers'; function renderEmptyMessage(message) { return ( @@ -76,6 +77,7 @@ class DefineMonitor extends Component { loadingResponse: false, PanelComponent: props.flyoutMode ? ({ children }) => <>{children} : ContentPanel, remoteMonitoringEnabled: false, + canCallGetRemoteIndexes: false, }; this.renderGraph = this.renderGraph.bind(this); @@ -180,31 +182,52 @@ class DefineMonitor extends Component { } async getSettings() { + const { httpClient } = this.props; + let remoteMonitoringEnabled = false; + let canCallGetRemoteIndexes = false; + + // Check whether remote monitoring is enabled try { - const { httpClient } = this.props; const response = await httpClient.get('../api/alerting/_settings'); if (response.ok) { const { defaults, transient, persistent } = response.resp; - let remoteMonitoringEnabled = _.get( + remoteMonitoringEnabled = _.get( // If present, take the 'transient' setting. transient, - REMOTE_MONITORING_ENABLED_SETTING_PATH, + CROSS_CLUSTER_MONITORING_ENABLED_SETTING, // Else take the 'persistent' setting. _.get( persistent, - REMOTE_MONITORING_ENABLED_SETTING_PATH, + CROSS_CLUSTER_MONITORING_ENABLED_SETTING, // Else take the 'default' setting. - _.get(defaults, REMOTE_MONITORING_ENABLED_SETTING_PATH, false) + _.get(defaults, CROSS_CLUSTER_MONITORING_ENABLED_SETTING, false) ) ); - // Boolean settings are returned as strings (e.g., `"true"`, and `"false"`). Constructing boolean value from the string. - if (typeof remoteMonitoringEnabled === 'string') + + // Boolean settings can be returned as strings (e.g., `"true"`, and `"false"`). Constructing boolean value from the string. + if (typeof remoteMonitoringEnabled === 'string') { remoteMonitoringEnabled = JSON.parse(remoteMonitoringEnabled); - this.setState({ remoteMonitoringEnabled: remoteMonitoringEnabled }); + } } } catch (e) { - console.log('Error while retrieving settings', e); + console.log('Error while retrieving settings:', e); } + + // Check whether the user can call GetRemoteIndexes + if (remoteMonitoringEnabled) { + try { + const query = { + indexes: '*,*:*', + include_mappings: false, + }; + const response = await httpClient.get(`../api/alerting/remote/indexes`, { query: query }); + canCallGetRemoteIndexes = response.ok; + } catch (e) { + console.warn('Error while retrieving clusters:', e); + } + } + + this.setState({ remoteMonitoringEnabled, canCallGetRemoteIndexes }); } requiresTimeField() { @@ -656,13 +679,16 @@ class DefineMonitor extends Component { isDarkMode, flyoutMode, } = this.props; - const { dataTypes, PanelComponent, remoteMonitoringEnabled } = this.state; + const { dataTypes, PanelComponent, canCallGetRemoteIndexes, remoteMonitoringEnabled } = + this.state; const monitorContent = this.getMonitorContent(); const { searchType } = this.props.values; const displayDataSourcePanel = searchType === SEARCH_TYPE.GRAPH || searchType === SEARCH_TYPE.QUERY || - (remoteMonitoringEnabled && monitor_type === MONITOR_TYPE.CLUSTER_METRICS); + (canCallGetRemoteIndexes && + remoteMonitoringEnabled && + monitor_type === MONITOR_TYPE.CLUSTER_METRICS); return (
@@ -676,6 +702,7 @@ class DefineMonitor extends Component { detectorId={detectorId} notifications={notifications} isDarkMode={isDarkMode} + canCallGetRemoteIndexes={canCallGetRemoteIndexes} remoteMonitoringEnabled={remoteMonitoringEnabled} /> diff --git a/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap b/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap index a0c25c035..b91cb4fd3 100644 --- a/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap +++ b/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap @@ -4,6 +4,7 @@ exports[`DefineMonitor renders 1`] = `
- {remoteMonitoringEnabled && supportsCrossClusterMonitoring ? ( + {remoteMonitoringEnabled && canCallGetRemoteIndexes && supportsCrossClusterMonitoring ? ( ) : ( { if (!options.length) return 'Must specify an index.'; const illegalCharacters = ILLEGAL_CHARACTERS.join(' '); - const pattern = options.map(({ label }) => label).join(''); + const pattern = options.map(({ value, label }) => value || label).join(''); if (!isIndexPatternQueryValid(pattern, ILLEGAL_CHARACTERS)) { return `One of your inputs contains invalid characters or spaces. Please omit: ${illegalCharacters}`; }