From a777ded1a2a4a3d4429cfdabf4d848623601c4d5 Mon Sep 17 00:00:00 2001 From: Kevin Delemme Date: Wed, 18 Sep 2024 15:03:25 -0400 Subject: [PATCH 1/3] Provide argument as object --- .../good_bad_events_chart.tsx | 10 +-- .../components/events_chart_panel.tsx | 10 +-- .../components/common/data_preview_chart.tsx | 2 +- .../slo/public/utils/slo/get_discover_link.ts | 62 +++++++++++++------ 4 files changed, 53 insertions(+), 31 deletions(-) rename x-pack/plugins/observability_solution/slo/public/{pages/slos/components/common => components/good_bad_events_chart}/good_bad_events_chart.tsx (94%) diff --git a/x-pack/plugins/observability_solution/slo/public/pages/slos/components/common/good_bad_events_chart.tsx b/x-pack/plugins/observability_solution/slo/public/components/good_bad_events_chart/good_bad_events_chart.tsx similarity index 94% rename from x-pack/plugins/observability_solution/slo/public/pages/slos/components/common/good_bad_events_chart.tsx rename to x-pack/plugins/observability_solution/slo/public/components/good_bad_events_chart/good_bad_events_chart.tsx index 601ac64372595..20732eca4058d 100644 --- a/x-pack/plugins/observability_solution/slo/public/pages/slos/components/common/good_bad_events_chart.tsx +++ b/x-pack/plugins/observability_solution/slo/public/components/good_bad_events_chart/good_bad_events_chart.tsx @@ -22,10 +22,10 @@ import { GetPreviewDataResponse, SLOWithSummaryResponse } from '@kbn/slo-schema' import moment from 'moment'; import React, { useRef } from 'react'; import { useAnnotations } from '@kbn/observability-plugin/public'; -import { TimeBounds } from '../../../slo_details/types'; -import { getBrushTimeBounds } from '../../../../utils/slo/duration'; -import { useKibana } from '../../../../utils/kibana_react'; -import { openInDiscover } from '../../../../utils/slo/get_discover_link'; +import { TimeBounds } from '../../pages/slo_details/types'; +import { getBrushTimeBounds } from '../../utils/slo/duration'; +import { useKibana } from '../../utils/kibana_react'; +import { openInDiscover } from '../../utils/slo/get_discover_link'; export interface Props { data: GetPreviewDataResponse; @@ -89,7 +89,7 @@ export function GoodBadEventsChart({ to: moment(datum.x).add(intervalInMilliseconds, 'ms').toISOString(), mode: 'absolute' as const, }; - openInDiscover(slo, isBad, !isBad, timeRange, discover); + openInDiscover({ slo, showBad: isBad, showGood: !isBad, timeRange, discover }); } }; diff --git a/x-pack/plugins/observability_solution/slo/public/pages/slo_details/components/events_chart_panel.tsx b/x-pack/plugins/observability_solution/slo/public/pages/slo_details/components/events_chart_panel.tsx index cd0251fd5ab64..0e047ee16bb05 100644 --- a/x-pack/plugins/observability_solution/slo/public/pages/slo_details/components/events_chart_panel.tsx +++ b/x-pack/plugins/observability_solution/slo/public/pages/slo_details/components/events_chart_panel.tsx @@ -26,7 +26,7 @@ import { TimeBounds } from '../types'; import { SloTabId } from './slo_details'; import { useGetPreviewData } from '../../../hooks/use_get_preview_data'; import { useKibana } from '../../../utils/kibana_react'; -import { GoodBadEventsChart } from '../../slos/components/common/good_bad_events_chart'; +import { GoodBadEventsChart } from '../../../components/good_bad_events_chart/good_bad_events_chart'; import { getDiscoverLink } from '../../../utils/slo/get_discover_link'; export interface Props { @@ -104,15 +104,15 @@ export function EventsChartPanel({ slo, range, selectedTabId, onBrushed }: Props diff --git a/x-pack/plugins/observability_solution/slo/public/pages/slo_edit/components/common/data_preview_chart.tsx b/x-pack/plugins/observability_solution/slo/public/pages/slo_edit/components/common/data_preview_chart.tsx index cb9730497e216..5241e6c78aebe 100644 --- a/x-pack/plugins/observability_solution/slo/public/pages/slo_edit/components/common/data_preview_chart.tsx +++ b/x-pack/plugins/observability_solution/slo/public/pages/slo_edit/components/common/data_preview_chart.tsx @@ -38,7 +38,7 @@ import moment from 'moment'; import React, { useState } from 'react'; import { useFormContext } from 'react-hook-form'; import { useKibana } from '../../../../utils/kibana_react'; -import { GoodBadEventsChart } from '../../../slos/components/common/good_bad_events_chart'; +import { GoodBadEventsChart } from '../../../../components/good_bad_events_chart/good_bad_events_chart'; import { useDebouncedGetPreviewData } from '../../hooks/use_preview'; import { useSectionFormValidation } from '../../hooks/use_section_form_validation'; import { CreateSLOForm } from '../../types'; diff --git a/x-pack/plugins/observability_solution/slo/public/utils/slo/get_discover_link.ts b/x-pack/plugins/observability_solution/slo/public/utils/slo/get_discover_link.ts index 80ef9c12ee99e..b4cf59d251848 100644 --- a/x-pack/plugins/observability_solution/slo/public/utils/slo/get_discover_link.ts +++ b/x-pack/plugins/observability_solution/slo/public/utils/slo/get_discover_link.ts @@ -12,12 +12,17 @@ import { buildEsQuery } from '@kbn/observability-plugin/public'; import { v4 } from 'uuid'; import { isEmpty } from 'lodash'; -function createDiscoverLocator( - slo: SLOWithSummaryResponse, +function createDiscoverLocator({ + slo, showBad = false, showGood = false, - timeRange?: TimeRange -) { + timeRange, +}: { + slo: SLOWithSummaryResponse; + showBad: boolean; + showGood: boolean; + timeRange: TimeRange; +}) { const indexId = v4(); const filters: Filter[] = []; @@ -42,8 +47,15 @@ function createDiscoverLocator( const totalFilters = kqlWithFiltersSchema.is(slo.indicator.params.total) ? slo.indicator.params.total.filters : []; - const customGoodFilter = buildEsQuery({ kuery: goodKuery, filters: goodFilters }); - const customTotalFilter = buildEsQuery({ kuery: totalKuery, filters: totalFilters }); + + const customGoodFilter = buildEsQuery({ + kuery: goodKuery, + filters: goodFilters, + }); + const customTotalFilter = buildEsQuery({ + kuery: totalKuery, + filters: totalFilters, + }); const customBadFilter = { bool: { filter: customTotalFilter, must_not: customGoodFilter } }; filters.push({ @@ -144,22 +156,32 @@ function createDiscoverLocator( }; } -export function getDiscoverLink( - slo: SLOWithSummaryResponse, - timeRange: TimeRange, - discover?: DiscoverStart -) { - const config = createDiscoverLocator(slo, false, false, timeRange); - return discover?.locator?.getRedirectUrl(config); +export function getDiscoverLink({ + slo, + timeRange, + discover, +}: { + slo: SLOWithSummaryResponse; + timeRange: TimeRange; + discover?: DiscoverStart; +}) { + const locatorConfig = createDiscoverLocator({ slo, showBad: false, showGood: false, timeRange }); + return discover?.locator?.getRedirectUrl(locatorConfig); } -export function openInDiscover( - slo: SLOWithSummaryResponse, +export function openInDiscover({ + slo, showBad = false, showGood = false, - timeRange?: TimeRange, - discover?: DiscoverStart -) { - const config = createDiscoverLocator(slo, showBad, showGood, timeRange); - discover?.locator?.navigate(config); + timeRange, + discover, +}: { + slo: SLOWithSummaryResponse; + showBad: boolean; + showGood: boolean; + timeRange: TimeRange; + discover?: DiscoverStart; +}) { + const locatorConfig = createDiscoverLocator({ slo, showBad, showGood, timeRange }); + discover?.locator?.navigate(locatorConfig); } From 950fd28d0c645011d594b01bec6785c9efbf4f93 Mon Sep 17 00:00:00 2001 From: Kevin Delemme Date: Wed, 18 Sep 2024 16:55:36 -0400 Subject: [PATCH 2/3] fetch esQueryConfig from uiSettings --- .../good_bad_events_chart.tsx | 2 +- .../components/events_chart_panel.tsx | 3 ++- .../slo/public/utils/slo/get_discover_link.ts | 20 +++++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/observability_solution/slo/public/components/good_bad_events_chart/good_bad_events_chart.tsx b/x-pack/plugins/observability_solution/slo/public/components/good_bad_events_chart/good_bad_events_chart.tsx index 20732eca4058d..ba3a201402e4f 100644 --- a/x-pack/plugins/observability_solution/slo/public/components/good_bad_events_chart/good_bad_events_chart.tsx +++ b/x-pack/plugins/observability_solution/slo/public/components/good_bad_events_chart/good_bad_events_chart.tsx @@ -89,7 +89,7 @@ export function GoodBadEventsChart({ to: moment(datum.x).add(intervalInMilliseconds, 'ms').toISOString(), mode: 'absolute' as const, }; - openInDiscover({ slo, showBad: isBad, showGood: !isBad, timeRange, discover }); + openInDiscover({ slo, showBad: isBad, showGood: !isBad, timeRange, discover, uiSettings }); } }; diff --git a/x-pack/plugins/observability_solution/slo/public/pages/slo_details/components/events_chart_panel.tsx b/x-pack/plugins/observability_solution/slo/public/pages/slo_details/components/events_chart_panel.tsx index 0e047ee16bb05..c7da9418db769 100644 --- a/x-pack/plugins/observability_solution/slo/public/pages/slo_details/components/events_chart_panel.tsx +++ b/x-pack/plugins/observability_solution/slo/public/pages/slo_details/components/events_chart_panel.tsx @@ -37,7 +37,7 @@ export interface Props { } export function EventsChartPanel({ slo, range, selectedTabId, onBrushed }: Props) { - const { discover } = useKibana().services; + const { discover, uiSettings } = useKibana().services; const { isLoading, data } = useGetPreviewData({ range, @@ -112,6 +112,7 @@ export function EventsChartPanel({ slo, range, selectedTabId, onBrushed }: Props mode: 'relative', }, discover, + uiSettings, })} data-test-subj="sloDetailDiscoverLink" > diff --git a/x-pack/plugins/observability_solution/slo/public/utils/slo/get_discover_link.ts b/x-pack/plugins/observability_solution/slo/public/utils/slo/get_discover_link.ts index b4cf59d251848..e8878b0a16530 100644 --- a/x-pack/plugins/observability_solution/slo/public/utils/slo/get_discover_link.ts +++ b/x-pack/plugins/observability_solution/slo/public/utils/slo/get_discover_link.ts @@ -11,17 +11,21 @@ import { i18n } from '@kbn/i18n'; import { buildEsQuery } from '@kbn/observability-plugin/public'; import { v4 } from 'uuid'; import { isEmpty } from 'lodash'; +import { getEsQueryConfig } from '@kbn/data-plugin/public'; +import { IUiSettingsClient } from '@kbn/core/public'; function createDiscoverLocator({ slo, showBad = false, showGood = false, timeRange, + uiSettings, }: { slo: SLOWithSummaryResponse; showBad: boolean; showGood: boolean; timeRange: TimeRange; + uiSettings?: IUiSettingsClient; }) { const indexId = v4(); const filters: Filter[] = []; @@ -51,10 +55,12 @@ function createDiscoverLocator({ const customGoodFilter = buildEsQuery({ kuery: goodKuery, filters: goodFilters, + ...(uiSettings && { config: getEsQueryConfig(uiSettings) }), }); const customTotalFilter = buildEsQuery({ kuery: totalKuery, filters: totalFilters, + ...(uiSettings && { config: getEsQueryConfig(uiSettings) }), }); const customBadFilter = { bool: { filter: customTotalFilter, must_not: customGoodFilter } }; @@ -160,12 +166,20 @@ export function getDiscoverLink({ slo, timeRange, discover, + uiSettings, }: { slo: SLOWithSummaryResponse; timeRange: TimeRange; discover?: DiscoverStart; + uiSettings?: IUiSettingsClient; }) { - const locatorConfig = createDiscoverLocator({ slo, showBad: false, showGood: false, timeRange }); + const locatorConfig = createDiscoverLocator({ + slo, + showBad: false, + showGood: false, + timeRange, + uiSettings, + }); return discover?.locator?.getRedirectUrl(locatorConfig); } @@ -175,13 +189,15 @@ export function openInDiscover({ showGood = false, timeRange, discover, + uiSettings, }: { slo: SLOWithSummaryResponse; showBad: boolean; showGood: boolean; timeRange: TimeRange; discover?: DiscoverStart; + uiSettings?: IUiSettingsClient; }) { - const locatorConfig = createDiscoverLocator({ slo, showBad, showGood, timeRange }); + const locatorConfig = createDiscoverLocator({ slo, showBad, showGood, timeRange, uiSettings }); discover?.locator?.navigate(locatorConfig); } From c44a2dde71000c27c50968a39a46e9047ac0c65e Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:59:27 +0000 Subject: [PATCH 3/3] [CI] Auto-commit changed files from 'yarn openapi:bundle' --- ...solution_entity_analytics_api_2023_10_31.bundled.schema.yaml | 2 +- ...solution_entity_analytics_api_2023_10_31.bundled.schema.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml b/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml index 461d490305707..42e8db13d78a4 100644 --- a/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml +++ b/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml @@ -439,7 +439,7 @@ paths: - Security Solution Entity Analytics API /api/entity_store/entities/list: get: - description: 'List entities records, paging, sorting and filtering as needed.' + description: List entities records, paging, sorting and filtering as needed. operationId: ListEntities parameters: - in: query diff --git a/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml b/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml index b3584e7efd08c..ec3cf571b936e 100644 --- a/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml +++ b/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_entity_analytics_api_2023_10_31.bundled.schema.yaml @@ -439,7 +439,7 @@ paths: - Security Solution Entity Analytics API /api/entity_store/entities/list: get: - description: 'List entities records, paging, sorting and filtering as needed.' + description: List entities records, paging, sorting and filtering as needed. operationId: ListEntities parameters: - in: query