Skip to content

Commit a91209c

Browse files
authored
[Logs UI] Anomalies page dataset filtering (#71110)
Adds dataset filtering to logs anomalies page
1 parent 7b026bb commit a91209c

28 files changed

+506
-129
lines changed

x-pack/plugins/infra/common/http_api/log_analysis/results/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export * from './log_entry_category_examples';
1010
export * from './log_entry_rate';
1111
export * from './log_entry_examples';
1212
export * from './log_entry_anomalies';
13+
export * from './log_entry_anomalies_datasets';

x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ export const getLogEntryAnomaliesRequestPayloadRT = rt.type({
128128
pagination: paginationRT,
129129
// Sort properties
130130
sort: sortRT,
131+
// Dataset filters
132+
datasets: rt.array(rt.string),
131133
}),
132134
]),
133135
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import * as rt from 'io-ts';
8+
9+
import {
10+
badRequestErrorRT,
11+
forbiddenErrorRT,
12+
timeRangeRT,
13+
routeTimingMetadataRT,
14+
} from '../../shared';
15+
16+
export const LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_DATASETS_PATH =
17+
'/api/infra/log_analysis/results/log_entry_anomalies_datasets';
18+
19+
/**
20+
* request
21+
*/
22+
23+
export const getLogEntryAnomaliesDatasetsRequestPayloadRT = rt.type({
24+
data: rt.type({
25+
// the id of the source configuration
26+
sourceId: rt.string,
27+
// the time range to fetch the anomalies datasets from
28+
timeRange: timeRangeRT,
29+
}),
30+
});
31+
32+
export type GetLogEntryAnomaliesDatasetsRequestPayload = rt.TypeOf<
33+
typeof getLogEntryAnomaliesDatasetsRequestPayloadRT
34+
>;
35+
36+
/**
37+
* response
38+
*/
39+
40+
export const getLogEntryAnomaliesDatasetsSuccessReponsePayloadRT = rt.intersection([
41+
rt.type({
42+
data: rt.type({
43+
datasets: rt.array(rt.string),
44+
}),
45+
}),
46+
rt.partial({
47+
timing: routeTimingMetadataRT,
48+
}),
49+
]);
50+
51+
export type GetLogEntryAnomaliesDatasetsSuccessResponsePayload = rt.TypeOf<
52+
typeof getLogEntryAnomaliesDatasetsSuccessReponsePayloadRT
53+
>;
54+
55+
export const getLogEntryAnomaliesDatasetsResponsePayloadRT = rt.union([
56+
getLogEntryAnomaliesDatasetsSuccessReponsePayloadRT,
57+
badRequestErrorRT,
58+
forbiddenErrorRT,
59+
]);
60+
61+
export type GetLogEntryAnomaliesDatasetsReponsePayload = rt.TypeOf<
62+
typeof getLogEntryAnomaliesDatasetsResponsePayloadRT
63+
>;

x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_rate.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ export const LOG_ANALYSIS_GET_LOG_ENTRY_RATE_PATH =
1616
*/
1717

1818
export const getLogEntryRateRequestPayloadRT = rt.type({
19-
data: rt.type({
20-
bucketDuration: rt.number,
21-
sourceId: rt.string,
22-
timeRange: timeRangeRT,
23-
}),
19+
data: rt.intersection([
20+
rt.type({
21+
bucketDuration: rt.number,
22+
sourceId: rt.string,
23+
timeRange: timeRangeRT,
24+
}),
25+
rt.partial({
26+
datasets: rt.array(rt.string),
27+
}),
28+
]),
2429
});
2530

2631
export type GetLogEntryRateRequestPayload = rt.TypeOf<typeof getLogEntryRateRequestPayloadRT>;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui';
88
import { i18n } from '@kbn/i18n';
99
import React, { useCallback, useMemo } from 'react';
1010

11-
import { getFriendlyNameForPartitionId } from '../../../../../../common/log_analysis';
11+
import { getFriendlyNameForPartitionId } from '../../../../common/log_analysis';
1212

1313
type DatasetOptionProps = EuiComboBoxOptionOption<string>;
1414

@@ -51,7 +51,7 @@ export const DatasetsSelector: React.FunctionComponent<{
5151
};
5252

5353
const datasetFilterPlaceholder = i18n.translate(
54-
'xpack.infra.logs.logEntryCategories.datasetFilterPlaceholder',
54+
'xpack.infra.logs.analysis.datasetFilterPlaceholder',
5555
{
5656
defaultMessage: 'Filter by datasets',
5757
}

x-pack/plugins/infra/public/pages/logs/log_entry_categories/sections/top_categories/top_categories_section.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { BetaBadge } from '../../../../../components/beta_badge';
1414
import { LoadingOverlayWrapper } from '../../../../../components/loading_overlay_wrapper';
1515
import { RecreateJobButton } from '../../../../../components/logging/log_analysis_job_status';
1616
import { AnalyzeInMlButton } from '../../../../../components/logging/log_analysis_results';
17-
import { DatasetsSelector } from './datasets_selector';
17+
import { DatasetsSelector } from '../../../../../components/logging/log_analysis_results/datasets_selector';
1818
import { TopCategoriesTable } from './top_categories_table';
1919

2020
export const TopCategoriesSection: React.FunctionComponent<{

x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
StringTimeRange,
2828
useLogAnalysisResultsUrlState,
2929
} from './use_log_entry_rate_results_url_state';
30+
import { DatasetsSelector } from '../../../components/logging/log_analysis_results/datasets_selector';
3031

3132
export const SORT_DEFAULTS = {
3233
direction: 'desc' as const,
@@ -80,11 +81,14 @@ export const LogEntryRateResultsContent: React.FunctionComponent = () => {
8081
[queryTimeRange.value.endTime, queryTimeRange.value.startTime]
8182
);
8283

84+
const [selectedDatasets, setSelectedDatasets] = useState<string[]>([]);
85+
8386
const { getLogEntryRate, isLoading, logEntryRate } = useLogEntryRateResults({
8487
sourceId,
8588
startTime: queryTimeRange.value.startTime,
8689
endTime: queryTimeRange.value.endTime,
8790
bucketDuration,
91+
filteredDatasets: selectedDatasets,
8892
});
8993

9094
const {
@@ -97,12 +101,15 @@ export const LogEntryRateResultsContent: React.FunctionComponent = () => {
97101
changePaginationOptions,
98102
sortOptions,
99103
paginationOptions,
104+
datasets,
105+
isLoadingDatasets,
100106
} = useLogEntryAnomaliesResults({
101107
sourceId,
102108
startTime: queryTimeRange.value.startTime,
103109
endTime: queryTimeRange.value.endTime,
104110
defaultSortOptions: SORT_DEFAULTS,
105111
defaultPaginationOptions: PAGINATION_DEFAULTS,
112+
filteredDatasets: selectedDatasets,
106113
});
107114

108115
const handleQueryTimeRangeChange = useCallback(
@@ -175,7 +182,7 @@ export const LogEntryRateResultsContent: React.FunctionComponent = () => {
175182

176183
useEffect(() => {
177184
getLogEntryRate();
178-
}, [getLogEntryRate, queryTimeRange.lastChangedTime]);
185+
}, [getLogEntryRate, selectedDatasets, queryTimeRange.lastChangedTime]);
179186

180187
useInterval(
181188
() => {
@@ -191,7 +198,15 @@ export const LogEntryRateResultsContent: React.FunctionComponent = () => {
191198
<ResultsContentPage>
192199
<EuiFlexGroup direction="column">
193200
<EuiFlexItem grow={false}>
194-
<EuiFlexGroup justifyContent="flexEnd">
201+
<EuiFlexGroup justifyContent="spaceBetween">
202+
<EuiFlexItem>
203+
<DatasetsSelector
204+
availableDatasets={datasets}
205+
isLoading={isLoadingDatasets}
206+
selectedDatasets={selectedDatasets}
207+
onChangeDatasetSelection={setSelectedDatasets}
208+
/>
209+
</EuiFlexItem>
195210
<EuiFlexItem grow={false}>
196211
<EuiSuperDatePicker
197212
start={selectedTimeRange.startTime}

x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_anomalies.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export const callGetLogEntryAnomaliesAPI = async (
1818
startTime: number,
1919
endTime: number,
2020
sort: Sort,
21-
pagination: Pagination
21+
pagination: Pagination,
22+
datasets?: string[]
2223
) => {
2324
const response = await npStart.http.fetch(LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_PATH, {
2425
method: 'POST',
@@ -32,6 +33,7 @@ export const callGetLogEntryAnomaliesAPI = async (
3233
},
3334
sort,
3435
pagination,
36+
datasets,
3537
},
3638
})
3739
),
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { npStart } from '../../../../legacy_singletons';
8+
import { decodeOrThrow } from '../../../../../common/runtime_types';
9+
import {
10+
getLogEntryAnomaliesDatasetsRequestPayloadRT,
11+
getLogEntryAnomaliesDatasetsSuccessReponsePayloadRT,
12+
LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_DATASETS_PATH,
13+
} from '../../../../../common/http_api/log_analysis';
14+
15+
export const callGetLogEntryAnomaliesDatasetsAPI = async (
16+
sourceId: string,
17+
startTime: number,
18+
endTime: number
19+
) => {
20+
const response = await npStart.http.fetch(LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_DATASETS_PATH, {
21+
method: 'POST',
22+
body: JSON.stringify(
23+
getLogEntryAnomaliesDatasetsRequestPayloadRT.encode({
24+
data: {
25+
sourceId,
26+
timeRange: {
27+
startTime,
28+
endTime,
29+
},
30+
},
31+
})
32+
),
33+
});
34+
35+
return decodeOrThrow(getLogEntryAnomaliesDatasetsSuccessReponsePayloadRT)(response);
36+
};

x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_rate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const callGetLogEntryRateAPI = async (
1919
sourceId: string,
2020
startTime: number,
2121
endTime: number,
22-
bucketDuration: number
22+
bucketDuration: number,
23+
datasets?: string[]
2324
) => {
2425
const response = await npStart.http.fetch(LOG_ANALYSIS_GET_LOG_ENTRY_RATE_PATH, {
2526
method: 'POST',
@@ -32,6 +33,7 @@ export const callGetLogEntryRateAPI = async (
3233
endTime,
3334
},
3435
bucketDuration,
36+
datasets,
3537
},
3638
})
3739
),

0 commit comments

Comments
 (0)