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] Switches remaining rule types to use new Rule Preview API #116374

Merged
merged 35 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
70e0bdb
switches old preview to new api
dplumlee Oct 26, 2021
5ef4af0
fixes types
dplumlee Oct 27, 2021
1965bb8
updates eql and query rule type previews
dplumlee Nov 4, 2021
6e28d0f
fixes types
dplumlee Nov 8, 2021
963ed0d
fixes types
dplumlee Nov 8, 2021
0798046
adds query to preview
dplumlee Nov 9, 2021
dac95eb
fixes text errors
dplumlee Nov 9, 2021
e435c5d
updates react tests
dplumlee Nov 11, 2021
889c057
adds integration tests
dplumlee Nov 11, 2021
929cd9e
ready for es update
dplumlee Nov 15, 2021
f15835c
updates jest tests
dplumlee Nov 15, 2021
c4de39e
updates cypress tests
dplumlee Nov 16, 2021
ec6d047
updates basename for backing indices
dplumlee Nov 22, 2021
fc4bcde
fixes query obj nesting
dplumlee Nov 23, 2021
9b12937
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Nov 29, 2021
9fab7d2
fixes histogram query
dplumlee Nov 29, 2021
5ec0fcb
fix rule interval logic
dplumlee Nov 29, 2021
28416b2
fixes some tests
dplumlee Nov 30, 2021
4f286f5
fixes rests of tests
dplumlee Nov 30, 2021
cb7ef5f
addresses some comments
dplumlee Nov 30, 2021
566e42c
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Dec 1, 2021
e1e4094
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Dec 2, 2021
e71b2e1
addresses comments
dplumlee Dec 2, 2021
af31a21
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Dec 2, 2021
33f97ec
removes comment
dplumlee Dec 2, 2021
5aaf91f
fixes lookback time
dplumlee Dec 3, 2021
4145e8a
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Dec 3, 2021
5b25b3f
fixes timeframe reset bug
dplumlee Dec 3, 2021
9b3b2f3
addresses comments
dplumlee Dec 6, 2021
a4e2aff
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Dec 6, 2021
75fd94c
adds ml rule preview and fixes refresh error
dplumlee Dec 6, 2021
a60e3c7
updates jest tests for ML previews
dplumlee Dec 7, 2021
5f62ed2
updates rule data client mock
dplumlee Dec 7, 2021
1505e01
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Dec 7, 2021
0fa27da
fixes 404 error
dplumlee Dec 7, 2021
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
1 change: 0 additions & 1 deletion x-pack/plugins/rule_registry/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ export const config: PluginConfigDescriptor = {
export type RuleRegistryPluginConfig = TypeOf<typeof config.schema>;

export const INDEX_PREFIX = '.alerts' as const;
export const INDEX_PREFIX_FOR_BACKING_INDICES = '.internal.alerts' as const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could consider renaming the const to INTERNAL_PREFIX with the value ".internal" and use it on line 37 in rule_data_plugin_service/index_info.ts

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { INDEX_PREFIX, INDEX_PREFIX_FOR_BACKING_INDICES } from '../config';
import { INDEX_PREFIX } from '../config';
import { IndexOptions } from './index_options';
import { joinWithDash } from './utils';
import { joinWithDash, joinWith } from './utils';

interface ConstructorOptions {
indexOptions: IndexOptions;
Expand All @@ -23,16 +23,18 @@ interface ConstructorOptions {
export class IndexInfo {
constructor(options: ConstructorOptions) {
const { indexOptions, kibanaVersion } = options;
const { registrationContext, dataset } = indexOptions;
const { registrationContext, dataset, additionalPrefix } = indexOptions;

this.indexOptions = indexOptions;
this.kibanaVersion = kibanaVersion;
this.baseName = joinWithDash(INDEX_PREFIX, `${registrationContext}.${dataset}`);
this.baseName = additionalPrefix
dplumlee marked this conversation as resolved.
Show resolved Hide resolved
? joinWith('')(
additionalPrefix,
joinWithDash(INDEX_PREFIX, `${registrationContext}.${dataset}`)
)
: joinWithDash(INDEX_PREFIX, `${registrationContext}.${dataset}`);
this.basePattern = joinWithDash(this.baseName, '*');
this.baseNameForBackingIndices = joinWithDash(
INDEX_PREFIX_FOR_BACKING_INDICES,
`${registrationContext}.${dataset}`
);
this.baseNameForBackingIndices = joinWith('')(`.internal`, this.baseName);
dplumlee marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ export interface IndexOptions {
* @example '.siem-signals', undefined
*/
secondaryAlias?: string;

/**
* Optional prefix name that will be prepended to indices in addition to
* primary dataset and context naming convention.
*
* Currently only set to `.preview` for preview rule execution, able to be expanded
dplumlee marked this conversation as resolved.
Show resolved Hide resolved
* later with more reason
*/
additionalPrefix?: '.preview';
dplumlee marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const DEFAULT_APP_TIME_RANGE = 'securitySolution:timeDefaults' as const;
export const DEFAULT_APP_REFRESH_INTERVAL = 'securitySolution:refreshIntervalDefaults' as const;
export const DEFAULT_ALERTS_INDEX = '.alerts-security.alerts' as const;
export const DEFAULT_SIGNALS_INDEX = '.siem-signals' as const;
export const DEFAULT_PREVIEW_INDEX = '.siem-preview-signals' as const;
export const DEFAULT_PREVIEW_INDEX = '.preview.alerts-security.alerts' as const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it not possible to create these DEFAULT_ALERTS_INDEX and DEFAULT_PREVIEW_INDEX by using the logic from the rule registry server by supplying 'security' on this side only? that way we can ensure that nothing ever gets out of sync

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ecezalp I'm not sure I follow; are you asking whether we can auto-create both of these indexes by some mechanism internal to the rule registry? E.g.

// creates both the alerts index and the preview index
ruleRegistry.create('security');

?

Copy link
Contributor Author

@dplumlee dplumlee Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you're describing currently happens at runtime within a constructor in the rule registry plugin so there's no existing way to do that. I don't think it'd be a bad idea to do something like that down the line but for now, using this as the single source of truth for our needs seems like a solid approach

export const DEFAULT_LISTS_INDEX = '.lists' as const;
export const DEFAULT_ITEMS_INDEX = '.items' as const;
// The DEFAULT_MAX_SIGNALS value exists also in `x-pack/plugins/cases/common/constants.ts`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ export const previewRulesSchema = t.intersection([
createTypeSpecific,
t.type({ invocationCount: t.number }),
]);
export type PreviewRulesSchema = t.TypeOf<typeof previewRulesSchema>;

type UpdateSchema<T> = SharedUpdateSchema & T;
export type EqlUpdateSchema = UpdateSchema<t.TypeOf<typeof eqlCreateParams>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ export const DEFINE_INDEX_INPUT =

export const EQL_TYPE = '[data-test-subj="eqlRuleType"]';

export const EQL_QUERY_INPUT = '[data-test-subj="eqlQueryBarTextInput"]';
export const PREVIEW_HISTOGRAM = '[data-test-subj="preview-histogram-bar-chart"]';

export const EQL_QUERY_PREVIEW_HISTOGRAM = '[data-test-subj="queryPreviewEqlHistogram"]';
export const EQL_QUERY_INPUT = '[data-test-subj="eqlQueryBarTextInput"]';

export const EQL_QUERY_VALIDATION_SPINNER = '[data-test-subj="eql-validation-loading"]';

Expand Down Expand Up @@ -170,7 +170,7 @@ export const RISK_OVERRIDE =

export const RULES_CREATION_FORM = '[data-test-subj="stepDefineRule"]';

export const RULES_CREATION_PREVIEW = '[data-test-subj="ruleCreationQueryPreview"]';
export const RULES_CREATION_PREVIEW = '[data-test-subj="rule-preview"]';

export const RULE_DESCRIPTION_INPUT =
'[data-test-subj="detectionEngineStepAboutRuleDescription"] [data-test-subj="input"]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
DEFAULT_RISK_SCORE_INPUT,
DEFINE_CONTINUE_BUTTON,
EQL_QUERY_INPUT,
EQL_QUERY_PREVIEW_HISTOGRAM,
EQL_QUERY_VALIDATION_SPINNER,
EQL_TYPE,
FALSE_POSITIVES_INPUT,
Expand Down Expand Up @@ -92,6 +91,7 @@ import {
EMAIL_CONNECTOR_USER_INPUT,
EMAIL_CONNECTOR_PASSWORD_INPUT,
EMAIL_CONNECTOR_SERVICE_SELECTOR,
PREVIEW_HISTOGRAM,
} from '../screens/create_new_rule';
import { LOADING_INDICATOR } from '../screens/security_header';
import { TOAST_ERROR } from '../screens/shared';
Expand Down Expand Up @@ -325,12 +325,12 @@ export const fillDefineEqlRuleAndContinue = (rule: CustomRule) => {
.find(QUERY_PREVIEW_BUTTON)
.should('not.be.disabled')
.click({ force: true });
cy.get(EQL_QUERY_PREVIEW_HISTOGRAM)
cy.get(PREVIEW_HISTOGRAM)
.invoke('text')
.then((text) => {
if (text !== 'Hits') {
cy.get(RULES_CREATION_PREVIEW).find(QUERY_PREVIEW_BUTTON).click({ force: true });
cy.get(EQL_QUERY_PREVIEW_HISTOGRAM).should('contain.text', 'Hits');
cy.get(PREVIEW_HISTOGRAM).should('contain.text', 'Hits');
}
});
cy.get(TOAST_ERROR).should('not.exist');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { MatrixHistogramType } from '../../../../common/search_strategy/security
import { UpdateDateRange } from '../charts/common';
import { GlobalTimeArgs } from '../../containers/use_global_time';
import { DocValueFields } from '../../../../common/search_strategy';
import { Threshold } from '../../../detections/components/rules/query_preview';
import { FieldValueThreshold } from '../../../detections/components/rules/threshold_input';

export type MatrixHistogramMappingTypes = Record<
string,
Expand Down Expand Up @@ -77,7 +77,7 @@ export interface MatrixHistogramQueryProps {
stackByField: string;
startDate: string;
histogramType: MatrixHistogramType;
threshold?: Threshold;
threshold?: FieldValueThreshold;
skip?: boolean;
isPtrIncluded?: boolean;
includeMissingData?: boolean;
Expand Down

This file was deleted.

This file was deleted.

Loading