Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution][Detections][Threshold Rules] Threshold Rule Bug Fixes #84918

Merged
merged 25 commits into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0f8c746
Move threshold dupe detection logic to its own function
madirey Nov 30, 2020
679a958
Merge branch 'master' of github.com:elastic/kibana into threshold-fields
madirey Nov 30, 2020
f741972
Minor fixup
madirey Nov 30, 2020
4c3c7bb
Merge branch 'master' of github.com:elastic/kibana into threshold-fields
madirey Dec 1, 2020
da111d0
Refactor and remove property injection for threshold signals
madirey Dec 2, 2020
a4cc0c8
Merge branch 'master' of github.com:elastic/kibana into threshold-fields
madirey Dec 2, 2020
539fa49
Only show aggregatable fields for threshold rule grouping
madirey Dec 3, 2020
788aa13
Merge branch 'master' of github.com:elastic/kibana into threshold-fields
madirey Dec 3, 2020
6482374
Add threshold rule kql filter to timeline
madirey Dec 3, 2020
7e2ca17
Remove outdated getThresholdSignalQueryFields tests
madirey Dec 3, 2020
deefbdf
Merge branch 'master' of github.com:elastic/kibana into threshold-fields
madirey Dec 3, 2020
220ed6f
Merge branch 'master' of github.com:elastic/kibana into threshold-fields
madirey Dec 7, 2020
550da9d
Merge master, fix conflicts
madirey Dec 15, 2020
6f9d468
Filter aggregatable fields on client
madirey Dec 16, 2020
01e4340
Merge branch 'master' of github.com:elastic/kibana into threshold-fields
madirey Dec 16, 2020
6e94e3b
Revert "Only show aggregatable fields for threshold rule grouping"
madirey Dec 16, 2020
04b1432
Fix bug with incorrect calculation of threshold signal dupes when no …
madirey Dec 16, 2020
a08f1a0
Merge branch 'master' of github.com:elastic/kibana into threshold-fields
madirey Dec 16, 2020
81b069f
Merge branch 'master' of github.com:elastic/kibana into threshold-fields
madirey Dec 17, 2020
25efc01
Revert "Add threshold rule kql filter to timeline"
madirey Dec 17, 2020
2e6cf19
Add test skeleton
madirey Dec 17, 2020
ad495ab
Merge branch 'master' of github.com:elastic/kibana into threshold-fields
madirey Dec 17, 2020
7dc1e97
Finish tests
madirey Dec 18, 2020
64781a8
Merge branch 'master' of github.com:elastic/kibana into threshold-fields
madirey Dec 20, 2020
8eb8404
Address comment
madirey Dec 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ export class IndexPatternsFetcher {
pattern: string | string[];
metaFields?: string[];
fieldCapsOptions?: { allow_no_indices: boolean };
filters?: { aggregatable: boolean };
type?: string;
rollupIndex?: string;
}): Promise<FieldDescriptor[]> {
const { pattern, metaFields, fieldCapsOptions, type, rollupIndex } = options;
const { pattern, metaFields, fieldCapsOptions, filters, type, rollupIndex } = options;
const fieldCapsResponse = await getFieldCapabilities(
this.elasticsearchClient,
pattern,
metaFields,
filters,
{
allow_no_indices: fieldCapsOptions
? fieldCapsOptions.allow_no_indices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export async function getFieldCapabilities(
callCluster: ElasticsearchClient,
indices: string | string[] = [],
metaFields: string[] = [],
filters?: { aggregatable: boolean },
fieldCapsOptions?: { allow_no_indices: boolean }
) {
const esFieldCaps = await callFieldCapsApi(callCluster, indices, fieldCapsOptions);
Expand Down Expand Up @@ -69,7 +70,8 @@ export async function getFieldCapabilities(
readFromDocValues: false,
})
)
.map(mergeOverrides);
.map(mergeOverrides)
.filter((field) => (filters?.aggregatable ? field.aggregatable === true : true));

return sortBy(allFieldsUnsorted, 'name');
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const useField = <T, FormType = FormData, I = T>(
) => {
const {
type = FIELD_TYPES.TEXT,
defaultValue = '', // The value to use a fallback mecanism when no initial value is passed
defaultValue = '', // The value to use a fallback mechanism when no initial value is passed
initialValue = config.defaultValue ?? '', // The value explicitly passed
isIncludedInOutput = true,
label = '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type BeatFields = Record<string, FieldInfo>;
export interface IndexFieldsStrategyRequest extends IEsSearchRequest {
indices: string[];
onlyCheckIfIndicesExist: boolean;
filters?: { aggregatable: boolean };
}

export interface IndexFieldsStrategyResponse extends IEsSearchResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ interface FetchIndexReturn {

export const useFetchIndex = (
indexNames: string[],
onlyCheckIfIndicesExist: boolean = false
onlyCheckIfIndicesExist: boolean = false,
filters?: { aggregatable: boolean }
): [boolean, FetchIndexReturn] => {
const { data, notifications } = useKibana().services;
const abortCtrl = useRef(new AbortController());
Expand All @@ -144,7 +145,7 @@ export const useFetchIndex = (
setLoading(true);
const searchSubscription$ = data.search
.search<IndexFieldsStrategyRequest, IndexFieldsStrategyResponse>(
{ indices: iNames, onlyCheckIfIndicesExist },
{ indices: iNames, onlyCheckIfIndicesExist, filters },
{
abortSignal: abortCtrl.current.signal,
strategy: 'securitySolutionIndexFields',
Expand Down Expand Up @@ -193,7 +194,7 @@ export const useFetchIndex = (
abortCtrl.current.abort();
};
},
[data.search, notifications.toasts, onlyCheckIfIndicesExist]
[data.search, filters, notifications.toasts, onlyCheckIfIndicesExist]
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { get, getOr, isEmpty, find } from 'lodash/fp';
import moment from 'moment';
import { i18n } from '@kbn/i18n';

import { buildQueryFilter, Filter } from '../../../../../../../src/plugins/data/common';
import { TimelineId, TimelineStatus, TimelineType } from '../../../../common/types/timeline';
import { updateAlertStatus } from '../../containers/detection_engine/alerts/api';
import { SendAlertToTimelineActionProps, UpdateAlertStatusActionProps } from './types';
Expand Down Expand Up @@ -289,6 +290,13 @@ export const sendAlertToTimelineAction = async ({
end: to,
},
eventType: 'all',
filters: [
buildQueryFilter(
ecsData.signal?.rule?.filters,
ecsData._index ?? '',
(ecsData.signal?.rule?.filters as Filter).meta?.alias ?? ''
),
],
kqlQuery: {
filterQuery: {
kuery: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ const StepDefineRuleComponent: FC<StepDefineRuleProps> = ({
const ruleType = formRuleType || initialState.ruleType;
const queryBarQuery =
formQuery != null ? formQuery.query.query : '' || initialState.queryBar.query.query;
const [indexPatternsLoading, { browserFields, indexPatterns }] = useFetchIndex(index);
const filters = isThresholdRule(ruleType) ? { aggregatable: true } : undefined;
const [indexPatternsLoading, { browserFields, indexPatterns }] = useFetchIndex(
index,
false,
filters
);
const [
threatIndexPatternsLoading,
{ browserFields: threatBrowserFields, indexPatterns: threatIndexPatterns },
Expand Down
Loading