From 1b5678668eb44398caa46ad4fc6c60eb85020fbe Mon Sep 17 00:00:00 2001 From: Yngrid Coello Date: Wed, 15 Jan 2025 13:14:11 +0100 Subject: [PATCH] support failures store syntax in links and logs explorer locator --- .../locators/observability_logs_explorer.ts | 5 +++ .../table/failed_docs_percentage_link.tsx | 10 +++-- .../failed_docs/lens_attributes.ts | 2 +- .../quality_issue_flyout/index.tsx | 13 +++++- .../hooks/use_quality_issues_docs_chart.ts | 12 +++--- .../public/hooks/use_redirect_link.ts | 41 ++++++++----------- .../common/locators/single_dataset_locator.ts | 14 +++++-- 7 files changed, 58 insertions(+), 39 deletions(-) diff --git a/packages/deeplinks/observability/locators/observability_logs_explorer.ts b/packages/deeplinks/observability/locators/observability_logs_explorer.ts index ae4cbc12cec6d..d2d56a72a0d6d 100644 --- a/packages/deeplinks/observability/locators/observability_logs_explorer.ts +++ b/packages/deeplinks/observability/locators/observability_logs_explorer.ts @@ -38,6 +38,11 @@ export interface SingleDatasetLocatorParams extends DatasetLocatorParams { * ex: system.syslog */ dataset: string; + /** + * Selector to be added to the dataset. + * ex: ::failures + */ + selector?: string; } // Data view locator diff --git a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/failed_docs_percentage_link.tsx b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/failed_docs_percentage_link.tsx index 2ba6b22b63771..219025ebb8757 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/failed_docs_percentage_link.tsx +++ b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/failed_docs_percentage_link.tsx @@ -5,13 +5,14 @@ * 2.0. */ -import { EuiSkeletonRectangle, EuiFlexGroup, EuiLink } from '@elastic/eui'; -import React from 'react'; +import { EuiFlexGroup, EuiLink, EuiSkeletonRectangle } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { useDatasetRedirectLinkTelemetry, useRedirectLink } from '../../../hooks'; -import { QualityPercentageIndicator } from '../../quality_indicator'; +import React from 'react'; +import { FAILURE_STORE_SELECTOR } from '../../../../common/constants'; import { DataStreamStat } from '../../../../common/data_streams_stats/data_stream_stat'; import { TimeRangeConfig } from '../../../../common/types'; +import { useDatasetRedirectLinkTelemetry, useRedirectLink } from '../../../hooks'; +import { QualityPercentageIndicator } from '../../quality_indicator'; export const FailedDocsPercentageLink = ({ isLoading, @@ -36,6 +37,7 @@ export const FailedDocsPercentageLink = ({ query: { language: 'kuery', query: '' }, sendTelemetry, timeRangeConfig: timeRange, + selector: FAILURE_STORE_SELECTOR, }); const tooltip = (failedDocsCount: number) => diff --git a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality_details/overview/document_trends/failed_docs/lens_attributes.ts b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality_details/overview/document_trends/failed_docs/lens_attributes.ts index a278d999e731f..bd6b3f2b4384c 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality_details/overview/document_trends/failed_docs/lens_attributes.ts +++ b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality_details/overview/document_trends/failed_docs/lens_attributes.ts @@ -25,7 +25,7 @@ enum DatasetQualityLensColumn { } const MAX_BREAKDOWN_SERIES = 5; -const FAILED_DOCS_QUERY = `_index: "${FAILURE_STORE_SELECTOR}"`; +const FAILED_DOCS_QUERY = `_index: "*${FAILURE_STORE_SELECTOR}"`; interface GetLensAttributesParams { color: string; diff --git a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality_details/quality_issue_flyout/index.tsx b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality_details/quality_issue_flyout/index.tsx index 38b03a9d07748..a16b4e90b153b 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality_details/quality_issue_flyout/index.tsx +++ b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality_details/quality_issue_flyout/index.tsx @@ -22,6 +22,7 @@ import { EuiToolTip, } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; +import { FAILURE_STORE_SELECTOR } from '../../../../common/constants'; import { NavigationSource } from '../../../services/telemetry'; import { useDatasetDetailsRedirectLinkTelemetry, @@ -74,8 +75,18 @@ export default function QualityIssueFlyout() { const redirectLinkProps = useRedirectLink({ dataStreamStat: datasetDetails, timeRangeConfig: timeRange, - query: { language: 'kuery', query: `${_IGNORED}: ${expandedDegradedField}` }, + query: { + language: 'kuery', + query: + expandedDegradedField && expandedDegradedField.type === 'degraded' + ? `${_IGNORED}: ${expandedDegradedField?.name}` + : '', + }, sendTelemetry, + selector: + expandedDegradedField && expandedDegradedField.type === 'failed' + ? FAILURE_STORE_SELECTOR + : undefined, }); return ( diff --git a/x-pack/plugins/observability_solution/dataset_quality/public/hooks/use_quality_issues_docs_chart.ts b/x-pack/plugins/observability_solution/dataset_quality/public/hooks/use_quality_issues_docs_chart.ts index d425198bb46c6..438defa8ae0f0 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/public/hooks/use_quality_issues_docs_chart.ts +++ b/x-pack/plugins/observability_solution/dataset_quality/public/hooks/use_quality_issues_docs_chart.ts @@ -11,7 +11,7 @@ import { i18n } from '@kbn/i18n'; import { useEuiTheme } from '@elastic/eui'; import type { DataView, DataViewField } from '@kbn/data-views-plugin/common'; import { fieldSupportsBreakdown } from '@kbn/field-utils'; -import { DEFAULT_LOGS_DATA_VIEW } from '../../common/constants'; +import { DEFAULT_LOGS_DATA_VIEW, FAILURE_STORE_SELECTOR } from '../../common/constants'; import { useCreateDataView } from './use_create_dataview'; import { useKibanaContextForPlugin } from '../utils'; import { useDatasetQualityDetailsState } from './use_dataset_quality_details_state'; @@ -20,7 +20,6 @@ import { getLensAttributes as getFailedLensAttributes } from '../components/data import { useRedirectLink } from './use_redirect_link'; import { useDatasetDetailsTelemetry } from './use_dataset_details_telemetry'; import { useDatasetDetailsRedirectLinkTelemetry } from './use_redirect_link_telemetry'; -import { QualityIssueType } from '../state_machines/dataset_quality_details_controller'; const openInLensText = i18n.translate('xpack.datasetQuality.details.chartOpenInLensText', { defaultMessage: 'Open in Lens', @@ -60,7 +59,9 @@ export const useQualityIssuesDocsChart = () => { const query = docsTrendChart === 'degraded' ? DEGRADED_DOCS_KUERY : ''; const { dataView } = useCreateDataView({ - indexPatternString: getDataViewIndexPattern(dataStream), + indexPatternString: getDataViewIndexPattern( + docsTrendChart === 'degraded' ? dataStream : `${dataStream}${FAILURE_STORE_SELECTOR}` + ), }); const breakdownDataViewField = useMemo( @@ -83,7 +84,7 @@ export const useQualityIssuesDocsChart = () => { ); const handleDocsTrendChartChange = useCallback( - (qualityIssuesChart: string) => { + (qualityIssuesChart: 'degraded' | 'failed') => { service.send({ type: 'QUALITY_ISSUES_CHART_CHANGE', qualityIssuesChart, @@ -97,7 +98,6 @@ export const useQualityIssuesDocsChart = () => { }, [trackDatasetDetailsBreakdownFieldChanged, isBreakdownFieldAsserted]); useEffect(() => { - // TODO: Fix dataStreamName for accesing failure store (::failures) const dataStreamName = dataStream ?? DEFAULT_LOGS_DATA_VIEW; const datasetTitle = integrationDetails?.integration?.datasets?.[datasetDetails.name] ?? datasetDetails.name; @@ -176,6 +176,7 @@ export const useQualityIssuesDocsChart = () => { timeRangeConfig: timeRange, breakdownField: breakdownDataViewField?.name, sendTelemetry, + selector: docsTrendChart === 'failed' ? FAILURE_STORE_SELECTOR : undefined, }); const extraActions: Action[] = [getOpenInLensAction]; @@ -204,7 +205,6 @@ export const useQualityIssuesDocsChart = () => { }; }; -// TODO: Fix dataView for accesing failure store (::failures) function getDataViewIndexPattern(dataStream: string | undefined) { return dataStream ?? DEFAULT_LOGS_DATA_VIEW; } diff --git a/x-pack/plugins/observability_solution/dataset_quality/public/hooks/use_redirect_link.ts b/x-pack/plugins/observability_solution/dataset_quality/public/hooks/use_redirect_link.ts index 5e065e55db44e..f3dbbdc9148be 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/public/hooks/use_redirect_link.ts +++ b/x-pack/plugins/observability_solution/dataset_quality/public/hooks/use_redirect_link.ts @@ -15,7 +15,7 @@ import { SingleDatasetLocatorParams, } from '@kbn/deeplinks-observability'; import { DiscoverAppLocatorParams, DISCOVER_APP_LOCATOR } from '@kbn/discover-plugin/common'; -import { Query, AggregateQuery, buildPhraseFilter } from '@kbn/es-query'; +import { Query, AggregateQuery } from '@kbn/es-query'; import { getRouterLinkProps } from '@kbn/router-utils'; import { RouterLinkProps } from '@kbn/router-utils/src/get_router_link_props'; import { LocatorPublic } from '@kbn/share-plugin/common'; @@ -30,12 +30,14 @@ export const useRedirectLink = ({ timeRangeConfig, breakdownField, sendTelemetry, + selector = '', }: { dataStreamStat: T; query?: Query | AggregateQuery; timeRangeConfig: TimeRangeConfig; breakdownField?: string; sendTelemetry: SendTelemetryFn; + selector?: string; }) => { const { services: { share, application }, @@ -76,6 +78,7 @@ export const useRedirectLink = ({ from, to, breakdownField, + selector, }) : buildDiscoverConfig({ locatorClient: share.url.locators, @@ -84,6 +87,7 @@ export const useRedirectLink = ({ from, to, breakdownField, + selector, }); const onClickWithTelemetry = (event: Parameters[0]) => { @@ -107,15 +111,16 @@ export const useRedirectLink = ({ isLogsExplorerAvailable, }; }, [ - breakdownField, + isLogsExplorerAppAccessible, + logsExplorerLocator, dataStreamStat, + query, from, to, - logsExplorerLocator, - query, - sendTelemetry, + breakdownField, + selector, share.url.locators, - isLogsExplorerAppAccessible, + sendTelemetry, ]); }; @@ -126,6 +131,7 @@ const buildLogsExplorerConfig = ({ from, to, breakdownField, + selector, }: { locator: LocatorPublic; dataStreamStat: T; @@ -133,6 +139,7 @@ const buildLogsExplorerConfig = ({ from: string; to: string; breakdownField?: string; + selector?: string; }): { navigate: () => void; routerLinkProps: RouterLinkProps; @@ -152,6 +159,7 @@ const buildLogsExplorerConfig = ({ }, }, breakdownField, + selector, }; const urlToLogsExplorer = locator.getRedirectUrl(params); @@ -175,6 +183,7 @@ const buildDiscoverConfig = ({ from, to, breakdownField, + selector, }: { locatorClient: LocatorClient; dataStreamStat: T; @@ -182,14 +191,12 @@ const buildDiscoverConfig = ({ from: string; to: string; breakdownField?: string; + selector?: string; }): { navigate: () => void; routerLinkProps: RouterLinkProps; } => { - const dataViewId = `${dataStreamStat.type}-${dataStreamStat.name}-*`; - const dataViewTitle = dataStreamStat.integration - ? `[${dataStreamStat.integration.title}] ${dataStreamStat.name}` - : `${dataViewId}`; + const dataViewId = `${dataStreamStat.type}-${dataStreamStat.name}-${dataStreamStat.namespace}${selector}`; const params: DiscoverAppLocatorParams = { timeRange: { @@ -209,19 +216,7 @@ const buildDiscoverConfig = ({ query, breakdownField, columns: [], - filters: [ - buildPhraseFilter( - { - name: 'data_stream.namespace', - type: 'string', - }, - dataStreamStat.namespace, - { - id: dataViewId, - title: dataViewTitle, - } - ), - ], + filters: [], interval: 'auto', sort: [['@timestamp', 'desc']], }; diff --git a/x-pack/plugins/observability_solution/observability_logs_explorer/common/locators/single_dataset_locator.ts b/x-pack/plugins/observability_solution/observability_logs_explorer/common/locators/single_dataset_locator.ts index 4187b9067d667..9ec23ae0bb364 100644 --- a/x-pack/plugins/observability_solution/observability_logs_explorer/common/locators/single_dataset_locator.ts +++ b/x-pack/plugins/observability_solution/observability_logs_explorer/common/locators/single_dataset_locator.ts @@ -26,12 +26,15 @@ export class SingleDatasetLocatorDefinition public readonly getLocation = (params: SingleDatasetLocatorParams) => { const { useHash } = this.deps; - const { integration, dataset } = params; + const { integration, dataset, selector = '' } = params; + + const datasetPattern = this.composeIndexPattern(dataset, selector); const unresolvedDatasetSelection = UnresolvedDatasetSelection.fromSelection({ name: integration, dataset: { - name: this.composeIndexPattern(dataset), + name: datasetPattern, + title: selector !== '' ? `${datasetPattern.split('-')[1]}${selector}` : undefined, }, }); @@ -42,7 +45,10 @@ export class SingleDatasetLocatorDefinition }); }; - private composeIndexPattern(datasetName: SingleDatasetLocatorParams['dataset']) { - return `logs-${datasetName}-*` as IndexPattern; + private composeIndexPattern( + datasetName: SingleDatasetLocatorParams['dataset'], + selector: string + ) { + return `logs-${datasetName}-*${selector}` as IndexPattern; } }