From c304b34e0edd90dedcb67dff10da6472d4a823c0 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Fri, 13 Sep 2024 11:10:15 +0200 Subject: [PATCH] [Metric threshold] Fix the condition not showing up in the metric threshold flyout (#192736) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #192439 ## Summary This PR reverts this [line](https://github.com/elastic/kibana/pull/191948/files#diff-2dd82a791bba3d995e9e6b35d4a973053f166351cc6025a5cd1d24dc789766aeR48) in a previous [PR](https://github.com/elastic/kibana/pull/191948) that caused an issue in loading the metric threshold flyout on the observability alerts page. | Before ❌ | After ✅ | |---|---| |![Image](https://github.com/user-attachments/assets/3c0b8812-8cd9-4769-bd20-ab10f559009b)|![Image](https://github.com/user-attachments/assets/9823e691-ce18-4c00-8748-ce5797a19943)| I also added a small test that fails before this fix. --- .../components/expression_row.tsx | 2 +- .../containers/metrics_source/source.tsx | 2 +- .../observability/alerts/rules_page.ts | 15 ++++++++ .../apps/observability/index.ts | 1 + .../pages/alerts/metric_threshold.ts | 38 +++++++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 x-pack/test/observability_functional/apps/observability/pages/alerts/metric_threshold.ts diff --git a/x-pack/plugins/observability_solution/infra/public/alerting/metric_threshold/components/expression_row.tsx b/x-pack/plugins/observability_solution/infra/public/alerting/metric_threshold/components/expression_row.tsx index 48371bebb2569..8aeb7e19402fb 100644 --- a/x-pack/plugins/observability_solution/infra/public/alerting/metric_threshold/components/expression_row.tsx +++ b/x-pack/plugins/observability_solution/infra/public/alerting/metric_threshold/components/expression_row.tsx @@ -200,7 +200,7 @@ export const ExpressionRow = ({ return ( <> - + { method: 'GET', } ); - telemetry.reportPerformanceMetricEvent( + telemetry?.reportPerformanceMetricEvent( 'infra_source_load', performance.now() - start, {}, diff --git a/x-pack/test/functional/services/observability/alerts/rules_page.ts b/x-pack/test/functional/services/observability/alerts/rules_page.ts index 226d257ed918b..76f700f99b999 100644 --- a/x-pack/test/functional/services/observability/alerts/rules_page.ts +++ b/x-pack/test/functional/services/observability/alerts/rules_page.ts @@ -6,6 +6,8 @@ */ import { FtrProviderContext } from '../../../ftr_provider_context'; +const METRIC_THRESHOLD_RULE_TYPE_SELECTOR = 'metrics.alert.threshold-SelectOption'; + export function ObservabilityAlertsRulesProvider({ getService }: FtrProviderContext) { const testSubjects = getService('testSubjects'); const find = getService('find'); @@ -30,6 +32,17 @@ export function ObservabilityAlertsRulesProvider({ getService }: FtrProviderCont await find.clickByButtonText('metric-threshold'); }; + const clickOnInfrastructureCategory = async () => { + const categories = await testSubjects.find('ruleTypeModal'); + const category = await categories.findByCssSelector(`.euiFacetButton[title="Infrastructure"]`); + await category.click(); + }; + + const clickOnMetricThresholdRule = async () => { + await testSubjects.existOrFail(METRIC_THRESHOLD_RULE_TYPE_SELECTOR); + await testSubjects.click(METRIC_THRESHOLD_RULE_TYPE_SELECTOR); + }; + return { getManageRulesPageHref, clickCreateRuleButton, @@ -37,5 +50,7 @@ export function ObservabilityAlertsRulesProvider({ getService }: FtrProviderCont clickDisableFromDropDownMenu, clickLogsTab, clickOnRuleInEventLogs, + clickOnInfrastructureCategory, + clickOnMetricThresholdRule, }; } diff --git a/x-pack/test/observability_functional/apps/observability/index.ts b/x-pack/test/observability_functional/apps/observability/index.ts index 67c00ef846a2c..64636e79123d7 100644 --- a/x-pack/test/observability_functional/apps/observability/index.ts +++ b/x-pack/test/observability_functional/apps/observability/index.ts @@ -24,5 +24,6 @@ export default function ({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./pages/rules_page')); loadTestFile(require.resolve('./pages/rule_details_page')); loadTestFile(require.resolve('./pages/alert_details_page')); + loadTestFile(require.resolve('./pages/alerts/metric_threshold')); }); } diff --git a/x-pack/test/observability_functional/apps/observability/pages/alerts/metric_threshold.ts b/x-pack/test/observability_functional/apps/observability/pages/alerts/metric_threshold.ts new file mode 100644 index 0000000000000..e474314b72178 --- /dev/null +++ b/x-pack/test/observability_functional/apps/observability/pages/alerts/metric_threshold.ts @@ -0,0 +1,38 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default ({ getService }: FtrProviderContext) => { + const esArchiver = getService('esArchiver'); + const testSubjects = getService('testSubjects'); + + describe('Metric threshold rule', function () { + this.tags('includeFirefox'); + + const observability = getService('observability'); + + before(async () => { + await esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs'); + await observability.alerts.common.navigateToRulesPage(); + }); + + after(async () => { + await esArchiver.unload('x-pack/test/functional/es_archives/infra/metrics_and_logs'); + }); + + it('shows the metric threshold rule in the observability section', async () => { + await observability.alerts.rulesPage.clickCreateRuleButton(); + await observability.alerts.rulesPage.clickOnInfrastructureCategory(); + await observability.alerts.rulesPage.clickOnMetricThresholdRule(); + }); + + it('shows an expression row in the condition section', async () => { + await testSubjects.existOrFail('metricThresholdExpressionRow'); + }); + }); +};