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][Alerts] Alert suppression time window #148868

Merged
merged 31 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d48454d
WIP
marshallmain Dec 15, 2022
51776bc
Merge branch 'main' of github.com:elastic/kibana into alert-suppressi…
marshallmain Jan 5, 2023
382f0c3
Add radio button to rule create, implement alert update logic
marshallmain Jan 11, 2023
bf6ec62
Add explicit index to bulk updates
marshallmain Jan 12, 2023
b210b3b
Fix deduplication bug with null values, add tests
marshallmain Jan 13, 2023
5d52a88
Cleanup
marshallmain Jan 13, 2023
6743a5d
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 13, 2023
899d160
Fix types
marshallmain Jan 13, 2023
3a6d854
Merge branch 'main' into alert-suppression-time-window
marshallmain Jan 13, 2023
f39021f
Fix more types
marshallmain Jan 13, 2023
7d7b504
Fix unit tests
marshallmain Jan 13, 2023
60b8490
Fix test data
marshallmain Jan 13, 2023
bea5a14
Merge branch 'main' into alert-suppression-time-window
marshallmain Jan 13, 2023
14037fd
Add real rule execution test for suppression
marshallmain Jan 13, 2023
57cb8cf
Merge branch 'main' into alert-suppression-time-window
marshallmain Jan 13, 2023
b2d2df2
Merge branch 'main' into alert-suppression-time-window
marshallmain Jan 17, 2023
feb371f
Move suppression types to rule registry
marshallmain Jan 18, 2023
79e81a9
Apply Garrett's fix
marshallmain Jan 24, 2023
d2c586b
Add timestamp override and max_signals tests, move schema
marshallmain Jan 24, 2023
d654699
Merge branch 'main' of github.com:elastic/kibana into alert-suppressi…
marshallmain Jan 25, 2023
0c0b157
Fix import
marshallmain Jan 25, 2023
ce3a624
Fix technical field names post merge
marshallmain Jan 25, 2023
424d74b
Merge branch 'main' into alert-suppression-time-window
marshallmain Jan 25, 2023
6e6c572
Helper funcs in persistence wrapper, fix license check in UI
marshallmain Jan 25, 2023
969253f
Exclude closed alerts from suppression update logic
marshallmain Jan 26, 2023
9b98237
PR comments
marshallmain Jan 27, 2023
6052cc9
Merge branch 'main' of github.com:elastic/kibana into alert-suppressi…
marshallmain Jan 27, 2023
3f1ecb2
Update x-pack/plugins/rule_registry/server/utils/create_persistence_r…
marshallmain Jan 27, 2023
487f56b
Modify tests to account for alert start and enable rule timestamp bug
marshallmain Jan 27, 2023
5650d6f
Fix tests
marshallmain Jan 30, 2023
1ca4f87
Merge branch 'main' into alert-suppression-time-window
marshallmain Jan 30, 2023
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
5 changes: 5 additions & 0 deletions packages/kbn-rule-data-utils/src/default_alerts_as_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const ALERT_FLAPPING = `${ALERT_NAMESPACE}.flapping` as const;
// kibana.alert.id - alert ID, also known as alert instance ID
const ALERT_ID = `${ALERT_NAMESPACE}.id` as const;

// kibana.alert.last_detected - timestamp when the alert was last seen
const ALERT_LAST_DETECTED = `${ALERT_NAMESPACE}.last_detected` as const;

// kibana.alert.reason - human readable reason that this alert is active
const ALERT_REASON = `${ALERT_NAMESPACE}.reason` as const;

Expand Down Expand Up @@ -91,6 +94,7 @@ const fields = {
ALERT_END,
ALERT_FLAPPING,
ALERT_ID,
ALERT_LAST_DETECTED,
ALERT_REASON,
ALERT_RULE_CATEGORY,
ALERT_RULE_CONSUMER,
Expand All @@ -116,6 +120,7 @@ export {
ALERT_END,
ALERT_FLAPPING,
ALERT_ID,
ALERT_LAST_DETECTED,
ALERT_REASON,
ALERT_RULE_CATEGORY,
ALERT_RULE_CONSUMER,
Expand Down
33 changes: 33 additions & 0 deletions x-pack/plugins/rule_registry/common/schemas/8.6.0/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import {
ALERT_SUPPRESSION_TERMS,
ALERT_SUPPRESSION_START,
ALERT_SUPPRESSION_END,
ALERT_SUPPRESSION_DOCS_COUNT,
} from '@kbn/rule-data-utils';
import { AlertWithCommonFields800 } from '../8.0.0';

/* DO NOT MODIFY THIS SCHEMA TO ADD NEW FIELDS. These types represent the alerts that shipped in 8.0.0.
Any changes to these types should be bug fixes so the types more accurately represent the alerts from 8.0.0.

If you are adding new fields for a new release of Kibana, create a new sibling folder to this one
for the version to be released and add the field(s) to the schema in that folder.

Then, update `../index.ts` to import from the new folder that has the latest schemas, add the
new schemas to the union of all alert schemas, and re-export the new schemas as the `*Latest` schemas.
*/

export interface SuppressionFields860 {
[ALERT_SUPPRESSION_TERMS]: Array<{ field: string; value: string | number | null }>;
[ALERT_SUPPRESSION_START]: Date;
[ALERT_SUPPRESSION_END]: Date;
[ALERT_SUPPRESSION_DOCS_COUNT]: number;
}

export type AlertWithSuppressionFields860<T> = AlertWithCommonFields800<T> & SuppressionFields860;
8 changes: 8 additions & 0 deletions x-pack/plugins/rule_registry/common/schemas/8.7.0/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {
TIMESTAMP,
ALERT_RULE_PARAMETERS,
} from '@kbn/rule-data-utils';
import { AlertWithCommonFields800 } from '../8.0.0';

import { SuppressionFields860 } from '../8.6.0';

/* DO NOT MODIFY THIS SCHEMA TO ADD NEW FIELDS. These types represent the alerts that shipped in 8.7.0.
Any changes to these types should be bug fixes so the types more accurately represent the alerts from 8.7.0.
Expand All @@ -32,6 +35,11 @@ Then, update `../index.ts` to import from the new folder that has the latest sch
new schemas to the union of all alert schemas, and re-export the new schemas as the `*Latest` schemas.
*/

export interface SuppressionFields870 extends SuppressionFields860 {
[ALERT_INSTANCE_ID]: string;
}

export type AlertWithSuppressionFields870<T> = AlertWithCommonFields800<T> & SuppressionFields870;
const commonAlertIdFieldNames = [ALERT_INSTANCE_ID, ALERT_UUID];
export type CommonAlertIdFieldName870 = Values<typeof commonAlertIdFieldNames>;

Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/rule_registry/common/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import type {
AlertWithCommonFields870,
} from './8.7.0';

import type { AlertWithSuppressionFields870, SuppressionFields870 } from './8.7.0';

export type {
AlertWithSuppressionFields870 as AlertWithSuppressionFieldsLatest,
SuppressionFields870 as SuppressionFieldsLatest,
CommonAlertFieldName870 as CommonAlertFieldNameLatest,
CommonAlertIdFieldName870 as CommonAlertIdFieldNameLatest,
CommonAlertFields870 as CommonAlertFieldsLatest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,18 @@ export class RuleDataClient implements IRuleDataClient {
};

return {
search: async <TSearchRequest extends ESSearchRequest>(
search: async <
TSearchRequest extends ESSearchRequest,
TAlertDoc = Partial<ParsedTechnicalFields & ParsedExperimentalFields>
>(
request: TSearchRequest
): Promise<
ESSearchResponse<Partial<ParsedTechnicalFields & ParsedExperimentalFields>, TSearchRequest>
> => {
): Promise<ESSearchResponse<TAlertDoc, TSearchRequest>> => {
try {
const clusterClient = await waitUntilReady();
return (await clusterClient.search({
...request,
index: indexPattern,
})) as unknown as ESSearchResponse<
Partial<ParsedTechnicalFields & ParsedExperimentalFields>,
TSearchRequest
>;
})) as unknown as ESSearchResponse<TAlertDoc, TSearchRequest>;
} catch (err) {
this.options.logger.error(`Error performing search in RuleDataClient - ${err.message}`);
throw err;
Expand Down
9 changes: 5 additions & 4 deletions x-pack/plugins/rule_registry/server/rule_data_client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ export interface IRuleDataClient {
}

export interface IRuleDataReader {
search<TSearchRequest extends ESSearchRequest>(
search<
TSearchRequest extends ESSearchRequest,
TAlertDoc = Partial<ParsedTechnicalFields & ParsedExperimentalFields>
>(
request: TSearchRequest
): Promise<
ESSearchResponse<Partial<ParsedTechnicalFields & ParsedExperimentalFields>, TSearchRequest>
>;
): Promise<ESSearchResponse<TAlertDoc, TSearchRequest>>;

getDynamicIndexPattern(target?: string): Promise<{
title: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PersistenceServices } from './persistence_types';
export const createPersistenceServicesMock = (): jest.Mocked<PersistenceServices> => {
return {
alertWithPersistence: jest.fn(),
alertWithSuppression: jest.fn(),
};
};

Expand Down
Loading