Skip to content

Commit fbd79ea

Browse files
authored
skip query of detections page when we do not have .siem-signals index (#74580)
* skip query of detections page when we do not have .siem-signals index * review I
1 parent 979bdaa commit fbd79ea

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 { TimelineId } from '../../../common/types/timeline';
8+
import { skipQueryForDetectionsPage } from './helpers';
9+
10+
describe('skipQueryForDetectionsPage', () => {
11+
test('Make sure to NOT skip the query when it is not a timeline from a detection pages', () => {
12+
expect(skipQueryForDetectionsPage(TimelineId.active, ['auditbeat-*', 'filebeat-*'])).toBe(
13+
false
14+
);
15+
expect(
16+
skipQueryForDetectionsPage(TimelineId.hostsPageEvents, ['auditbeat-*', 'filebeat-*'])
17+
).toBe(false);
18+
expect(
19+
skipQueryForDetectionsPage(TimelineId.hostsPageExternalAlerts, ['auditbeat-*', 'filebeat-*'])
20+
).toBe(false);
21+
expect(
22+
skipQueryForDetectionsPage(TimelineId.networkPageExternalAlerts, [
23+
'auditbeat-*',
24+
'filebeat-*',
25+
])
26+
).toBe(false);
27+
});
28+
29+
test('Make sure to SKIP the query when it is a timeline from a detection pages without the siem-signals', () => {
30+
expect(
31+
skipQueryForDetectionsPage(TimelineId.detectionsPage, ['auditbeat-*', 'filebeat-*'])
32+
).toBe(true);
33+
expect(
34+
skipQueryForDetectionsPage(TimelineId.detectionsRulesDetailsPage, [
35+
'auditbeat-*',
36+
'filebeat-*',
37+
])
38+
).toBe(true);
39+
});
40+
41+
test('Make sure to NOT skip the query when it is a timeline from a detection pages with the siem-signals', () => {
42+
expect(
43+
skipQueryForDetectionsPage(TimelineId.detectionsPage, [
44+
'auditbeat-*',
45+
'.siem-signals-rainbow-butterfly',
46+
])
47+
).toBe(false);
48+
expect(
49+
skipQueryForDetectionsPage(TimelineId.detectionsRulesDetailsPage, [
50+
'.siem-signals-rainbow-butterfly',
51+
])
52+
).toBe(false);
53+
});
54+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 { TimelineId } from '../../../common/types/timeline';
8+
9+
export const detectionsTimelineIds = [
10+
TimelineId.detectionsPage,
11+
TimelineId.detectionsRulesDetailsPage,
12+
];
13+
14+
export const skipQueryForDetectionsPage = (id: string, defaultIndex: string[]) =>
15+
id != null &&
16+
detectionsTimelineIds.some((timelineId) => timelineId === id) &&
17+
!defaultIndex.some((di) => di.toLowerCase().startsWith('.siem-signals'));

x-pack/plugins/security_solution/public/timelines/containers/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { Query } from 'react-apollo';
1111
import { compose, Dispatch } from 'redux';
1212
import { connect, ConnectedProps } from 'react-redux';
1313

14-
import { TimelineId } from '../../../common/types/timeline';
1514
import { DEFAULT_INDEX_KEY } from '../../../common/constants';
1615
import { IIndexPattern } from '../../../../../../src/plugins/data/common/index_patterns';
1716
import {
@@ -28,8 +27,7 @@ import { QueryTemplate, QueryTemplateProps } from '../../common/containers/query
2827
import { EventType } from '../../timelines/store/timeline/model';
2928
import { timelineQuery } from './index.gql_query';
3029
import { timelineActions } from '../../timelines/store/timeline';
31-
32-
const timelineIds = [TimelineId.detectionsPage, TimelineId.detectionsRulesDetailsPage];
30+
import { detectionsTimelineIds, skipQueryForDetectionsPage } from './helpers';
3331

3432
export interface TimelineArgs {
3533
events: TimelineItem[];
@@ -130,6 +128,7 @@ class TimelineQueryComponent extends QueryTemplate<
130128
query={timelineQuery}
131129
fetchPolicy="network-only"
132130
notifyOnNetworkStatusChange
131+
skip={skipQueryForDetectionsPage(id, defaultIndex)}
133132
variables={variables}
134133
>
135134
{({ data, loading, fetchMore, refetch }) => {
@@ -202,7 +201,7 @@ const makeMapStateToProps = () => {
202201

203202
const mapDispatchToProps = (dispatch: Dispatch) => ({
204203
clearSignalsState: ({ id }: { id?: string }) => {
205-
if (id != null && timelineIds.some((timelineId) => timelineId === id)) {
204+
if (id != null && detectionsTimelineIds.some((timelineId) => timelineId === id)) {
206205
dispatch(timelineActions.clearEventsLoading({ id }));
207206
dispatch(timelineActions.clearEventsDeleted({ id }));
208207
}

0 commit comments

Comments
 (0)