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

[8.x] [SecuritySolution] Add enrichPolicyExecutionInterval to entity enablement and init APIs (#207374) #208223

Merged
merged 4 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions oas_docs/output/kibana.serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7567,6 +7567,8 @@ paths:
schema:
type: object
properties:
enrichPolicyExecutionInterval:
$ref: '#/components/schemas/Security_Entity_Analytics_API_Interval'
fieldHistoryLength:
default: 10
description: The number of historical values to keep for each field.
Expand Down Expand Up @@ -46875,6 +46877,11 @@ components:
required:
- dsl
- response
Security_Entity_Analytics_API_Interval:
description: Interval in which enrich policy runs. For example, `"1h"` means the rule runs every hour.
example: 1h
pattern: ^[1-9]\d*[smh]$
type: string
Security_Entity_Analytics_API_RiskEngineScheduleNowErrorResponse:
type: object
properties:
Expand Down
13 changes: 13 additions & 0 deletions oas_docs/output/kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13033,6 +13033,12 @@ paths:
schema:
type: object
properties:
enrichPolicyExecutionInterval:
$ref: '#/components/schemas/Security_Entity_Analytics_API_Interval'
entityTypes:
items:
$ref: '#/components/schemas/Security_Entity_Analytics_API_EntityType'
type: array
fieldHistoryLength:
default: 10
description: The number of historical values to keep for each field.
Expand Down Expand Up @@ -13144,6 +13150,8 @@ paths:
schema:
type: object
properties:
enrichPolicyExecutionInterval:
$ref: '#/components/schemas/Security_Entity_Analytics_API_Interval'
fieldHistoryLength:
default: 10
description: The number of historical values to keep for each field.
Expand Down Expand Up @@ -35275,6 +35283,11 @@ components:
required:
- dsl
- response
Security_Entity_Analytics_API_Interval:
description: Interval in which enrich policy runs. For example, `"1h"` means the rule runs every hour.
example: 1h
pattern: ^[1-9]\d*[smh]$
type: string
Security_Entity_Analytics_API_RiskEngineScheduleNowErrorResponse:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ export const InspectQuery = z.object({
response: z.array(z.string()),
dsl: z.array(z.string()),
});

/**
* Interval in which enrich policy runs. For example, `"1h"` means the rule runs every hour.
*/
export type Interval = z.infer<typeof Interval>;
export const Interval = z.string().regex(/^[1-9]\d*[smh]$/);
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,8 @@ components:
required:
- dsl
- response
Interval:
type: string
description: Interval in which enrich policy runs. For example, `"1h"` means the rule runs every hour.
pattern: '^[1-9]\d*[smh]$' # any number except zero followed by one of the suffixes 's', 'm', 'h'
example: '1h'
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { z } from '@kbn/zod';

import { IndexPattern, EngineDescriptor } from './common.gen';
import { IndexPattern, EntityType, Interval, EngineDescriptor } from './common.gen';

export type InitEntityStoreRequestBody = z.infer<typeof InitEntityStoreRequestBody>;
export const InitEntityStoreRequestBody = z.object({
Expand All @@ -26,6 +26,8 @@ export const InitEntityStoreRequestBody = z.object({
fieldHistoryLength: z.number().int().optional().default(10),
indexPattern: IndexPattern.optional(),
filter: z.string().optional(),
entityTypes: z.array(EntityType).optional(),
enrichPolicyExecutionInterval: Interval.optional(),
});
export type InitEntityStoreRequestBodyInput = z.input<typeof InitEntityStoreRequestBody>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ paths:
$ref: './common.schema.yaml#/components/schemas/IndexPattern'
filter:
type: string
entityTypes:
type: array
items:
$ref: './common.schema.yaml#/components/schemas/EntityType'
enrichPolicyExecutionInterval:
$ref: './common.schema.yaml#/components/schemas/Interval'
responses:
'200':
description: Successful response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { z } from '@kbn/zod';

import { EntityType, IndexPattern, EngineDescriptor } from '../common.gen';
import { EntityType, IndexPattern, Interval, EngineDescriptor } from '../common.gen';

export type InitEntityEngineRequestParams = z.infer<typeof InitEntityEngineRequestParams>;
export const InitEntityEngineRequestParams = z.object({
Expand All @@ -35,6 +35,7 @@ export const InitEntityEngineRequestBody = z.object({
fieldHistoryLength: z.number().int().optional().default(10),
indexPattern: IndexPattern.optional(),
filter: z.string().optional(),
enrichPolicyExecutionInterval: Interval.optional(),
});
export type InitEntityEngineRequestBodyInput = z.input<typeof InitEntityEngineRequestBody>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ paths:
$ref: '../common.schema.yaml#/components/schemas/IndexPattern'
filter:
type: string
enrichPolicyExecutionInterval:
$ref: '../common.schema.yaml#/components/schemas/Interval'
responses:
'200':
description: Successful response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ paths:
schema:
type: object
properties:
enrichPolicyExecutionInterval:
$ref: '#/components/schemas/Interval'
entityTypes:
items:
$ref: '#/components/schemas/EntityType'
type: array
fieldHistoryLength:
default: 10
description: The number of historical values to keep for each field.
Expand Down Expand Up @@ -418,6 +424,8 @@ paths:
schema:
type: object
properties:
enrichPolicyExecutionInterval:
$ref: '#/components/schemas/Interval'
fieldHistoryLength:
default: 10
description: The number of historical values to keep for each field.
Expand Down Expand Up @@ -1134,6 +1142,13 @@ components:
required:
- dsl
- response
Interval:
description: >-
Interval in which enrich policy runs. For example, `"1h"` means the rule
runs every hour.
example: 1h
pattern: '^[1-9]\d*[smh]$'
type: string
RiskEngineScheduleNowErrorResponse:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ paths:
schema:
type: object
properties:
enrichPolicyExecutionInterval:
$ref: '#/components/schemas/Interval'
entityTypes:
items:
$ref: '#/components/schemas/EntityType'
type: array
fieldHistoryLength:
default: 10
description: The number of historical values to keep for each field.
Expand Down Expand Up @@ -418,6 +424,8 @@ paths:
schema:
type: object
properties:
enrichPolicyExecutionInterval:
$ref: '#/components/schemas/Interval'
fieldHistoryLength:
default: 10
description: The number of historical values to keep for each field.
Expand Down Expand Up @@ -1134,6 +1142,13 @@ components:
required:
- dsl
- response
Interval:
description: >-
Interval in which enrich policy runs. For example, `"1h"` means the rule
runs every hour.
example: 1h
pattern: '^[1-9]\d*[smh]$'
type: string
RiskEngineScheduleNowErrorResponse:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import {
import { CRITICALITY_VALUES } from '../asset_criticality/constants';
import { createEngineDescription } from './installation/engine_description';
import { convertToEntityManagerDefinition } from './entity_definitions/entity_manager_conversion';
import { DEFAULT_INTERVAL } from './task/constants';

// Workaround. TransformState type is wrong. The health type should be: TransformHealth from '@kbn/transform-plugin/common/types/transform_stats'
export interface TransformHealth extends estypes.TransformGetTransformStatsTransformStatsHealth {
Expand Down Expand Up @@ -200,7 +201,13 @@ export class EntityStoreDataClient {
}

public async enable(
{ indexPattern = '', filter = '', fieldHistoryLength = 10 }: InitEntityStoreRequestBody,
{
indexPattern = '',
filter = '',
fieldHistoryLength = 10,
entityTypes,
enrichPolicyExecutionInterval,
}: InitEntityStoreRequestBody,
{ pipelineDebugMode = false }: { pipelineDebugMode?: boolean } = {}
): Promise<InitEntityStoreResponse> {
if (!this.options.taskManager) {
Expand All @@ -216,7 +223,11 @@ export class EntityStoreDataClient {

const promises = enginesTypes.map((entity) =>
run(() =>
this.init(entity, { indexPattern, filter, fieldHistoryLength }, { pipelineDebugMode })
this.init(
entity,
{ indexPattern, filter, fieldHistoryLength, enrichPolicyExecutionInterval },
{ pipelineDebugMode }
)
)
);

Expand Down Expand Up @@ -274,7 +285,12 @@ export class EntityStoreDataClient {

public async init(
entityType: EntityType,
{ indexPattern = '', filter = '', fieldHistoryLength = 10 }: InitEntityEngineRequestBody,
{
indexPattern = '',
filter = '',
fieldHistoryLength = 10,
enrichPolicyExecutionInterval = DEFAULT_INTERVAL,
}: InitEntityEngineRequestBody,
{ pipelineDebugMode = false }: { pipelineDebugMode?: boolean } = {}
): Promise<InitEntityEngineResponse> {
const { experimentalFeatures } = this.options;
Expand Down Expand Up @@ -330,6 +346,7 @@ export class EntityStoreDataClient {
this.asyncSetup(
entityType,
fieldHistoryLength,
enrichPolicyExecutionInterval,
this.options.taskManager,
indexPattern,
filter,
Expand All @@ -345,6 +362,7 @@ export class EntityStoreDataClient {
private async asyncSetup(
entityType: EntityType,
fieldHistoryLength: number,
enrichPolicyExecutionInterval: string,
taskManager: TaskManagerStartContract,
indexPattern: string,
filter: string,
Expand Down Expand Up @@ -425,6 +443,7 @@ export class EntityStoreDataClient {
namespace,
logger,
taskManager,
interval: enrichPolicyExecutionInterval,
});
this.log(`debug`, entityType, `Started entity store field retention enrich task`);
this.log(`info`, entityType, `Entity store initialized`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
export const SCOPE = ['securitySolution'];
export const TYPE = 'entity_store:field_retention:enrichment';
export const VERSION = '1.0.0';
export const INTERVAL = '1h';
export const DEFAULT_INTERVAL = '1h';
export const TIMEOUT = '10m';
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
stateSchemaByVersion,
type LatestTaskStateSchema as EntityStoreFieldRetentionTaskState,
} from './state';
import { INTERVAL, SCOPE, TIMEOUT, TYPE, VERSION } from './constants';
import { SCOPE, TIMEOUT, TYPE, VERSION } from './constants';
import type { EntityAnalyticsRoutesDeps } from '../../types';

import { executeFieldRetentionEnrichPolicy } from '../elasticsearch_assets';
Expand Down Expand Up @@ -120,10 +120,12 @@ export const startEntityStoreFieldRetentionEnrichTask = async ({
logger,
namespace,
taskManager,
interval,
}: {
logger: Logger;
namespace: string;
taskManager: TaskManagerStartContract;
interval: string;
}) => {
const taskId = getTaskId(namespace);
const log = logFactory(logger, taskId);
Expand All @@ -136,7 +138,7 @@ export const startEntityStoreFieldRetentionEnrichTask = async ({
taskType: getTaskName(),
scope: SCOPE,
schedule: {
interval: INTERVAL,
interval,
},
state: { ...defaultState, namespace },
params: { version: VERSION },
Expand Down Expand Up @@ -234,7 +236,7 @@ export const runTask = async ({

telemetry.reportEvent(FIELD_RETENTION_ENRICH_POLICY_EXECUTION_EVENT.eventType, {
duration: taskDurationInSeconds,
interval: INTERVAL,
interval: taskInstance.schedule?.interval,
});

// Track entity store usage
Expand Down
Loading