From 9ec31d0397d0a600c988327150912510b15208d1 Mon Sep 17 00:00:00 2001 From: Kevin Delemme Date: Wed, 19 Apr 2023 12:15:20 -0400 Subject: [PATCH] chore(slo): Improve active alerts badge (#155290) --- .../slo_active_alerts_badge.tsx | 13 +++++++------ .../hooks/slo/use_fetch_active_alerts.ts | 7 +++++++ .../slo_details/components/header_title.tsx | 2 +- .../slos/components/badges/slo_badges.tsx | 2 +- .../helpers/alerts_page_query_filter.test.ts | 18 ------------------ .../slos/helpers/alerts_page_query_filter.ts | 17 ----------------- 6 files changed, 16 insertions(+), 43 deletions(-) delete mode 100644 x-pack/plugins/observability/public/pages/slos/helpers/alerts_page_query_filter.test.ts delete mode 100644 x-pack/plugins/observability/public/pages/slos/helpers/alerts_page_query_filter.ts diff --git a/x-pack/plugins/observability/public/components/slo/slo_status_badge/slo_active_alerts_badge.tsx b/x-pack/plugins/observability/public/components/slo/slo_status_badge/slo_active_alerts_badge.tsx index 218f1c8bd84c3..4d5e826ab4129 100644 --- a/x-pack/plugins/observability/public/components/slo/slo_status_badge/slo_active_alerts_badge.tsx +++ b/x-pack/plugins/observability/public/components/slo/slo_status_badge/slo_active_alerts_badge.tsx @@ -8,17 +8,18 @@ import { EuiBadge, EuiFlexItem } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React from 'react'; +import { SLOWithSummaryResponse } from '@kbn/slo-schema'; + import { paths } from '../../../config/paths'; import { useKibana } from '../../../utils/kibana_react'; - import { ActiveAlerts } from '../../../hooks/slo/use_fetch_active_alerts'; -import { toAlertsPageQueryFilter } from '../../../pages/slos/helpers/alerts_page_query_filter'; export interface Props { activeAlerts?: ActiveAlerts; + slo: SLOWithSummaryResponse; } -export function SloActiveAlertsBadge({ activeAlerts }: Props) { +export function SloActiveAlertsBadge({ slo, activeAlerts }: Props) { const { application: { navigateToUrl }, http: { basePath }, @@ -27,9 +28,9 @@ export function SloActiveAlertsBadge({ activeAlerts }: Props) { const handleActiveAlertsClick = () => { if (activeAlerts) { navigateToUrl( - `${basePath.prepend(paths.observability.alerts)}?_a=${toAlertsPageQueryFilter( - activeAlerts - )}` + `${basePath.prepend(paths.observability.alerts)}?_a=(kuery:'slo.id:"${ + slo.id + }"',rangeFrom:now-15m,rangeTo:now,status:active)` ); } }; diff --git a/x-pack/plugins/observability/public/hooks/slo/use_fetch_active_alerts.ts b/x-pack/plugins/observability/public/hooks/slo/use_fetch_active_alerts.ts index 4e90e51060df0..b8dc07a00ab32 100644 --- a/x-pack/plugins/observability/public/hooks/slo/use_fetch_active_alerts.ts +++ b/x-pack/plugins/observability/public/hooks/slo/use_fetch_active_alerts.ts @@ -58,6 +58,13 @@ export function useFetchActiveAlerts({ sloIds = [] }: Params): UseFetchActiveAle query: { bool: { filter: [ + { + range: { + '@timestamp': { + gte: 'now-15m/m', + }, + }, + }, { term: { 'kibana.alert.rule.rule_type_id': 'slo.rules.burnRate', diff --git a/x-pack/plugins/observability/public/pages/slo_details/components/header_title.tsx b/x-pack/plugins/observability/public/pages/slo_details/components/header_title.tsx index 4ce439f290fe7..94e7bcc8acf2c 100644 --- a/x-pack/plugins/observability/public/pages/slo_details/components/header_title.tsx +++ b/x-pack/plugins/observability/public/pages/slo_details/components/header_title.tsx @@ -38,7 +38,7 @@ export function HeaderTitle(props: Props) { {slo.name} - + ); diff --git a/x-pack/plugins/observability/public/pages/slos/components/badges/slo_badges.tsx b/x-pack/plugins/observability/public/pages/slos/components/badges/slo_badges.tsx index 15d36f3525ed1..89d5eadf4d9ad 100644 --- a/x-pack/plugins/observability/public/pages/slos/components/badges/slo_badges.tsx +++ b/x-pack/plugins/observability/public/pages/slos/components/badges/slo_badges.tsx @@ -31,7 +31,7 @@ export function SloBadges({ activeAlerts, rules, slo, onClickRuleBadge }: Props) - + ); diff --git a/x-pack/plugins/observability/public/pages/slos/helpers/alerts_page_query_filter.test.ts b/x-pack/plugins/observability/public/pages/slos/helpers/alerts_page_query_filter.test.ts deleted file mode 100644 index 956f5e087b6cf..0000000000000 --- a/x-pack/plugins/observability/public/pages/slos/helpers/alerts_page_query_filter.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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 { toAlertsPageQueryFilter } from './alerts_page_query_filter'; - -describe('AlertsPageQueryFilter', () => { - it('computes the query filter correctly', async () => { - expect( - toAlertsPageQueryFilter({ count: 2, ruleIds: ['rule-1', 'rule-2'] }) - ).toMatchInlineSnapshot( - `"(kuery:'kibana.alert.rule.uuid:\\"rule-1\\" or kibana.alert.rule.uuid:\\"rule-2\\"',rangeFrom:now-15m,rangeTo:now,status:all)"` - ); - }); -}); diff --git a/x-pack/plugins/observability/public/pages/slos/helpers/alerts_page_query_filter.ts b/x-pack/plugins/observability/public/pages/slos/helpers/alerts_page_query_filter.ts deleted file mode 100644 index 3fa407fab1bd8..0000000000000 --- a/x-pack/plugins/observability/public/pages/slos/helpers/alerts_page_query_filter.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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 { ActiveAlerts } from '../../../hooks/slo/use_fetch_active_alerts'; - -export function toAlertsPageQueryFilter(activeAlerts: ActiveAlerts): string { - const kuery = activeAlerts.ruleIds - .map((ruleId) => `kibana.alert.rule.uuid:"${ruleId}"`) - .join(' or '); - - const query = `(kuery:'${kuery}',rangeFrom:now-15m,rangeTo:now,status:all)`; - return query; -}