Skip to content

Commit

Permalink
skip query of detections page when we do not have .siem-signals index (
Browse files Browse the repository at this point in the history
…#74580) (#74609)

* skip query of detections page when we do not have .siem-signals index

* review I
  • Loading branch information
XavierM authored Aug 7, 2020
1 parent 557070e commit 65357b2
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { TimelineId } from '../../../common/types/timeline';
import { skipQueryForDetectionsPage } from './helpers';

describe('skipQueryForDetectionsPage', () => {
test('Make sure to NOT skip the query when it is not a timeline from a detection pages', () => {
expect(skipQueryForDetectionsPage(TimelineId.active, ['auditbeat-*', 'filebeat-*'])).toBe(
false
);
expect(
skipQueryForDetectionsPage(TimelineId.hostsPageEvents, ['auditbeat-*', 'filebeat-*'])
).toBe(false);
expect(
skipQueryForDetectionsPage(TimelineId.hostsPageExternalAlerts, ['auditbeat-*', 'filebeat-*'])
).toBe(false);
expect(
skipQueryForDetectionsPage(TimelineId.networkPageExternalAlerts, [
'auditbeat-*',
'filebeat-*',
])
).toBe(false);
});

test('Make sure to SKIP the query when it is a timeline from a detection pages without the siem-signals', () => {
expect(
skipQueryForDetectionsPage(TimelineId.detectionsPage, ['auditbeat-*', 'filebeat-*'])
).toBe(true);
expect(
skipQueryForDetectionsPage(TimelineId.detectionsRulesDetailsPage, [
'auditbeat-*',
'filebeat-*',
])
).toBe(true);
});

test('Make sure to NOT skip the query when it is a timeline from a detection pages with the siem-signals', () => {
expect(
skipQueryForDetectionsPage(TimelineId.detectionsPage, [
'auditbeat-*',
'.siem-signals-rainbow-butterfly',
])
).toBe(false);
expect(
skipQueryForDetectionsPage(TimelineId.detectionsRulesDetailsPage, [
'.siem-signals-rainbow-butterfly',
])
).toBe(false);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { TimelineId } from '../../../common/types/timeline';

export const detectionsTimelineIds = [
TimelineId.detectionsPage,
TimelineId.detectionsRulesDetailsPage,
];

export const skipQueryForDetectionsPage = (id: string, defaultIndex: string[]) =>
id != null &&
detectionsTimelineIds.some((timelineId) => timelineId === id) &&
!defaultIndex.some((di) => di.toLowerCase().startsWith('.siem-signals'));
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Query } from 'react-apollo';
import { compose, Dispatch } from 'redux';
import { connect, ConnectedProps } from 'react-redux';

import { TimelineId } from '../../../common/types/timeline';
import { DEFAULT_INDEX_KEY } from '../../../common/constants';
import { IIndexPattern } from '../../../../../../src/plugins/data/common/index_patterns';
import {
Expand All @@ -28,8 +27,7 @@ import { QueryTemplate, QueryTemplateProps } from '../../common/containers/query
import { EventType } from '../../timelines/store/timeline/model';
import { timelineQuery } from './index.gql_query';
import { timelineActions } from '../../timelines/store/timeline';

const timelineIds = [TimelineId.detectionsPage, TimelineId.detectionsRulesDetailsPage];
import { detectionsTimelineIds, skipQueryForDetectionsPage } from './helpers';

export interface TimelineArgs {
events: TimelineItem[];
Expand Down Expand Up @@ -130,6 +128,7 @@ class TimelineQueryComponent extends QueryTemplate<
query={timelineQuery}
fetchPolicy="network-only"
notifyOnNetworkStatusChange
skip={skipQueryForDetectionsPage(id, defaultIndex)}
variables={variables}
>
{({ data, loading, fetchMore, refetch }) => {
Expand Down Expand Up @@ -202,7 +201,7 @@ const makeMapStateToProps = () => {

const mapDispatchToProps = (dispatch: Dispatch) => ({
clearSignalsState: ({ id }: { id?: string }) => {
if (id != null && timelineIds.some((timelineId) => timelineId === id)) {
if (id != null && detectionsTimelineIds.some((timelineId) => timelineId === id)) {
dispatch(timelineActions.clearEventsLoading({ id }));
dispatch(timelineActions.clearEventsDeleted({ id }));
}
Expand Down

0 comments on commit 65357b2

Please sign in to comment.