Skip to content

Commit

Permalink
support failures store syntax in links and logs explorer locator
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrdyn committed Jan 15, 2025
1 parent 5289ba5 commit 1b56786
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -36,6 +37,7 @@ export const FailedDocsPercentageLink = ({
query: { language: 'kuery', query: '' },
sendTelemetry,
timeRangeConfig: timeRange,
selector: FAILURE_STORE_SELECTOR,
});

const tooltip = (failedDocsCount: number) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down Expand Up @@ -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(
Expand All @@ -83,7 +84,7 @@ export const useQualityIssuesDocsChart = () => {
);

const handleDocsTrendChartChange = useCallback(
(qualityIssuesChart: string) => {
(qualityIssuesChart: 'degraded' | 'failed') => {
service.send({
type: 'QUALITY_ISSUES_CHART_CHANGE',
qualityIssuesChart,
Expand All @@ -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;
Expand Down Expand Up @@ -176,6 +176,7 @@ export const useQualityIssuesDocsChart = () => {
timeRangeConfig: timeRange,
breakdownField: breakdownDataViewField?.name,
sendTelemetry,
selector: docsTrendChart === 'failed' ? FAILURE_STORE_SELECTOR : undefined,
});

const extraActions: Action[] = [getOpenInLensAction];
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -30,12 +30,14 @@ export const useRedirectLink = <T extends BasicDataStream>({
timeRangeConfig,
breakdownField,
sendTelemetry,
selector = '',
}: {
dataStreamStat: T;
query?: Query | AggregateQuery;
timeRangeConfig: TimeRangeConfig;
breakdownField?: string;
sendTelemetry: SendTelemetryFn;
selector?: string;
}) => {
const {
services: { share, application },
Expand Down Expand Up @@ -76,6 +78,7 @@ export const useRedirectLink = <T extends BasicDataStream>({
from,
to,
breakdownField,
selector,
})
: buildDiscoverConfig({
locatorClient: share.url.locators,
Expand All @@ -84,6 +87,7 @@ export const useRedirectLink = <T extends BasicDataStream>({
from,
to,
breakdownField,
selector,
});

const onClickWithTelemetry = (event: Parameters<RouterLinkProps['onClick']>[0]) => {
Expand All @@ -107,15 +111,16 @@ export const useRedirectLink = <T extends BasicDataStream>({
isLogsExplorerAvailable,
};
}, [
breakdownField,
isLogsExplorerAppAccessible,
logsExplorerLocator,
dataStreamStat,
query,
from,
to,
logsExplorerLocator,
query,
sendTelemetry,
breakdownField,
selector,
share.url.locators,
isLogsExplorerAppAccessible,
sendTelemetry,
]);
};

Expand All @@ -126,13 +131,15 @@ const buildLogsExplorerConfig = <T extends BasicDataStream>({
from,
to,
breakdownField,
selector,
}: {
locator: LocatorPublic<SingleDatasetLocatorParams>;
dataStreamStat: T;
query?: Query | AggregateQuery;
from: string;
to: string;
breakdownField?: string;
selector?: string;
}): {
navigate: () => void;
routerLinkProps: RouterLinkProps;
Expand All @@ -152,6 +159,7 @@ const buildLogsExplorerConfig = <T extends BasicDataStream>({
},
},
breakdownField,
selector,
};

const urlToLogsExplorer = locator.getRedirectUrl(params);
Expand All @@ -175,21 +183,20 @@ const buildDiscoverConfig = <T extends BasicDataStream>({
from,
to,
breakdownField,
selector,
}: {
locatorClient: LocatorClient;
dataStreamStat: T;
query?: Query | AggregateQuery;
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: {
Expand All @@ -209,19 +216,7 @@ const buildDiscoverConfig = <T extends BasicDataStream>({
query,
breakdownField,
columns: [],
filters: [
buildPhraseFilter(
{
name: 'data_stream.namespace',
type: 'string',
},
dataStreamStat.namespace,
{
id: dataViewId,
title: dataViewTitle,
}
),
],
filters: [],
interval: 'auto',
sort: [['@timestamp', 'desc']],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});

Expand All @@ -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;
}
}

0 comments on commit 1b56786

Please sign in to comment.