Skip to content

Commit

Permalink
Add support in rule registry to refresh based on stateless vs stateful
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Nov 21, 2024
1 parent 3aa0ce4 commit 5ed3e9e
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe('initializeAlertsClient', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
executionId: 'abc',
logger,
Expand Down Expand Up @@ -159,6 +160,7 @@ describe('initializeAlertsClient', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
executionId: 'abc',
logger,
Expand Down Expand Up @@ -219,6 +221,7 @@ describe('initializeAlertsClient', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
executionId: 'abc',
logger,
Expand Down Expand Up @@ -288,6 +291,7 @@ describe('initializeAlertsClient', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
executionId: 'abc',
logger,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ export class AlertingPlugin {
supportsEphemeralTasks: plugins.taskManager.supportsEphemeralTasks(),
uiSettings: core.uiSettings,
usageCounter: this.usageCounter,
isServerless: !!plugins.serverless,
});

this.eventLogService!.registerSavedObjectProvider(RULE_SAVED_OBJECT_TYPE, (request) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ const taskRunnerFactoryInitializerParams: TaskRunnerFactoryInitializerParamsType
supportsEphemeralTasks: false,
uiSettings: uiSettingsService,
usageCounter: mockUsageCounter,
isServerless: false,
};

const mockedTaskInstance: ConcreteTaskInstance = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export class AdHocTaskRunner implements CancellableTask {
ruleLogPrefix: ruleLabel,
ruleRunMetricsStore,
spaceId: adHocRunData.spaceId,
isServerless: this.context.isServerless,
};
const alertsClient = await initializeAlertsClient<
RuleTypeParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ describe('RuleTypeRunner', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
alertsClient,
executionId: 'abc',
Expand Down Expand Up @@ -231,6 +232,7 @@ describe('RuleTypeRunner', () => {
startedAtOverridden: false,
previousStartedAt: null,
spaceId: 'default',
isServerless: false,
rule: {
id: RULE_ID,
name: mockedRule.name,
Expand Down Expand Up @@ -295,6 +297,7 @@ describe('RuleTypeRunner', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
alertsClient,
executionId: 'abc',
Expand Down Expand Up @@ -337,6 +340,7 @@ describe('RuleTypeRunner', () => {
startedAtOverridden: true,
previousStartedAt: null,
spaceId: 'default',
isServerless: false,
rule: {
id: RULE_ID,
name: mockedRule.name,
Expand Down Expand Up @@ -404,6 +408,7 @@ describe('RuleTypeRunner', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
alertsClient,
executionId: 'abc',
Expand Down Expand Up @@ -465,6 +470,7 @@ describe('RuleTypeRunner', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
alertsClient,
executionId: 'abc',
Expand Down Expand Up @@ -507,6 +513,7 @@ describe('RuleTypeRunner', () => {
startedAtOverridden: false,
previousStartedAt: null,
spaceId: 'default',
isServerless: false,
rule: {
id: RULE_ID,
name: mockedRule.name,
Expand Down Expand Up @@ -567,6 +574,7 @@ describe('RuleTypeRunner', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
alertsClient,
executionId: 'abc',
Expand Down Expand Up @@ -609,6 +617,7 @@ describe('RuleTypeRunner', () => {
startedAtOverridden: false,
previousStartedAt: null,
spaceId: 'default',
isServerless: false,
rule: {
id: RULE_ID,
name: mockedRule.name,
Expand Down Expand Up @@ -669,6 +678,7 @@ describe('RuleTypeRunner', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
alertsClient,
executionId: 'abc',
Expand Down Expand Up @@ -706,6 +716,7 @@ describe('RuleTypeRunner', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
alertsClient,
executionId: 'abc',
Expand Down Expand Up @@ -748,6 +759,7 @@ describe('RuleTypeRunner', () => {
startedAtOverridden: false,
previousStartedAt: null,
spaceId: 'default',
isServerless: false,
rule: {
id: RULE_ID,
name: mockedRule.name,
Expand Down Expand Up @@ -819,6 +831,7 @@ describe('RuleTypeRunner', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
alertsClient,
executionId: 'abc',
Expand Down Expand Up @@ -861,6 +874,7 @@ describe('RuleTypeRunner', () => {
startedAtOverridden: false,
previousStartedAt: null,
spaceId: 'default',
isServerless: false,
rule: {
id: RULE_ID,
name: mockedRule.name,
Expand Down Expand Up @@ -932,6 +946,7 @@ describe('RuleTypeRunner', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
alertsClient,
executionId: 'abc',
Expand Down Expand Up @@ -975,6 +990,7 @@ describe('RuleTypeRunner', () => {
startedAtOverridden: false,
previousStartedAt: null,
spaceId: 'default',
isServerless: false,
rule: {
id: RULE_ID,
name: mockedRule.name,
Expand Down Expand Up @@ -1036,6 +1052,7 @@ describe('RuleTypeRunner', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
alertsClient,
executionId: 'abc',
Expand Down Expand Up @@ -1079,6 +1096,7 @@ describe('RuleTypeRunner', () => {
startedAtOverridden: false,
previousStartedAt: null,
spaceId: 'default',
isServerless: false,
rule: {
id: RULE_ID,
name: mockedRule.name,
Expand Down Expand Up @@ -1140,6 +1158,7 @@ describe('RuleTypeRunner', () => {
ruleLogPrefix: `${RULE_TYPE_ID}:${RULE_ID}: '${RULE_NAME}'`,
ruleRunMetricsStore,
spaceId: 'default',
isServerless: false,
},
alertsClient,
executionId: 'abc',
Expand Down Expand Up @@ -1183,6 +1202,7 @@ describe('RuleTypeRunner', () => {
startedAtOverridden: false,
previousStartedAt: null,
spaceId: 'default',
isServerless: false,
rule: {
id: RULE_ID,
name: mockedRule.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export class RuleTypeRunner<
...(context.queryDelaySec ? { queryDelay: context.queryDelaySec } : {}),
...(startedAtOverridden ? { forceNow: startedAt } : {}),
}),
isServerless: context.isServerless,
})
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ describe('Task Runner', () => {
supportsEphemeralTasks: false,
uiSettings: uiSettingsService,
usageCounter: mockUsageCounter,
isServerless: false,
};

const ephemeralTestParams: Array<
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export class TaskRunner<
ruleLogPrefix: ruleLabel,
ruleRunMetricsStore,
spaceId,
isServerless: this.context.isServerless,
};
const alertsClient = await withAlertingSpan('alerting:initialize-alerts-client', () =>
initializeAlertsClient<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ describe('Task Runner', () => {
supportsEphemeralTasks: false,
uiSettings: uiSettingsService,
usageCounter: mockUsageCounter,
isServerless: false,
};

describe(`using ${label} for alert indices`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ describe('Task Runner Cancel', () => {
supportsEphemeralTasks: false,
uiSettings: uiSettingsService,
usageCounter: mockUsageCounter,
isServerless: false,
};

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe('Task Runner Factory', () => {
supportsEphemeralTasks: true,
uiSettings: uiSettingsService,
usageCounter: mockUsageCounter,
isServerless: false,
};

beforeEach(() => {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/task_runner/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export interface RuleTypeRunnerContext {
ruleLogPrefix: string;
ruleRunMetricsStore: RuleRunMetricsStore;
spaceId: string;
isServerless: boolean;
}

export interface RuleRunnerErrorStackTraceLog {
Expand Down Expand Up @@ -180,4 +181,5 @@ export interface TaskRunnerContext {
supportsEphemeralTasks: boolean;
uiSettings: UiSettingsServiceStart;
usageCounter?: UsageCounter;
isServerless: boolean;
}
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export interface RuleExecutorOptions<
namespace?: string;
flappingSettings: RulesSettingsFlappingProperties;
getTimeRange: (timeWindow?: string) => GetTimeRangeResult;
isServerless: boolean;
}

export interface RuleParamsAndRefs<Params extends RuleTypeParams> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,5 @@ export const createDefaultAlertExecutorOptions = <
const date = new Date(Date.now()).toISOString();
return { dateStart: date, dateEnd: date };
},
isServerless: false,
});

0 comments on commit 5ed3e9e

Please sign in to comment.