From df3845d12e791d8fd7ed69ae8b8f496292f5289a Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Thu, 22 Dec 2022 16:31:42 +0100 Subject: [PATCH 01/44] WIP --- .../alert_details_app_section.tsx | 14 +++ .../latency_alerts_history_chart.tsx | 106 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx index 92cd229333062..f81eb996693c3 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx @@ -44,6 +44,7 @@ import { import { getAggsTypeFromRule } from './helpers'; import { filterNil } from '../../../shared/charts/latency_chart'; import { errorRateI18n } from '../../../shared/charts/failed_transaction_rate_chart'; +import { LatencyAlertsHistoryChart } from './latency_alerts_history_chart'; export function AlertDetailsAppSection({ rule, @@ -409,6 +410,19 @@ export function AlertDetailsAppSection({ + + + + + diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx new file mode 100644 index 0000000000000..ff75aa77ce1ab --- /dev/null +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -0,0 +1,106 @@ +/* + * 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 React, { useMemo } from 'react'; +import moment from 'moment'; +import { getDurationFormatter } from '../../../../../common/utils/formatters'; +import { getLatencyChartSelector } from '../../../../selectors/latency_chart_selectors'; +import { LatencyAggregationType } from '../../../../../common/latency_aggregation_types'; +import { useFetcher } from '../../../../hooks/use_fetcher'; +import { TimeseriesChart } from '../../../shared/charts/timeseries_chart'; +import { filterNil } from '../../../shared/charts/latency_chart'; +import { + getMaxY, + getResponseTimeTickFormatter, +} from '../../../shared/charts/transaction_charts/helper'; + +interface LatencyAlertsHistoryChartProps { + serviceName: string; + start: string; + end: string; + transactionType?: string; + latencyAggregationType: LatencyAggregationType; + environment: string; + timeZone: string; +} +export function LatencyAlertsHistoryChart({ + serviceName, + start, + end, + transactionType, + latencyAggregationType, + environment, + timeZone, +}: LatencyAlertsHistoryChartProps) { + console.log(moment().toISOString()); + console.log(moment().subtract(30, 'days').toISOString()); + const { data, status } = useFetcher( + (callApmApi) => { + if ( + serviceName && + start && + end && + transactionType && + latencyAggregationType + ) { + return callApmApi( + `GET /internal/apm/services/{serviceName}/transactions/charts/latency`, + { + params: { + path: { serviceName }, + query: { + environment, + kuery: '', + start: moment().toISOString(), + end: moment().subtract(30, 'days').toISOString(), + transactionType, + transactionName: undefined, + latencyAggregationType, + }, + }, + } + ); + } + }, + [ + end, + environment, + latencyAggregationType, + serviceName, + start, + transactionType, + ] + ); + const memoizedData = useMemo( + () => + getLatencyChartSelector({ + latencyChart: data, + latencyAggregationType, + previousPeriodLabel: '', + }), + // It should only update when the data has changed + // eslint-disable-next-line react-hooks/exhaustive-deps + [data] + ); + const { currentPeriod, previousPeriod } = memoizedData; + const timeseriesLatency = [currentPeriod, previousPeriod].filter(filterNil); + const latencyMaxY = getMaxY(timeseriesLatency); + const latencyFormatter = getDurationFormatter(latencyMaxY); + + return ( + + ); +} From 14f0479151d464fad193f5f2f0dd0721cc12cea8 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Fri, 23 Dec 2022 14:47:39 +0100 Subject: [PATCH 02/44] Add the alert triggered and the avg time to recover --- .../alert_details_app_section.tsx | 24 +++-- .../latency_alerts_history_chart.tsx | 98 ++++++++++++++++--- 2 files changed, 95 insertions(+), 27 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx index f81eb996693c3..1ea5adcbe4edd 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx @@ -410,19 +410,17 @@ export function AlertDetailsAppSection({ - - - - - + + + diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index ff75aa77ce1ab..b9c83cf041fcc 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -7,6 +7,12 @@ import React, { useMemo } from 'react'; import moment from 'moment'; +import { EuiPanel, EuiSpacer } from '@elastic/eui'; +import { EuiFlexGroup } from '@elastic/eui'; +import { EuiFlexItem } from '@elastic/eui'; +import { EuiTitle } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { EuiText } from '@elastic/eui'; import { getDurationFormatter } from '../../../../../common/utils/formatters'; import { getLatencyChartSelector } from '../../../../selectors/latency_chart_selectors'; import { LatencyAggregationType } from '../../../../../common/latency_aggregation_types'; @@ -36,8 +42,6 @@ export function LatencyAlertsHistoryChart({ environment, timeZone, }: LatencyAlertsHistoryChartProps) { - console.log(moment().toISOString()); - console.log(moment().subtract(30, 'days').toISOString()); const { data, status } = useFetcher( (callApmApi) => { if ( @@ -55,8 +59,8 @@ export function LatencyAlertsHistoryChart({ query: { environment, kuery: '', - start: moment().toISOString(), - end: moment().subtract(30, 'days').toISOString(), + start: moment().subtract(30, 'days').toISOString(), + end: moment().toISOString(), transactionType, transactionName: undefined, latencyAggregationType, @@ -92,15 +96,81 @@ export function LatencyAlertsHistoryChart({ const latencyFormatter = getDurationFormatter(latencyMaxY); return ( - + + + + +

+ {i18n.translate('xpack.apm.latencyChartHistory.chartTitle', { + defaultMessage: 'Kibana latency alerts history', + })} +

+
+
+ + + {i18n.translate('xpack.apm.latencyChartHistory.last30days', { + defaultMessage: 'Last 30 days', + })} + + +
+ + + + + + + + +

28

+
+
+
+ + + {i18n.translate( + 'xpack.apm.latencyChartHistory.alertsTriggered', + { + defaultMessage: 'Alerts triggered', + } + )} + + +
+
+ + + + +

45 minutes

+
+
+
+ + + {i18n.translate( + 'xpack.apm.latencyChartHistory.avgTimeToRecover', + { + defaultMessage: 'Avg time to recover', + } + )} + + +
+
+ + + +
); } From 85f9fd22fbd98baaec85724a80efc9f61dbebdfd Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Tue, 27 Dec 2022 17:46:11 +0100 Subject: [PATCH 03/44] Add new hook to fetch triggered alert history --- .../use_fetch_triggered_alert_history.ts | 175 ++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts diff --git a/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts b/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts new file mode 100644 index 0000000000000..449afb498eae9 --- /dev/null +++ b/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts @@ -0,0 +1,175 @@ +/* + * 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 { AsApiContract } from '@kbn/actions-plugin/common'; +import { HttpSetup } from '@kbn/core/public'; +import { ALERT_RULE_UUID, ALERT_START, ALERT_TIME_RANGE } from '@kbn/rule-data-utils'; +import { BASE_RAC_ALERTS_API_PATH } from '@kbn/rule-registry-plugin/common'; +import { useCallback, useEffect, useRef, useState } from 'react'; +import { useKibana } from '../utils/kibana_react'; + +interface UseFetchTriggeredAlertsHistoryProps { + features: string; + ruleId: string; +} +interface FetchTriggeredAlertsHistory { + totalTriggeredAlerts: number; + histogramTriggeredAlerts: Array<{ + key_as_string: string; + key: number; + doc_count: number; + }>; + error?: string; +} + +interface TriggeredAlertsHistory { + isLoadingTriggeredAlertHistory: boolean; + errorTriggeredAlertHistory?: string; + data?: FetchTriggeredAlertsHistory; +} +export function useFetchTriggeredAlertsHistory({ + features, + ruleId, +}: UseFetchTriggeredAlertsHistoryProps) { + const { http } = useKibana().services; + const [triggeredAlertsHistory, setTriggeredAlertsHistory] = useState({ + isLoadingTriggeredAlertHistory: true, + }); + const isCancelledRef = useRef(false); + const abortCtrlRef = useRef(new AbortController()); + const loadRuleAlertsAgg = useCallback(async () => { + isCancelledRef.current = false; + abortCtrlRef.current.abort(); + abortCtrlRef.current = new AbortController(); + + try { + if (!features) return; + const { index } = await fetchIndexNameAPI({ + http, + features, + }); + + const { totalTriggeredAlerts, histogramTriggeredAlerts, error } = + await fetchTriggeredAlertsHistory({ + http, + index, + ruleId, + signal: abortCtrlRef.current.signal, + }); + + if (error) throw error; + if (!isCancelledRef.current) { + setTriggeredAlertsHistory((oldState: TriggeredAlertsHistory) => ({ + ...oldState, + data: { totalTriggeredAlerts, histogramTriggeredAlerts }, + isLoadingRuleAlertsAggs: false, + })); + } + } catch (error) { + if (!isCancelledRef.current) { + if (error.name !== 'AbortError') { + setTriggeredAlertsHistory((oldState: TriggeredAlertsHistory) => ({ + ...oldState, + isLoadingRuleAlertsAggs: false, + errorTriggeredAlertHistory: error, + data: undefined, + })); + } + } + } + }, [features, http, ruleId]); + useEffect(() => { + loadRuleAlertsAgg(); + }, [loadRuleAlertsAgg]); + + return triggeredAlertsHistory; +} + +interface IndexName { + index: string; +} + +export async function fetchIndexNameAPI({ + http, + features, +}: { + http: HttpSetup; + features: string; +}): Promise { + const res = await http.get<{ index_name: string[] }>(`${BASE_RAC_ALERTS_API_PATH}/index`, { + query: { features }, + }); + return { + index: res.index_name[0], + }; +} + +export async function fetchTriggeredAlertsHistory({ + http, + index, + ruleId, + signal, +}: { + http: HttpSetup; + index: string; + ruleId: string; + signal: AbortSignal; +}): Promise { + try { + const res = await http.post>(`${BASE_RAC_ALERTS_API_PATH}/find`, { + signal, + body: JSON.stringify({ + index, + size: 0, + query: { + bool: { + must: [ + { + term: { + [ALERT_RULE_UUID]: ruleId, + }, + }, + { + range: { + [ALERT_TIME_RANGE]: { + gte: 'now-30d', + lt: 'now', + }, + }, + }, + ], + }, + }, + aggs: { + histogramTriggeredAlerts: { + date_histogram: { + field: ALERT_START, + fixed_interval: '1d', + extended_bounds: { + min: 'now-30d', + max: 'now', + }, + }, + }, + }, + }), + }); + const totalTriggeredAlerts = res?.hits.total.value; + const histogramTriggeredAlerts = res?.aggregations?.histogramTriggeredAlerts.buckets; + return { + totalTriggeredAlerts, + histogramTriggeredAlerts, + }; + } catch (error) { + console.error(error); + return { + error, + totalTriggeredAlerts: 0, + histogramTriggeredAlerts: [], + }; + } +} From a5cdacde6a84a0345f78458b6f319c3a09fcb6c2 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Wed, 28 Dec 2022 15:25:29 +0100 Subject: [PATCH 04/44] import the new hook and use it --- .../alert_details_app_section.tsx | 7 ++++++- .../latency_alerts_history_chart.tsx | 10 ++++++++-- .../public/hooks/use_fetch_triggered_alert_history.ts | 6 +++--- x-pack/plugins/observability/public/index.ts | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx index 1ea5adcbe4edd..49d867de8a5ce 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx @@ -12,7 +12,11 @@ import { i18n } from '@kbn/i18n'; import { EuiPanel } from '@elastic/eui'; import { EuiTitle } from '@elastic/eui'; import { EuiIconTip } from '@elastic/eui'; -import { ALERT_DURATION, ALERT_END } from '@kbn/rule-data-utils'; +import { + ALERT_DURATION, + ALERT_END, + ALERT_RULE_UUID, +} from '@kbn/rule-data-utils'; import moment from 'moment'; import { ENVIRONMENT_ALL } from '../../../../../common/environment_filter_values'; import { getTransactionType } from '../../../../context/apm_service/apm_service_context'; @@ -413,6 +417,7 @@ export function AlertDetailsAppSection({ { @@ -94,7 +97,10 @@ export function LatencyAlertsHistoryChart({ const timeseriesLatency = [currentPeriod, previousPeriod].filter(filterNil); const latencyMaxY = getMaxY(timeseriesLatency); const latencyFormatter = getDurationFormatter(latencyMaxY); - + const { triggeredAlertsData } = useFetchTriggeredAlertsHistory({ + features: 'apm', + ruleId, + }); return ( @@ -123,7 +129,7 @@ export function LatencyAlertsHistoryChart({ -

28

+

{triggeredAlertsData?.totalTriggeredAlerts}

diff --git a/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts b/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts index 449afb498eae9..2131294fd2e6e 100644 --- a/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts +++ b/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts @@ -29,7 +29,7 @@ interface FetchTriggeredAlertsHistory { interface TriggeredAlertsHistory { isLoadingTriggeredAlertHistory: boolean; errorTriggeredAlertHistory?: string; - data?: FetchTriggeredAlertsHistory; + triggeredAlertsData?: FetchTriggeredAlertsHistory; } export function useFetchTriggeredAlertsHistory({ features, @@ -65,7 +65,7 @@ export function useFetchTriggeredAlertsHistory({ if (!isCancelledRef.current) { setTriggeredAlertsHistory((oldState: TriggeredAlertsHistory) => ({ ...oldState, - data: { totalTriggeredAlerts, histogramTriggeredAlerts }, + triggeredAlertsData: { totalTriggeredAlerts, histogramTriggeredAlerts }, isLoadingRuleAlertsAggs: false, })); } @@ -76,7 +76,7 @@ export function useFetchTriggeredAlertsHistory({ ...oldState, isLoadingRuleAlertsAggs: false, errorTriggeredAlertHistory: error, - data: undefined, + triggeredAlertsData: undefined, })); } } diff --git a/x-pack/plugins/observability/public/index.ts b/x-pack/plugins/observability/public/index.ts index 62f980bfc9d32..a73dfe25bdc2f 100644 --- a/x-pack/plugins/observability/public/index.ts +++ b/x-pack/plugins/observability/public/index.ts @@ -121,3 +121,4 @@ export { ExploratoryViewContextProvider } from './components/shared/exploratory_ export { fromQuery, toQuery } from './utils/url'; export type { NavigationSection } from './services/navigation_registry'; +export { useFetchTriggeredAlertsHistory } from './hooks/use_fetch_triggered_alert_history'; From 9e3bfd1fec153da31452ad5512cdbb0a88ff20b2 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 10 Jan 2023 08:27:26 +0000 Subject: [PATCH 05/44] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- x-pack/plugins/observability/tsconfig.json | 1 + .../security_solution/public/management/cypress/tsconfig.json | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/observability/tsconfig.json b/x-pack/plugins/observability/tsconfig.json index dbb01d971f9a3..2a548202e0f54 100644 --- a/x-pack/plugins/observability/tsconfig.json +++ b/x-pack/plugins/observability/tsconfig.json @@ -68,6 +68,7 @@ "@kbn/core-notifications-browser", "@kbn/slo-schema", "@kbn/core-http-server-internal", + "@kbn/actions-plugin", ], "exclude": [ "target/**/*", diff --git a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json index af09fee04643f..a99e4af76fe2e 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json +++ b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json @@ -22,6 +22,8 @@ "path": "../../../tsconfig.json", "force": true }, - "@kbn/security-plugin" + "@kbn/security-plugin", + "@kbn/securitysolution-list-constants", + "@kbn/fleet-plugin" ] } From 5fef281feb283e647de73f9cd5ba30006325c69a Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Tue, 10 Jan 2023 11:46:09 +0100 Subject: [PATCH 06/44] github issue --- .../public/management/cypress/tsconfig.json | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json index a99e4af76fe2e..b800a68eae269 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json +++ b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json @@ -1,18 +1,10 @@ { "extends": "../../../../../../tsconfig.base.json", - "include": [ - "**/*" - ], - "exclude": [ - "target/**/*" - ], + "include": ["**/*"], + "exclude": ["target/**/*"], "compilerOptions": { "outDir": "target/types", - "types": [ - "cypress", - "node", - "cypress-react-selector" - ], + "types": ["cypress", "node", "cypress-react-selector"] }, "kbn_references": [ // this cypress project uses code from the parent ts project @@ -22,8 +14,6 @@ "path": "../../../tsconfig.json", "force": true }, - "@kbn/security-plugin", - "@kbn/securitysolution-list-constants", - "@kbn/fleet-plugin" + "@kbn/security-plugin" ] } From 974239a622f33426de3adb6d2e5d5420a09c47b2 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Tue, 10 Jan 2023 11:48:55 +0100 Subject: [PATCH 07/44] github --- x-pack/plugins/observability/tsconfig.json | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/observability/tsconfig.json b/x-pack/plugins/observability/tsconfig.json index 2a548202e0f54..1c230e77fa9bb 100644 --- a/x-pack/plugins/observability/tsconfig.json +++ b/x-pack/plugins/observability/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../../tsconfig.base.json", "compilerOptions": { - "outDir": "target/types", + "outDir": "target/types" }, "include": [ "common/**/*", @@ -9,7 +9,7 @@ "public/**/*.json", "server/**/*", "typings/**/*", - "../../../typings/**/*", + "../../../typings/**/*" ], "kbn_references": [ "@kbn/core", @@ -67,10 +67,7 @@ "@kbn/share-plugin", "@kbn/core-notifications-browser", "@kbn/slo-schema", - "@kbn/core-http-server-internal", - "@kbn/actions-plugin", + "@kbn/core-http-server-internal" ], - "exclude": [ - "target/**/*", - ] + "exclude": ["target/**/*"] } From 7f069c8aa9ef68582028d8c398ab08d602943922 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Tue, 10 Jan 2023 11:53:55 +0100 Subject: [PATCH 08/44] fix format --- x-pack/plugins/observability/tsconfig.json | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/observability/tsconfig.json b/x-pack/plugins/observability/tsconfig.json index 1c230e77fa9bb..2a548202e0f54 100644 --- a/x-pack/plugins/observability/tsconfig.json +++ b/x-pack/plugins/observability/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../../tsconfig.base.json", "compilerOptions": { - "outDir": "target/types" + "outDir": "target/types", }, "include": [ "common/**/*", @@ -9,7 +9,7 @@ "public/**/*.json", "server/**/*", "typings/**/*", - "../../../typings/**/*" + "../../../typings/**/*", ], "kbn_references": [ "@kbn/core", @@ -67,7 +67,10 @@ "@kbn/share-plugin", "@kbn/core-notifications-browser", "@kbn/slo-schema", - "@kbn/core-http-server-internal" + "@kbn/core-http-server-internal", + "@kbn/actions-plugin", ], - "exclude": ["target/**/*"] + "exclude": [ + "target/**/*", + ] } From 6d8c450e5dff9b8e5c18da4ebe5ee08b6bec54ea Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Tue, 10 Jan 2023 11:54:56 +0100 Subject: [PATCH 09/44] fix format --- x-pack/plugins/observability/tsconfig.json | 1 - .../public/management/cypress/tsconfig.json | 14 +++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/observability/tsconfig.json b/x-pack/plugins/observability/tsconfig.json index 2a548202e0f54..dbb01d971f9a3 100644 --- a/x-pack/plugins/observability/tsconfig.json +++ b/x-pack/plugins/observability/tsconfig.json @@ -68,7 +68,6 @@ "@kbn/core-notifications-browser", "@kbn/slo-schema", "@kbn/core-http-server-internal", - "@kbn/actions-plugin", ], "exclude": [ "target/**/*", diff --git a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json index b800a68eae269..af09fee04643f 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json +++ b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json @@ -1,10 +1,18 @@ { "extends": "../../../../../../tsconfig.base.json", - "include": ["**/*"], - "exclude": ["target/**/*"], + "include": [ + "**/*" + ], + "exclude": [ + "target/**/*" + ], "compilerOptions": { "outDir": "target/types", - "types": ["cypress", "node", "cypress-react-selector"] + "types": [ + "cypress", + "node", + "cypress-react-selector" + ], }, "kbn_references": [ // this cypress project uses code from the parent ts project From af617d46cf04a3be6096e5ca48dfa68fe2c7a084 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 10 Jan 2023 11:02:12 +0000 Subject: [PATCH 10/44] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- x-pack/plugins/observability/tsconfig.json | 1 + .../security_solution/public/management/cypress/tsconfig.json | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/observability/tsconfig.json b/x-pack/plugins/observability/tsconfig.json index dbb01d971f9a3..2a548202e0f54 100644 --- a/x-pack/plugins/observability/tsconfig.json +++ b/x-pack/plugins/observability/tsconfig.json @@ -68,6 +68,7 @@ "@kbn/core-notifications-browser", "@kbn/slo-schema", "@kbn/core-http-server-internal", + "@kbn/actions-plugin", ], "exclude": [ "target/**/*", diff --git a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json index af09fee04643f..a99e4af76fe2e 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json +++ b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json @@ -22,6 +22,8 @@ "path": "../../../tsconfig.json", "force": true }, - "@kbn/security-plugin" + "@kbn/security-plugin", + "@kbn/securitysolution-list-constants", + "@kbn/fleet-plugin" ] } From 9cd497796098aa1a08a9bfbe6eb518074096fdfd Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Wed, 11 Jan 2023 15:34:51 +0100 Subject: [PATCH 11/44] Add annotation --- .../latency_alerts_history_chart.tsx | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 4c05b855e8fb0..5fe0711b75591 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -14,6 +14,13 @@ import { EuiTitle } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { EuiText } from '@elastic/eui'; import { useFetchTriggeredAlertsHistory } from '@kbn/observability-plugin/public'; +import { + AnnotationDomainType, + LineAnnotation, + Position, +} from '@elastic/charts'; +import { EuiIcon } from '@elastic/eui'; +import { EuiBadge } from '@elastic/eui'; import { getDurationFormatter } from '../../../../../common/utils/formatters'; import { getLatencyChartSelector } from '../../../../selectors/latency_chart_selectors'; import { LatencyAggregationType } from '../../../../../common/latency_aggregation_types'; @@ -101,6 +108,7 @@ export function LatencyAlertsHistoryChart({ features: 'apm', ruleId, }); + console.log(triggeredAlertsData); return ( @@ -166,9 +174,32 @@ export function LatencyAlertsHistoryChart({
+ annotation.doc_count > 0) + .map((annotation) => { + return { + dataValue: annotation.key, + header: String(annotation.doc_count), + details: String(annotation.doc_count), + }; + }) || [] + } + style={{ + line: { strokeWidth: 3, stroke: 'red', opacity: 1 }, + }} + marker={} + markerPosition={Position.Top} + />, + ]} height={200} comparisonEnabled={false} offset={''} From 1f29c837eb5eb1e4645a9ad5e15ff165f36dec80 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 11 Jan 2023 14:39:47 +0000 Subject: [PATCH 12/44] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../alert_details_app_section/latency_alerts_history_chart.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 5fe0711b75591..e892737636fca 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -20,7 +20,6 @@ import { Position, } from '@elastic/charts'; import { EuiIcon } from '@elastic/eui'; -import { EuiBadge } from '@elastic/eui'; import { getDurationFormatter } from '../../../../../common/utils/formatters'; import { getLatencyChartSelector } from '../../../../selectors/latency_chart_selectors'; import { LatencyAggregationType } from '../../../../../common/latency_aggregation_types'; From 918fa237d66a9f122bcca4bfd95990fe6da8b4cb Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Thu, 12 Jan 2023 11:33:19 +0100 Subject: [PATCH 13/44] Working annotation with alert number on the top of the marker --- .../latency_alerts_history_chart.tsx | 23 ++++++++++++------- .../public/hooks/use_chart_theme.tsx | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index e892737636fca..a32438560864a 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -31,6 +31,12 @@ import { getResponseTimeTickFormatter, } from '../../../shared/charts/transaction_charts/helper'; +const i18nAlertsTriggered = i18n.translate( + 'xpack.apm.latencyChartHistory.alertsTriggered', + { + defaultMessage: 'Alerts triggered', + } +); interface LatencyAlertsHistoryChartProps { serviceName: string; start: string; @@ -142,12 +148,7 @@ export function LatencyAlertsHistoryChart({
- {i18n.translate( - 'xpack.apm.latencyChartHistory.alertsTriggered', - { - defaultMessage: 'Alerts triggered', - } - )} + {i18nAlertsTriggered} @@ -173,7 +174,6 @@ export function LatencyAlertsHistoryChart({ - } + markerBody={(data) => ( + + + {data.header} + + + )} markerPosition={Position.Top} />, ]} diff --git a/x-pack/plugins/observability/public/hooks/use_chart_theme.tsx b/x-pack/plugins/observability/public/hooks/use_chart_theme.tsx index 6b11566b6e5a7..87e9e61036a71 100644 --- a/x-pack/plugins/observability/public/hooks/use_chart_theme.tsx +++ b/x-pack/plugins/observability/public/hooks/use_chart_theme.tsx @@ -22,7 +22,7 @@ export function useChartTheme(): PartialTheme[] { chartMargins: { left: 10, right: 10, - top: 10, + top: 35, bottom: 10, }, background: { From 24e586fb5079a8976b1db1eb722121256f4ae064 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Thu, 12 Jan 2023 11:34:02 +0100 Subject: [PATCH 14/44] Fix import --- .../alert_details_app_section/latency_alerts_history_chart.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index a32438560864a..1ff5c0ff6c940 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -20,6 +20,7 @@ import { Position, } from '@elastic/charts'; import { EuiIcon } from '@elastic/eui'; +import { EuiBadge } from '@elastic/eui'; import { getDurationFormatter } from '../../../../../common/utils/formatters'; import { getLatencyChartSelector } from '../../../../selectors/latency_chart_selectors'; import { LatencyAggregationType } from '../../../../../common/latency_aggregation_types'; From f759f2f5b1335546e48ddbe5180072fff57ca084 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Thu, 12 Jan 2023 11:39:38 +0100 Subject: [PATCH 15/44] Fix style --- .../latency_alerts_history_chart.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 1ff5c0ff6c940..3f061af46f2e6 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -198,11 +198,14 @@ export function LatencyAlertsHistoryChart({ }} marker={} markerBody={(data) => ( - - - {data.header} - - + <> + + + {data.header} + + + + )} markerPosition={Position.Top} />, From 2937e3109893f0f2383697735949a2417cf18609 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Thu, 12 Jan 2023 16:35:19 +0100 Subject: [PATCH 16/44] Add script to the query to calculate the avg recovered time --- .../latency_alerts_history_chart.tsx | 17 ++++++++++++++-- .../use_fetch_triggered_alert_history.ts | 20 +++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 3f061af46f2e6..4d33f647c99a4 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -106,6 +106,7 @@ export function LatencyAlertsHistoryChart({ // eslint-disable-next-line react-hooks/exhaustive-deps [data] ); + const { currentPeriod, previousPeriod } = memoizedData; const timeseriesLatency = [currentPeriod, previousPeriod].filter(filterNil); const latencyMaxY = getMaxY(timeseriesLatency); @@ -114,7 +115,15 @@ export function LatencyAlertsHistoryChart({ features: 'apm', ruleId, }); - console.log(triggeredAlertsData); + const getFormattedDuration = (avgTimeToRecover: number) => { + if (!avgTimeToRecover) return; + const time = moment.duration(avgTimeToRecover); + if (time.hours() > 0) { + return `${time.hours()}h ${time.minutes()}m`; + } else { + return `${time.minutes()}m ${time.seconds()}s`; + } + }; return ( @@ -158,7 +167,11 @@ export function LatencyAlertsHistoryChart({ -

45 minutes

+

+ {getFormattedDuration( + triggeredAlertsData?.avgTimeToRecoverMS || 0 + )} +

diff --git a/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts b/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts index 2131294fd2e6e..b760fda31ba32 100644 --- a/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts +++ b/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts @@ -24,6 +24,7 @@ interface FetchTriggeredAlertsHistory { doc_count: number; }>; error?: string; + avgTimeToRecoverMS: number; } interface TriggeredAlertsHistory { @@ -53,7 +54,7 @@ export function useFetchTriggeredAlertsHistory({ features, }); - const { totalTriggeredAlerts, histogramTriggeredAlerts, error } = + const { totalTriggeredAlerts, histogramTriggeredAlerts, error, avgTimeToRecoverMS } = await fetchTriggeredAlertsHistory({ http, index, @@ -65,7 +66,11 @@ export function useFetchTriggeredAlertsHistory({ if (!isCancelledRef.current) { setTriggeredAlertsHistory((oldState: TriggeredAlertsHistory) => ({ ...oldState, - triggeredAlertsData: { totalTriggeredAlerts, histogramTriggeredAlerts }, + triggeredAlertsData: { + totalTriggeredAlerts, + histogramTriggeredAlerts, + avgTimeToRecoverMS, + }, isLoadingRuleAlertsAggs: false, })); } @@ -155,14 +160,24 @@ export async function fetchTriggeredAlertsHistory({ }, }, }, + avgTimeToRecoverMS: { + avg: { + script: { + source: + "if (!doc['kibana.alert.end'].empty){return(doc['kibana.alert.end'].value.millis) - (doc['kibana.alert.start'].value.millis)}", + }, + }, + }, }, }), }); const totalTriggeredAlerts = res?.hits.total.value; const histogramTriggeredAlerts = res?.aggregations?.histogramTriggeredAlerts.buckets; + const avgTimeToRecoverMS = res?.aggregations?.avgTimeToRecoverMS.value; return { totalTriggeredAlerts, histogramTriggeredAlerts, + avgTimeToRecoverMS, }; } catch (error) { console.error(error); @@ -170,6 +185,7 @@ export async function fetchTriggeredAlertsHistory({ error, totalTriggeredAlerts: 0, histogramTriggeredAlerts: [], + avgTimeToRecoverMS: 0, }; } } From efc5ec0d7f23b8603153f08b7939507501d68c89 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Fri, 13 Jan 2023 16:54:43 +0100 Subject: [PATCH 17/44] Add date to the alert annotation --- .../latency_alerts_history_chart.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 4d33f647c99a4..2b7521a05fcb9 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -32,12 +32,6 @@ import { getResponseTimeTickFormatter, } from '../../../shared/charts/transaction_charts/helper'; -const i18nAlertsTriggered = i18n.translate( - 'xpack.apm.latencyChartHistory.alertsTriggered', - { - defaultMessage: 'Alerts triggered', - } -); interface LatencyAlertsHistoryChartProps { serviceName: string; start: string; @@ -158,7 +152,12 @@ export function LatencyAlertsHistoryChart({ - {i18nAlertsTriggered} + {i18n.translate( + 'xpack.apm.latencyChartHistory.alertsTriggered', + { + defaultMessage: 'Alerts triggered', + } + )}
@@ -199,10 +198,13 @@ export function LatencyAlertsHistoryChart({ triggeredAlertsData?.histogramTriggeredAlerts .filter((annotation) => annotation.doc_count > 0) .map((annotation) => { + console.log(annotation); return { dataValue: annotation.key, header: String(annotation.doc_count), - details: i18nAlertsTriggered, + details: moment(annotation.key_as_string).format( + 'yyyy-MM-DD' + ), }; }) || [] } From 727aeae2d881385b78a1f99d6e379c8ba8f16125 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Fri, 13 Jan 2023 16:56:27 +0100 Subject: [PATCH 18/44] DEL Logs --- .../alert_details_app_section/latency_alerts_history_chart.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 2b7521a05fcb9..025fc71fba072 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -198,7 +198,6 @@ export function LatencyAlertsHistoryChart({ triggeredAlertsData?.histogramTriggeredAlerts .filter((annotation) => annotation.doc_count > 0) .map((annotation) => { - console.log(annotation); return { dataValue: annotation.key, header: String(annotation.doc_count), From 30fc5348dfd86dd5fa5bec971394fb31e17fb568 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Fri, 13 Jan 2023 17:03:42 +0100 Subject: [PATCH 19/44] Add key to annotation --- .../alert_details_app_section/latency_alerts_history_chart.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 025fc71fba072..62164e2e137ef 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -193,6 +193,7 @@ export function LatencyAlertsHistoryChart({ annotations={[ Date: Fri, 13 Jan 2023 17:08:23 +0100 Subject: [PATCH 20/44] increase package limit --- packages/kbn-optimizer/limits.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index c1371edbd4068..a9a81d757222a 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -92,7 +92,7 @@ pageLoadAssetSize: monitoring: 80000 navigation: 37269 newsfeed: 42228 - observability: 95000 + observability: 107000 osquery: 107090 painlessLab: 179748 presentationUtil: 58834 From 1f40dab56121c4514a4cf57fcca07b0e815457c0 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Fri, 13 Jan 2023 17:11:16 +0100 Subject: [PATCH 21/44] fix --- x-pack/plugins/observability/tsconfig.json | 11 ++++------- .../public/management/cypress/tsconfig.json | 4 +--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/observability/tsconfig.json b/x-pack/plugins/observability/tsconfig.json index 2a548202e0f54..1c230e77fa9bb 100644 --- a/x-pack/plugins/observability/tsconfig.json +++ b/x-pack/plugins/observability/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../../tsconfig.base.json", "compilerOptions": { - "outDir": "target/types", + "outDir": "target/types" }, "include": [ "common/**/*", @@ -9,7 +9,7 @@ "public/**/*.json", "server/**/*", "typings/**/*", - "../../../typings/**/*", + "../../../typings/**/*" ], "kbn_references": [ "@kbn/core", @@ -67,10 +67,7 @@ "@kbn/share-plugin", "@kbn/core-notifications-browser", "@kbn/slo-schema", - "@kbn/core-http-server-internal", - "@kbn/actions-plugin", + "@kbn/core-http-server-internal" ], - "exclude": [ - "target/**/*", - ] + "exclude": ["target/**/*"] } diff --git a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json index a99e4af76fe2e..af09fee04643f 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json +++ b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json @@ -22,8 +22,6 @@ "path": "../../../tsconfig.json", "force": true }, - "@kbn/security-plugin", - "@kbn/securitysolution-list-constants", - "@kbn/fleet-plugin" + "@kbn/security-plugin" ] } From 24aa28d8be42af4c53158148b790bcbdba5a3ed7 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Fri, 13 Jan 2023 17:14:36 +0100 Subject: [PATCH 22/44] fix lint --- x-pack/plugins/observability/tsconfig.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/observability/tsconfig.json b/x-pack/plugins/observability/tsconfig.json index 1c230e77fa9bb..2847d0ea4b10b 100644 --- a/x-pack/plugins/observability/tsconfig.json +++ b/x-pack/plugins/observability/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../../tsconfig.base.json", "compilerOptions": { - "outDir": "target/types" + "outDir": "target/types", }, "include": [ "common/**/*", @@ -9,7 +9,7 @@ "public/**/*.json", "server/**/*", "typings/**/*", - "../../../typings/**/*" + "../../../typings/**/*", ], "kbn_references": [ "@kbn/core", @@ -69,5 +69,7 @@ "@kbn/slo-schema", "@kbn/core-http-server-internal" ], - "exclude": ["target/**/*"] + "exclude": [ + "target/**/*", + ] } From 731a954a77745d926d8ab9b43d93525a916f0570 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Fri, 13 Jan 2023 17:15:32 +0100 Subject: [PATCH 23/44] fix lint --- x-pack/plugins/observability/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/observability/tsconfig.json b/x-pack/plugins/observability/tsconfig.json index 2847d0ea4b10b..dbb01d971f9a3 100644 --- a/x-pack/plugins/observability/tsconfig.json +++ b/x-pack/plugins/observability/tsconfig.json @@ -67,7 +67,7 @@ "@kbn/share-plugin", "@kbn/core-notifications-browser", "@kbn/slo-schema", - "@kbn/core-http-server-internal" + "@kbn/core-http-server-internal", ], "exclude": [ "target/**/*", From e149baf738f20a3f91112be784d18d64f99547fb Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 13 Jan 2023 16:21:20 +0000 Subject: [PATCH 24/44] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- x-pack/plugins/observability/tsconfig.json | 1 + .../security_solution/public/management/cypress/tsconfig.json | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/observability/tsconfig.json b/x-pack/plugins/observability/tsconfig.json index dbb01d971f9a3..2a548202e0f54 100644 --- a/x-pack/plugins/observability/tsconfig.json +++ b/x-pack/plugins/observability/tsconfig.json @@ -68,6 +68,7 @@ "@kbn/core-notifications-browser", "@kbn/slo-schema", "@kbn/core-http-server-internal", + "@kbn/actions-plugin", ], "exclude": [ "target/**/*", diff --git a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json index af09fee04643f..a99e4af76fe2e 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json +++ b/x-pack/plugins/security_solution/public/management/cypress/tsconfig.json @@ -22,6 +22,8 @@ "path": "../../../tsconfig.json", "force": true }, - "@kbn/security-plugin" + "@kbn/security-plugin", + "@kbn/securitysolution-list-constants", + "@kbn/fleet-plugin" ] } From a9151544cbe6d92db6ae13d0ab030546b2080deb Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Fri, 13 Jan 2023 18:34:10 +0100 Subject: [PATCH 25/44] Update limit --- packages/kbn-optimizer/limits.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index a9a81d757222a..dfcef826bd3ed 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -92,7 +92,7 @@ pageLoadAssetSize: monitoring: 80000 navigation: 37269 newsfeed: 42228 - observability: 107000 + observability: 109000 osquery: 107090 painlessLab: 179748 presentationUtil: 58834 From a951d02afcd465765f899ff816a5b14ec51301c9 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Mon, 16 Jan 2023 12:02:32 +0100 Subject: [PATCH 26/44] Update limit --- packages/kbn-optimizer/limits.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index dfcef826bd3ed..31387bdc521d0 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -92,7 +92,7 @@ pageLoadAssetSize: monitoring: 80000 navigation: 37269 newsfeed: 42228 - observability: 109000 + observability: 110000 osquery: 107090 painlessLab: 179748 presentationUtil: 58834 From 3c81c91500f44ba67d3201f1cbbc0d2d0fbd8718 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Mon, 16 Jan 2023 15:27:55 +0100 Subject: [PATCH 27/44] code review - use transaction type from the alert --- .../alert_details_app_section.tsx | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx index bf4e10f7980e8..e946c051469f8 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx @@ -102,23 +102,7 @@ export function AlertDetailsAppSection({ .toISOString(); const { start, end } = useTimeRange({ rangeFrom, rangeTo }); - const { agentName } = useServiceAgentFetcher({ - serviceName, - start, - end, - }); - const transactionTypes = useServiceTransactionTypesFetcher({ - serviceName, - start, - end, - }); - - const transactionType = getTransactionType({ - transactionType: alert.fields[TRANSACTION_TYPE], - transactionTypes, - agentName, - }); - + const transactionType = alert.fields[TRANSACTION_TYPE]; const comparisonChartTheme = getComparisonChartTheme(); const INITIAL_STATE = { currentPeriod: [], From d6340eff2986f48098d783095fe74ed1bf58ad89 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Mon, 16 Jan 2023 15:32:21 +0100 Subject: [PATCH 28/44] use - when there is no value --- .../alert_details_app_section/latency_alerts_history_chart.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 62164e2e137ef..ff68eeba2e90c 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -110,7 +110,6 @@ export function LatencyAlertsHistoryChart({ ruleId, }); const getFormattedDuration = (avgTimeToRecover: number) => { - if (!avgTimeToRecover) return; const time = moment.duration(avgTimeToRecover); if (time.hours() > 0) { return `${time.hours()}h ${time.minutes()}m`; @@ -168,7 +167,7 @@ export function LatencyAlertsHistoryChart({

{getFormattedDuration( - triggeredAlertsData?.avgTimeToRecoverMS || 0 + triggeredAlertsData?.avgTimeToRecoverMS || - )}

From d88e5305286a8e7b4476bfcaf52f47333439180c Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 16 Jan 2023 15:04:24 +0000 Subject: [PATCH 29/44] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../alert_details_app_section/alert_details_app_section.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx index e946c051469f8..73690e8b0a00e 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/alert_details_app_section.tsx @@ -20,9 +20,6 @@ import { ALERT_RULE_TYPE_ID, } from '@kbn/rule-data-utils'; import moment from 'moment'; -import { getTransactionType } from '../../../../context/apm_service/apm_service_context'; -import { useServiceAgentFetcher } from '../../../../context/apm_service/use_service_agent_fetcher'; -import { useServiceTransactionTypesFetcher } from '../../../../context/apm_service/use_service_transaction_types_fetcher'; import { asPercent } from '../../../../../common/utils/formatters'; import { APIReturnType } from '../../../../services/rest/create_call_apm_api'; import { getDurationFormatter } from '../../../../../common/utils/formatters/duration'; From 6460159a8d9bfe8fa985172d94d4d458d92895c1 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Mon, 16 Jan 2023 17:20:43 +0100 Subject: [PATCH 30/44] fix formatting --- .../latency_alerts_history_chart.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index ff68eeba2e90c..499755830b81d 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -109,7 +109,8 @@ export function LatencyAlertsHistoryChart({ features: 'apm', ruleId, }); - const getFormattedDuration = (avgTimeToRecover: number) => { + const getFormattedDuration = (avgTimeToRecover?: number) => { + if (!avgTimeToRecover || avgTimeToRecover === 0) return '-'; const time = moment.duration(avgTimeToRecover); if (time.hours() > 0) { return `${time.hours()}h ${time.minutes()}m`; @@ -167,7 +168,7 @@ export function LatencyAlertsHistoryChart({

{getFormattedDuration( - triggeredAlertsData?.avgTimeToRecoverMS || - + triggeredAlertsData?.avgTimeToRecoverMS )}

From 09250d353c0450919dd4d3e6a7ea6689259ec4ec Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Mon, 16 Jan 2023 17:20:46 +0100 Subject: [PATCH 31/44] Updated bucketAggsSchemas to accept filter inside the aggs --- x-pack/plugins/rule_registry/common/types.ts | 84 +++++++++++--------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/x-pack/plugins/rule_registry/common/types.ts b/x-pack/plugins/rule_registry/common/types.ts index fd238b66c82bb..1bf454c8afab5 100644 --- a/x-pack/plugins/rule_registry/common/types.ts +++ b/x-pack/plugins/rule_registry/common/types.ts @@ -184,44 +184,6 @@ const bucketAggsTempsSchemas: t.Type = t.exact( ), }) ); - -export const bucketAggsSchemas = t.intersection([ - bucketAggsTempsSchemas, - t.partial({ - aggs: t.union([t.record(t.string, bucketAggsTempsSchemas), t.undefined]), - aggregations: t.union([t.record(t.string, bucketAggsTempsSchemas), t.undefined]), - }), -]); - -/** - * Schemas for the metrics Aggregations - * - * Currently supported: - * - avg - * - cardinality - * - min - * - max - * - sum - * - top_hits - * - weighted_avg - * - * Not implemented: - * - boxplot - * - extended_stats - * - geo_bounds - * - geo_centroid - * - geo_line - * - matrix_stats - * - median_absolute_deviation - * - percentile_ranks - * - percentiles - * - rate - * - scripted_metric - * - stats - * - string_stats - * - t_test - * - value_count - */ export const metricsAggsSchemas = t.exact( t.partial({ avg: t.exact( @@ -292,6 +254,52 @@ export const metricsAggsSchemas = t.exact( }) ); +export const bucketAggsSchemas = t.intersection([ + bucketAggsTempsSchemas, + t.partial({ + aggs: t.union([ + t.record(t.string, bucketAggsTempsSchemas), + t.record(t.string, metricsAggsSchemas), + t.undefined, + ]), + aggregations: t.union([ + t.record(t.string, bucketAggsTempsSchemas), + t.record(t.string, metricsAggsSchemas), + t.undefined, + ]), + }), +]); + +/** + * Schemas for the metrics Aggregations + * + * Currently supported: + * - avg + * - cardinality + * - min + * - max + * - sum + * - top_hits + * - weighted_avg + * + * Not implemented: + * - boxplot + * - extended_stats + * - geo_bounds + * - geo_centroid + * - geo_line + * - matrix_stats + * - median_absolute_deviation + * - percentile_ranks + * - percentiles + * - rate + * - scripted_metric + * - stats + * - string_stats + * - t_test + * - value_count + */ + export type PutIndexTemplateRequest = estypes.IndicesPutIndexTemplateRequest & { body?: { composed_of?: string[] }; }; From b24a0813d3868bea2cf31c29c0dc126ac1cb0b40 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Tue, 17 Jan 2023 12:20:31 +0100 Subject: [PATCH 32/44] update var name --- .../latency_alerts_history_chart.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 499755830b81d..888c944a5eedb 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -212,11 +212,11 @@ export function LatencyAlertsHistoryChart({ line: { strokeWidth: 3, stroke: 'red', opacity: 1 }, }} marker={} - markerBody={(data) => ( + markerBody={(annotationData) => ( <> - {data.header} + {annotationData.header} From d227c53b0d1b44590b3a90609168fe17fc28dac8 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Tue, 17 Jan 2023 12:21:01 +0100 Subject: [PATCH 33/44] update limit --- packages/kbn-optimizer/limits.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 31387bdc521d0..1734828971c78 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -92,7 +92,7 @@ pageLoadAssetSize: monitoring: 80000 navigation: 37269 newsfeed: 42228 - observability: 110000 + observability: 190000 osquery: 107090 painlessLab: 179748 presentationUtil: 58834 From 9989f4864a6dd38723dc8a3ef713004317ad7c27 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Tue, 17 Jan 2023 13:53:56 +0100 Subject: [PATCH 34/44] fix all errors and move the hook to apm --- packages/kbn-optimizer/limits.yml | 2 +- .../apm/common/utils/formatters/duration.ts | 2 +- .../latency_alerts_history_chart.tsx | 27 ++-- .../use_fetch_triggered_alert_history.ts | 123 ++++++++++-------- x-pack/plugins/observability/public/index.ts | 1 - 5 files changed, 90 insertions(+), 65 deletions(-) rename x-pack/plugins/{observability => apm}/public/hooks/use_fetch_triggered_alert_history.ts (64%) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 1734828971c78..c1371edbd4068 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -92,7 +92,7 @@ pageLoadAssetSize: monitoring: 80000 navigation: 37269 newsfeed: 42228 - observability: 190000 + observability: 95000 osquery: 107090 painlessLab: 179748 presentationUtil: 58834 diff --git a/x-pack/plugins/apm/common/utils/formatters/duration.ts b/x-pack/plugins/apm/common/utils/formatters/duration.ts index bf83ed2e093ea..a67242f7b0f3d 100644 --- a/x-pack/plugins/apm/common/utils/formatters/duration.ts +++ b/x-pack/plugins/apm/common/utils/formatters/duration.ts @@ -100,7 +100,7 @@ function getUnitLabelAndConvertedValue( /** * Converts a microseconds value into the unit defined. */ -function convertTo({ +export function convertTo({ unit, microseconds, defaultValue = NOT_AVAILABLE_LABEL, diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 888c944a5eedb..b4a9f1625263b 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -13,7 +13,7 @@ import { EuiFlexItem } from '@elastic/eui'; import { EuiTitle } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { EuiText } from '@elastic/eui'; -import { useFetchTriggeredAlertsHistory } from '@kbn/observability-plugin/public'; +// import { useFetchTriggeredAlertsHistory } from '@kbn/observability-plugin/public'; import { AnnotationDomainType, LineAnnotation, @@ -21,7 +21,11 @@ import { } from '@elastic/charts'; import { EuiIcon } from '@elastic/eui'; import { EuiBadge } from '@elastic/eui'; -import { getDurationFormatter } from '../../../../../common/utils/formatters'; +import { useFetchTriggeredAlertsHistory } from '../../../../hooks/use_fetch_triggered_alert_history'; +import { + convertTo, + getDurationFormatter, +} from '../../../../../common/utils/formatters'; import { getLatencyChartSelector } from '../../../../selectors/latency_chart_selectors'; import { LatencyAggregationType } from '../../../../../common/latency_aggregation_types'; import { useFetcher } from '../../../../hooks/use_fetcher'; @@ -111,12 +115,17 @@ export function LatencyAlertsHistoryChart({ }); const getFormattedDuration = (avgTimeToRecover?: number) => { if (!avgTimeToRecover || avgTimeToRecover === 0) return '-'; - const time = moment.duration(avgTimeToRecover); - if (time.hours() > 0) { - return `${time.hours()}h ${time.minutes()}m`; - } else { - return `${time.minutes()}m ${time.seconds()}s`; - } + const hours = convertTo({ + unit: 'hours', + microseconds: avgTimeToRecover * 1000, + }); + const minutes = convertTo({ + unit: 'minutes', + microseconds: avgTimeToRecover * 1000, + }); + + if (parseInt(minutes.value) > 60) return hours.formatted; + return minutes.formatted; }; return ( @@ -146,7 +155,7 @@ export function LatencyAlertsHistoryChart({ -

{triggeredAlertsData?.totalTriggeredAlerts}

+

{triggeredAlertsData?.totalTriggeredAlerts || '-'}

diff --git a/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts b/x-pack/plugins/apm/public/hooks/use_fetch_triggered_alert_history.ts similarity index 64% rename from x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts rename to x-pack/plugins/apm/public/hooks/use_fetch_triggered_alert_history.ts index b760fda31ba32..bc17451d9657f 100644 --- a/x-pack/plugins/observability/public/hooks/use_fetch_triggered_alert_history.ts +++ b/x-pack/plugins/apm/public/hooks/use_fetch_triggered_alert_history.ts @@ -7,10 +7,14 @@ import { AsApiContract } from '@kbn/actions-plugin/common'; import { HttpSetup } from '@kbn/core/public'; -import { ALERT_RULE_UUID, ALERT_START, ALERT_TIME_RANGE } from '@kbn/rule-data-utils'; +import { + ALERT_RULE_UUID, + ALERT_START, + ALERT_TIME_RANGE, +} from '@kbn/rule-data-utils'; import { BASE_RAC_ALERTS_API_PATH } from '@kbn/rule-registry-plugin/common'; import { useCallback, useEffect, useRef, useState } from 'react'; -import { useKibana } from '../utils/kibana_react'; +import { useKibana } from '@kbn/kibana-react-plugin/public'; interface UseFetchTriggeredAlertsHistoryProps { features: string; @@ -37,9 +41,10 @@ export function useFetchTriggeredAlertsHistory({ ruleId, }: UseFetchTriggeredAlertsHistoryProps) { const { http } = useKibana().services; - const [triggeredAlertsHistory, setTriggeredAlertsHistory] = useState({ - isLoadingTriggeredAlertHistory: true, - }); + const [triggeredAlertsHistory, setTriggeredAlertsHistory] = + useState({ + isLoadingTriggeredAlertHistory: true, + }); const isCancelledRef = useRef(false); const abortCtrlRef = useRef(new AbortController()); const loadRuleAlertsAgg = useCallback(async () => { @@ -48,19 +53,24 @@ export function useFetchTriggeredAlertsHistory({ abortCtrlRef.current = new AbortController(); try { + if (!http) throw 'No http client'; if (!features) return; const { index } = await fetchIndexNameAPI({ http, features, }); - const { totalTriggeredAlerts, histogramTriggeredAlerts, error, avgTimeToRecoverMS } = - await fetchTriggeredAlertsHistory({ - http, - index, - ruleId, - signal: abortCtrlRef.current.signal, - }); + const { + totalTriggeredAlerts, + histogramTriggeredAlerts, + error, + avgTimeToRecoverMS, + } = await fetchTriggeredAlertsHistory({ + http, + index, + ruleId, + signal: abortCtrlRef.current.signal, + }); if (error) throw error; if (!isCancelledRef.current) { @@ -105,9 +115,12 @@ export async function fetchIndexNameAPI({ http: HttpSetup; features: string; }): Promise { - const res = await http.get<{ index_name: string[] }>(`${BASE_RAC_ALERTS_API_PATH}/index`, { - query: { features }, - }); + const res = await http.get<{ index_name: string[] }>( + `${BASE_RAC_ALERTS_API_PATH}/index`, + { + query: { features }, + } + ); return { index: res.index_name[0], }; @@ -125,54 +138,58 @@ export async function fetchTriggeredAlertsHistory({ signal: AbortSignal; }): Promise { try { - const res = await http.post>(`${BASE_RAC_ALERTS_API_PATH}/find`, { - signal, - body: JSON.stringify({ - index, - size: 0, - query: { - bool: { - must: [ - { - term: { - [ALERT_RULE_UUID]: ruleId, + const res = await http.post>( + `${BASE_RAC_ALERTS_API_PATH}/find`, + { + signal, + body: JSON.stringify({ + index, + size: 0, + query: { + bool: { + must: [ + { + term: { + [ALERT_RULE_UUID]: ruleId, + }, }, - }, - { - range: { - [ALERT_TIME_RANGE]: { - gte: 'now-30d', - lt: 'now', + { + range: { + [ALERT_TIME_RANGE]: { + gte: 'now-30d', + lt: 'now', + }, }, }, - }, - ], + ], + }, }, - }, - aggs: { - histogramTriggeredAlerts: { - date_histogram: { - field: ALERT_START, - fixed_interval: '1d', - extended_bounds: { - min: 'now-30d', - max: 'now', + aggs: { + histogramTriggeredAlerts: { + date_histogram: { + field: ALERT_START, + fixed_interval: '1d', + extended_bounds: { + min: 'now-30d', + max: 'now', + }, }, }, - }, - avgTimeToRecoverMS: { - avg: { - script: { - source: - "if (!doc['kibana.alert.end'].empty){return(doc['kibana.alert.end'].value.millis) - (doc['kibana.alert.start'].value.millis)}", + avgTimeToRecoverMS: { + avg: { + script: { + source: + "if (!doc['kibana.alert.end'].empty){return(doc['kibana.alert.end'].value.millis) - (doc['kibana.alert.start'].value.millis)}", + }, }, }, }, - }, - }), - }); + }), + } + ); const totalTriggeredAlerts = res?.hits.total.value; - const histogramTriggeredAlerts = res?.aggregations?.histogramTriggeredAlerts.buckets; + const histogramTriggeredAlerts = + res?.aggregations?.histogramTriggeredAlerts.buckets; const avgTimeToRecoverMS = res?.aggregations?.avgTimeToRecoverMS.value; return { totalTriggeredAlerts, diff --git a/x-pack/plugins/observability/public/index.ts b/x-pack/plugins/observability/public/index.ts index a73dfe25bdc2f..62f980bfc9d32 100644 --- a/x-pack/plugins/observability/public/index.ts +++ b/x-pack/plugins/observability/public/index.ts @@ -121,4 +121,3 @@ export { ExploratoryViewContextProvider } from './components/shared/exploratory_ export { fromQuery, toQuery } from './utils/url'; export type { NavigationSection } from './services/navigation_registry'; -export { useFetchTriggeredAlertsHistory } from './hooks/use_fetch_triggered_alert_history'; From 8c913233b829d72544a0e95c0a1b94372e74d18d Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Tue, 17 Jan 2023 14:01:40 +0100 Subject: [PATCH 35/44] add radix --- .../alert_details_app_section/latency_alerts_history_chart.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index b4a9f1625263b..e8bdc72f60328 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -124,7 +124,7 @@ export function LatencyAlertsHistoryChart({ microseconds: avgTimeToRecover * 1000, }); - if (parseInt(minutes.value) > 60) return hours.formatted; + if (parseInt(minutes.value, 10) > 60) return hours.formatted; return minutes.formatted; }; return ( From cb631341253624e0cd11ccb47f35884e1c195c35 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Tue, 17 Jan 2023 14:02:45 +0100 Subject: [PATCH 36/44] fix lint --- .../apm/public/hooks/use_fetch_triggered_alert_history.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/apm/public/hooks/use_fetch_triggered_alert_history.ts b/x-pack/plugins/apm/public/hooks/use_fetch_triggered_alert_history.ts index bc17451d9657f..0b72b1fe63036 100644 --- a/x-pack/plugins/apm/public/hooks/use_fetch_triggered_alert_history.ts +++ b/x-pack/plugins/apm/public/hooks/use_fetch_triggered_alert_history.ts @@ -53,7 +53,7 @@ export function useFetchTriggeredAlertsHistory({ abortCtrlRef.current = new AbortController(); try { - if (!http) throw 'No http client'; + if (!http) throw new Error('No http client'); if (!features) return; const { index } = await fetchIndexNameAPI({ http, From 63712af6179efd53414b179b8e02d2a601c6979f Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 17 Jan 2023 13:08:27 +0000 Subject: [PATCH 37/44] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- x-pack/plugins/observability/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/observability/tsconfig.json b/x-pack/plugins/observability/tsconfig.json index 2a548202e0f54..dbb01d971f9a3 100644 --- a/x-pack/plugins/observability/tsconfig.json +++ b/x-pack/plugins/observability/tsconfig.json @@ -68,7 +68,6 @@ "@kbn/core-notifications-browser", "@kbn/slo-schema", "@kbn/core-http-server-internal", - "@kbn/actions-plugin", ], "exclude": [ "target/**/*", From d95a8f8bff8f2bcca10770dfb208fabf1228cbc8 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Tue, 17 Jan 2023 15:00:37 +0100 Subject: [PATCH 38/44] use duration formatter from observability --- .../apm/common/utils/formatters/duration.ts | 2 +- .../latency_alerts_history_chart.tsx | 30 +++++++------------ .../common/utils/formatters/duration.ts | 2 +- x-pack/plugins/observability/public/index.ts | 1 + 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/x-pack/plugins/apm/common/utils/formatters/duration.ts b/x-pack/plugins/apm/common/utils/formatters/duration.ts index a67242f7b0f3d..bf83ed2e093ea 100644 --- a/x-pack/plugins/apm/common/utils/formatters/duration.ts +++ b/x-pack/plugins/apm/common/utils/formatters/duration.ts @@ -100,7 +100,7 @@ function getUnitLabelAndConvertedValue( /** * Converts a microseconds value into the unit defined. */ -export function convertTo({ +function convertTo({ unit, microseconds, defaultValue = NOT_AVAILABLE_LABEL, diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index e8bdc72f60328..6b6a0c92964c8 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -21,11 +21,9 @@ import { } from '@elastic/charts'; import { EuiIcon } from '@elastic/eui'; import { EuiBadge } from '@elastic/eui'; +import { convertTo } from '@kbn/observability-plugin/public'; import { useFetchTriggeredAlertsHistory } from '../../../../hooks/use_fetch_triggered_alert_history'; -import { - convertTo, - getDurationFormatter, -} from '../../../../../common/utils/formatters'; +import { getDurationFormatter } from '../../../../../common/utils/formatters'; import { getLatencyChartSelector } from '../../../../selectors/latency_chart_selectors'; import { LatencyAggregationType } from '../../../../../common/latency_aggregation_types'; import { useFetcher } from '../../../../hooks/use_fetcher'; @@ -113,20 +111,7 @@ export function LatencyAlertsHistoryChart({ features: 'apm', ruleId, }); - const getFormattedDuration = (avgTimeToRecover?: number) => { - if (!avgTimeToRecover || avgTimeToRecover === 0) return '-'; - const hours = convertTo({ - unit: 'hours', - microseconds: avgTimeToRecover * 1000, - }); - const minutes = convertTo({ - unit: 'minutes', - microseconds: avgTimeToRecover * 1000, - }); - if (parseInt(minutes.value, 10) > 60) return hours.formatted; - return minutes.formatted; - }; return ( @@ -176,9 +161,14 @@ export function LatencyAlertsHistoryChart({

- {getFormattedDuration( - triggeredAlertsData?.avgTimeToRecoverMS - )} + {triggeredAlertsData?.avgTimeToRecoverMS + ? convertTo({ + unit: 'minutes', + microseconds: + triggeredAlertsData?.avgTimeToRecoverMS * 1000, + extended: true, + }).formatted + : '-'}

diff --git a/x-pack/plugins/observability/common/utils/formatters/duration.ts b/x-pack/plugins/observability/common/utils/formatters/duration.ts index 96486079f3c4f..d37b75cd1cab7 100644 --- a/x-pack/plugins/observability/common/utils/formatters/duration.ts +++ b/x-pack/plugins/observability/common/utils/formatters/duration.ts @@ -109,7 +109,7 @@ function getUnitLabelAndConvertedValue(unitKey: DurationTimeUnit, value: number) /** * Converts a microseconds value into the unit defined. */ -function convertTo({ +export function convertTo({ unit, microseconds, defaultValue = NOT_AVAILABLE_LABEL, diff --git a/x-pack/plugins/observability/public/index.ts b/x-pack/plugins/observability/public/index.ts index 62f980bfc9d32..b18df5c6cd548 100644 --- a/x-pack/plugins/observability/public/index.ts +++ b/x-pack/plugins/observability/public/index.ts @@ -121,3 +121,4 @@ export { ExploratoryViewContextProvider } from './components/shared/exploratory_ export { fromQuery, toQuery } from './utils/url'; export type { NavigationSection } from './services/navigation_registry'; +export { convertTo } from '../common/utils/formatters/duration'; From 2412cf4ed29bddb246b77cf2ad60d3387dbc1655 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Tue, 17 Jan 2023 16:25:39 +0100 Subject: [PATCH 39/44] fix service name typo --- .../alert_details_app_section/latency_alerts_history_chart.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 6b6a0c92964c8..21e1a6cab84d6 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -118,8 +118,9 @@ export function LatencyAlertsHistoryChart({

+ {serviceName} {i18n.translate('xpack.apm.latencyChartHistory.chartTitle', { - defaultMessage: 'Kibana latency alerts history', + defaultMessage: ' latency alerts history', })}

From fbe3293be6e092a26d856e3c01964656c1b3b4bc Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Wed, 18 Jan 2023 15:43:58 +0100 Subject: [PATCH 40/44] fix type and query --- .../latency_alerts_history_chart.tsx | 5 +- .../use_fetch_triggered_alert_history.ts | 31 ++++--- x-pack/plugins/rule_registry/common/types.ts | 81 +++++++++---------- 3 files changed, 61 insertions(+), 56 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 21e1a6cab84d6..5dd8b2a3fe57c 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -162,11 +162,10 @@ export function LatencyAlertsHistoryChart({

- {triggeredAlertsData?.avgTimeToRecoverMS + {triggeredAlertsData?.avgTimeToRecoverUS ? convertTo({ unit: 'minutes', - microseconds: - triggeredAlertsData?.avgTimeToRecoverMS * 1000, + microseconds: triggeredAlertsData?.avgTimeToRecoverUS, extended: true, }).formatted : '-'} diff --git a/x-pack/plugins/apm/public/hooks/use_fetch_triggered_alert_history.ts b/x-pack/plugins/apm/public/hooks/use_fetch_triggered_alert_history.ts index 0b72b1fe63036..4c457f135bf01 100644 --- a/x-pack/plugins/apm/public/hooks/use_fetch_triggered_alert_history.ts +++ b/x-pack/plugins/apm/public/hooks/use_fetch_triggered_alert_history.ts @@ -8,8 +8,10 @@ import { AsApiContract } from '@kbn/actions-plugin/common'; import { HttpSetup } from '@kbn/core/public'; import { + ALERT_DURATION, ALERT_RULE_UUID, ALERT_START, + ALERT_STATUS, ALERT_TIME_RANGE, } from '@kbn/rule-data-utils'; import { BASE_RAC_ALERTS_API_PATH } from '@kbn/rule-registry-plugin/common'; @@ -28,7 +30,7 @@ interface FetchTriggeredAlertsHistory { doc_count: number; }>; error?: string; - avgTimeToRecoverMS: number; + avgTimeToRecoverUS: number; } interface TriggeredAlertsHistory { @@ -64,7 +66,7 @@ export function useFetchTriggeredAlertsHistory({ totalTriggeredAlerts, histogramTriggeredAlerts, error, - avgTimeToRecoverMS, + avgTimeToRecoverUS, } = await fetchTriggeredAlertsHistory({ http, index, @@ -79,7 +81,7 @@ export function useFetchTriggeredAlertsHistory({ triggeredAlertsData: { totalTriggeredAlerts, histogramTriggeredAlerts, - avgTimeToRecoverMS, + avgTimeToRecoverUS, }, isLoadingRuleAlertsAggs: false, })); @@ -175,11 +177,17 @@ export async function fetchTriggeredAlertsHistory({ }, }, }, - avgTimeToRecoverMS: { - avg: { - script: { - source: - "if (!doc['kibana.alert.end'].empty){return(doc['kibana.alert.end'].value.millis) - (doc['kibana.alert.start'].value.millis)}", + avgTimeToRecoverUS: { + filter: { + term: { + [ALERT_STATUS]: 'recovered', + }, + }, + aggs: { + recoveryTime: { + avg: { + field: ALERT_DURATION, + }, }, }, }, @@ -190,11 +198,12 @@ export async function fetchTriggeredAlertsHistory({ const totalTriggeredAlerts = res?.hits.total.value; const histogramTriggeredAlerts = res?.aggregations?.histogramTriggeredAlerts.buckets; - const avgTimeToRecoverMS = res?.aggregations?.avgTimeToRecoverMS.value; + const avgTimeToRecoverUS = + res?.aggregations?.avgTimeToRecoverUS.recoveryTime.value; return { totalTriggeredAlerts, histogramTriggeredAlerts, - avgTimeToRecoverMS, + avgTimeToRecoverUS, }; } catch (error) { console.error(error); @@ -202,7 +211,7 @@ export async function fetchTriggeredAlertsHistory({ error, totalTriggeredAlerts: 0, histogramTriggeredAlerts: [], - avgTimeToRecoverMS: 0, + avgTimeToRecoverUS: 0, }; } } diff --git a/x-pack/plugins/rule_registry/common/types.ts b/x-pack/plugins/rule_registry/common/types.ts index 1bf454c8afab5..b73e0af8bc138 100644 --- a/x-pack/plugins/rule_registry/common/types.ts +++ b/x-pack/plugins/rule_registry/common/types.ts @@ -184,6 +184,36 @@ const bucketAggsTempsSchemas: t.Type = t.exact( ), }) ); + +/** + * Schemas for the metrics Aggregations + * + * Currently supported: + * - avg + * - cardinality + * - min + * - max + * - sum + * - top_hits + * - weighted_avg + * + * Not implemented: + * - boxplot + * - extended_stats + * - geo_bounds + * - geo_centroid + * - geo_line + * - matrix_stats + * - median_absolute_deviation + * - percentile_ranks + * - percentiles + * - rate + * - scripted_metric + * - stats + * - string_stats + * - t_test + * - value_count + */ export const metricsAggsSchemas = t.exact( t.partial({ avg: t.exact( @@ -256,50 +286,17 @@ export const metricsAggsSchemas = t.exact( export const bucketAggsSchemas = t.intersection([ bucketAggsTempsSchemas, - t.partial({ - aggs: t.union([ - t.record(t.string, bucketAggsTempsSchemas), - t.record(t.string, metricsAggsSchemas), - t.undefined, - ]), - aggregations: t.union([ - t.record(t.string, bucketAggsTempsSchemas), - t.record(t.string, metricsAggsSchemas), - t.undefined, - ]), - }), + t.exact( + t.partial({ + aggs: t.record(t.string, t.intersection([metricsAggsSchemas, bucketAggsTempsSchemas])), + aggregations: t.record( + t.string, + t.intersection([metricsAggsSchemas, bucketAggsTempsSchemas]) + ), + }) + ), ]); -/** - * Schemas for the metrics Aggregations - * - * Currently supported: - * - avg - * - cardinality - * - min - * - max - * - sum - * - top_hits - * - weighted_avg - * - * Not implemented: - * - boxplot - * - extended_stats - * - geo_bounds - * - geo_centroid - * - geo_line - * - matrix_stats - * - median_absolute_deviation - * - percentile_ranks - * - percentiles - * - rate - * - scripted_metric - * - stats - * - string_stats - * - t_test - * - value_count - */ - export type PutIndexTemplateRequest = estypes.IndicesPutIndexTemplateRequest & { body?: { composed_of?: string[] }; }; From b8d79d9a6952d56fb021b222772a58a713693256 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Thu, 19 Jan 2023 14:05:59 +0100 Subject: [PATCH 41/44] fix failing test --- x-pack/plugins/rule_registry/server/routes/find.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/rule_registry/server/routes/find.ts b/x-pack/plugins/rule_registry/server/routes/find.ts index 5cdaad09503c8..85e6874d7eca3 100644 --- a/x-pack/plugins/rule_registry/server/routes/find.ts +++ b/x-pack/plugins/rule_registry/server/routes/find.ts @@ -27,8 +27,8 @@ export const findAlertsByQueryRoute = (router: IRouter index: t.string, query: t.object, aggs: t.union([ - t.record(t.string, bucketAggsSchemas), t.record(t.string, metricsAggsSchemas), + t.record(t.string, bucketAggsSchemas), t.undefined, ]), sort: t.union([t.array(t.object), t.undefined]), From ef7431de1ecd877d7555f9e09c0c6a5326550638 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Thu, 19 Jan 2023 19:17:12 +0100 Subject: [PATCH 42/44] remove unused import --- .../alert_details_app_section/latency_alerts_history_chart.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 5dd8b2a3fe57c..2d160f16b1c0e 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -13,7 +13,6 @@ import { EuiFlexItem } from '@elastic/eui'; import { EuiTitle } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { EuiText } from '@elastic/eui'; -// import { useFetchTriggeredAlertsHistory } from '@kbn/observability-plugin/public'; import { AnnotationDomainType, LineAnnotation, From f85288214dce9870bca35ab821d8b105986d4d68 Mon Sep 17 00:00:00 2001 From: Faisal Kanout Date: Thu, 19 Jan 2023 20:02:37 +0100 Subject: [PATCH 43/44] unified the red color --- .../alert_details_app_section/constants.ts | 1 + .../latency_alerts_history_chart.tsx | 11 ++++++++--- .../latency_chart_components/alert_annotation.tsx | 6 +++--- .../alert_threshold_annotation.tsx | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/constants.ts b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/constants.ts index 45fe209d8111a..497b779d24e7d 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/constants.ts +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/constants.ts @@ -5,3 +5,4 @@ * 2.0. */ export const DEFAULT_DATE_FORMAT = 'HH:mm:ss'; +export const CHART_ANNOTATION_RED_COLOR = '#BD271E'; diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx index 2d160f16b1c0e..4927782b722d9 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_alerts_history_chart.tsx @@ -32,6 +32,7 @@ import { getMaxY, getResponseTimeTickFormatter, } from '../../../shared/charts/transaction_charts/helper'; +import { CHART_ANNOTATION_RED_COLOR } from './constants'; interface LatencyAlertsHistoryChartProps { serviceName: string; @@ -207,12 +208,16 @@ export function LatencyAlertsHistoryChart({ }) || [] } style={{ - line: { strokeWidth: 3, stroke: 'red', opacity: 1 }, + line: { + strokeWidth: 3, + stroke: CHART_ANNOTATION_RED_COLOR, + opacity: 1, + }, }} - marker={} + marker={} markerBody={(annotationData) => ( <> - + {annotationData.header} diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_chart_components/alert_annotation.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_chart_components/alert_annotation.tsx index 27354ea2ac3b8..d4496e6512434 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_chart_components/alert_annotation.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_chart_components/alert_annotation.tsx @@ -14,7 +14,7 @@ import { import moment from 'moment'; import { EuiIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { DEFAULT_DATE_FORMAT } from '../constants'; +import { CHART_ANNOTATION_RED_COLOR, DEFAULT_DATE_FORMAT } from '../constants'; export function AlertAnnotation({ alertStarted }: { alertStarted: number }) { return ( @@ -36,11 +36,11 @@ export function AlertAnnotation({ alertStarted }: { alertStarted: number }) { style={{ line: { strokeWidth: 3, - stroke: '#f00', + stroke: CHART_ANNOTATION_RED_COLOR, opacity: 1, }, }} - marker={} + marker={} markerPosition={Position.Top} /> ); diff --git a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_chart_components/alert_threshold_annotation.tsx b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_chart_components/alert_threshold_annotation.tsx index c1c6ddefd32f1..0304d298d195e 100644 --- a/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_chart_components/alert_threshold_annotation.tsx +++ b/x-pack/plugins/apm/public/components/alerting/ui_components/alert_details_app_section/latency_chart_components/alert_threshold_annotation.tsx @@ -7,6 +7,7 @@ import React from 'react'; import { AnnotationDomainType, LineAnnotation } from '@elastic/charts'; +import { CHART_ANNOTATION_RED_COLOR } from '../constants'; export function AlertThresholdAnnotation({ threshold, @@ -29,7 +30,7 @@ export function AlertThresholdAnnotation({ line: { opacity: 0.5, strokeWidth: 1, - stroke: 'red', + stroke: CHART_ANNOTATION_RED_COLOR, }, }} /> From 67ec1708bc325c7d972e123e057f4a9c75bb24b5 Mon Sep 17 00:00:00 2001 From: Xavier Mouligneau Date: Thu, 19 Jan 2023 15:37:43 -0500 Subject: [PATCH 44/44] simplify validation after a lot of failures --- x-pack/plugins/rule_registry/common/types.ts | 6 ++---- x-pack/plugins/rule_registry/server/routes/find.ts | 7 +------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/rule_registry/common/types.ts b/x-pack/plugins/rule_registry/common/types.ts index b73e0af8bc138..3c0816763e220 100644 --- a/x-pack/plugins/rule_registry/common/types.ts +++ b/x-pack/plugins/rule_registry/common/types.ts @@ -279,8 +279,6 @@ export const metricsAggsSchemas = t.exact( }), }) ), - aggs: t.undefined, - aggregations: t.undefined, }) ); @@ -288,10 +286,10 @@ export const bucketAggsSchemas = t.intersection([ bucketAggsTempsSchemas, t.exact( t.partial({ - aggs: t.record(t.string, t.intersection([metricsAggsSchemas, bucketAggsTempsSchemas])), + aggs: t.record(t.string, t.intersection([bucketAggsTempsSchemas, metricsAggsSchemas])), aggregations: t.record( t.string, - t.intersection([metricsAggsSchemas, bucketAggsTempsSchemas]) + t.intersection([bucketAggsTempsSchemas, metricsAggsSchemas]) ), }) ), diff --git a/x-pack/plugins/rule_registry/server/routes/find.ts b/x-pack/plugins/rule_registry/server/routes/find.ts index 85e6874d7eca3..b2ba28fdda5da 100644 --- a/x-pack/plugins/rule_registry/server/routes/find.ts +++ b/x-pack/plugins/rule_registry/server/routes/find.ts @@ -26,11 +26,7 @@ export const findAlertsByQueryRoute = (router: IRouter t.partial({ index: t.string, query: t.object, - aggs: t.union([ - t.record(t.string, metricsAggsSchemas), - t.record(t.string, bucketAggsSchemas), - t.undefined, - ]), + aggs: t.record(t.string, t.intersection([metricsAggsSchemas, bucketAggsSchemas])), sort: t.union([t.array(t.object), t.undefined]), search_after: t.union([t.array(t.number), t.array(t.string), t.undefined]), size: t.union([PositiveInteger, t.undefined]), @@ -49,7 +45,6 @@ export const findAlertsByQueryRoute = (router: IRouter // eslint-disable-next-line @typescript-eslint/naming-convention const { query, aggs, _source, track_total_hits, size, index, sort, search_after } = request.body; - const racContext = await context.rac; const alertsClient = await racContext.getAlertsClient(); const alerts = await alertsClient.find({