From afbd904e868f2a48a2bbeb8ff20baee8d4aeb468 Mon Sep 17 00:00:00 2001 From: christineweng <18648970+christineweng@users.noreply.github.com> Date: Mon, 10 Jun 2024 15:57:06 -0500 Subject: [PATCH] [8.14] [Security Solution][Alert KPI] Fix leading wildcard in KPI visualizations (#182875) (#185898) # Backport This will backport the following commits from `main` to `8.14`: - [[Security Solution][Alert KPI] Fix leading wildcard in KPI visualizations (#182875)](https://github.com/elastic/kibana/pull/182875) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) --- .../common/components/alerts_treemap_panel/index.tsx | 9 +++++++-- .../use_summary_chart_data.test.tsx | 2 ++ .../use_summary_chart_data.tsx | 9 +++++++-- .../pages/detection_engine/detection_engine.test.tsx | 3 --- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/alerts_treemap_panel/index.tsx b/x-pack/plugins/security_solution/public/common/components/alerts_treemap_panel/index.tsx index 33e526932c3e6..176671fa33667 100644 --- a/x-pack/plugins/security_solution/public/common/components/alerts_treemap_panel/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/alerts_treemap_panel/index.tsx @@ -10,6 +10,7 @@ import type { EuiComboBox } from '@elastic/eui'; import { EuiProgress } from '@elastic/eui'; import type { Filter, Query } from '@kbn/es-query'; import { buildEsQuery } from '@kbn/es-query'; +import { getEsQueryConfig } from '@kbn/data-plugin/common'; import React, { useEffect, useMemo } from 'react'; import { v4 as uuidv4 } from 'uuid'; @@ -24,6 +25,7 @@ import { HeaderSection } from '../header_section'; import { InspectButtonContainer } from '../inspect'; import { DEFAULT_STACK_BY_FIELD0_SIZE, getAlertsRiskQuery } from '../alerts_treemap/query'; import type { AlertsTreeMapAggregation } from '../alerts_treemap/types'; +import { useKibana } from '../../lib/kibana'; const DEFAULT_HEIGHT = DEFAULT_MIN_CHART_HEIGHT + 134; // px @@ -81,23 +83,26 @@ const AlertsTreemapPanelComponent: React.FC = ({ title, }: Props) => { const { to, from, deleteQuery, setQuery } = useGlobalTime(); + const { uiSettings } = useKibana().services; // create a unique, but stable (across re-renders) query id const uniqueQueryId = useMemo(() => `${ALERTS_TREEMAP_ID}-${uuidv4()}`, []); const additionalFilters = useMemo(() => { try { + const config = getEsQueryConfig(uiSettings); return [ buildEsQuery( undefined, query != null ? [query] : [], - filters?.filter((f) => f.meta.disabled === false) ?? [] + filters?.filter((f) => f.meta.disabled === false) ?? [], + config ), ]; } catch (e) { return []; } - }, [query, filters]); + }, [query, filters, uiSettings]); const { data: alertsData, diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data.test.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data.test.tsx index f25e4d9803c8b..7719fd47ea606 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data.test.tsx @@ -25,6 +25,8 @@ const dateNow = new Date(to).valueOf(); const mockDateNow = jest.fn().mockReturnValue(dateNow); Date.now = jest.fn(() => mockDateNow()) as unknown as DateConstructor['now']; +jest.mock('../../../../common/lib/kibana'); + const defaultUseQueryAlertsReturn = { loading: false, data: null, diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data.tsx index e8d0ddd061e81..db4f1881448f9 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data.tsx @@ -9,7 +9,9 @@ import { useEffect, useState, useMemo, useCallback } from 'react'; import { buildEsQuery } from '@kbn/es-query'; import type { MappingRuntimeFields } from '@elastic/elasticsearch/lib/api/types'; import type { Filter, Query } from '@kbn/es-query'; +import { getEsQueryConfig } from '@kbn/data-plugin/common'; import type { SummaryChartsAgg, SummaryChartsData } from './types'; +import { useKibana } from '../../../../common/lib/kibana'; import type { EntityFilter } from '../../../../overview/components/detection_response/alerts_by_status/use_alerts_by_status'; import type { ESBoolQuery } from '../../../../../common/typed_json'; import { useGlobalTime } from '../../../../common/containers/use_global_time'; @@ -86,19 +88,22 @@ export const useSummaryChartData: UseAlerts = ({ const [updatedAt, setUpdatedAt] = useState(Date.now()); const [items, setItems] = useState([]); + const { uiSettings } = useKibana().services; const additionalFilters = useMemo(() => { try { + const config = getEsQueryConfig(uiSettings); return [ buildEsQuery( undefined, query != null ? [query] : [], - filters?.filter((f) => f.meta.disabled === false) ?? [] + filters?.filter((f) => f.meta.disabled === false) ?? [], + config ), ]; } catch (e) { return []; } - }, [query, filters]); + }, [query, filters, uiSettings]); const { data, diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/detection_engine.test.tsx b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/detection_engine.test.tsx index 1deb6c98096b1..df14b0b775bb0 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/detection_engine.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/detection_engine.test.tsx @@ -112,9 +112,6 @@ jest.mock('../../../common/lib/kibana', () => { cases: { ui: { getCasesContext: mockCasesContext }, }, - uiSettings: { - get: jest.fn(), - }, timelines: { ...mockTimelines }, data: { query: {