Skip to content

Commit

Permalink
Merge branch 'main' into sample-data-obs
Browse files Browse the repository at this point in the history
  • Loading branch information
rshen91 authored Sep 7, 2023
2 parents 967167b + ed48990 commit a759617
Show file tree
Hide file tree
Showing 74 changed files with 2,641 additions and 294 deletions.
1 change: 1 addition & 0 deletions config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ xpack.alerting.rules.run.ruleTypeOverrides:
xpack.alerting.rules.minimumScheduleInterval.enforce: true
xpack.alerting.rules.maxScheduledPerMinute: 400
xpack.actions.run.maxAttempts: 10
xpack.actions.queued.max: 10000

# Disables ESQL in advanced settings (hides it from the UI)
uiSettings:
Expand Down
3 changes: 3 additions & 0 deletions docs/settings/alert-action-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ xpack.actions.run:
maxAttempts: 5
--

`xpack.actions.queued.max` {ess-icon}::
Specifies the maximum number of actions that can be queued. Default: 1000000

[float]
[[preconfigured-connector-settings]]
=== Preconfigured connector settings
Expand Down
16 changes: 16 additions & 0 deletions packages/kbn-config-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ function recordOf<K extends string, V>(
return new RecordOfType(keyType, valueType, options);
}

function oneOf<A, B, C, D, E, F, G, H, I, J, K>(
types: [
Type<A>,
Type<B>,
Type<C>,
Type<D>,
Type<E>,
Type<F>,
Type<G>,
Type<H>,
Type<I>,
Type<J>,
Type<K>
],
options?: TypeOptions<A | B | C | D | E | F | G | H | I | J | K>
): Type<A | B | C | D | E | F | G | H | I | J | K>;
function oneOf<A, B, C, D, E, F, G, H, I, J>(
types: [Type<A>, Type<B>, Type<C>, Type<D>, Type<E>, Type<F>, Type<G>, Type<H>, Type<I>, Type<J>],
options?: TypeOptions<A | B | C | D | E | F | G | H | I | J>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3019,6 +3019,7 @@ describe('bulkEnqueueExecution()', () => {
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
actionTypeId: 'my-action-type',
},
{
id: uuidv4(),
Expand All @@ -3027,6 +3028,7 @@ describe('bulkEnqueueExecution()', () => {
executionId: '456def',
apiKey: null,
source: asHttpRequestExecutionSource(request),
actionTypeId: 'my-action-type',
},
]);
expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
Expand All @@ -3051,6 +3053,7 @@ describe('bulkEnqueueExecution()', () => {
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
actionTypeId: 'my-action-type',
},
{
id: uuidv4(),
Expand All @@ -3059,6 +3062,7 @@ describe('bulkEnqueueExecution()', () => {
executionId: '456def',
apiKey: null,
source: asHttpRequestExecutionSource(request),
actionTypeId: 'my-action-type',
},
])
).rejects.toMatchInlineSnapshot(`[Error: Unauthorized to execute all actions]`);
Expand All @@ -3081,6 +3085,7 @@ describe('bulkEnqueueExecution()', () => {
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
actionTypeId: 'my-action-type',
},
{
id: uuidv4(),
Expand All @@ -3089,6 +3094,7 @@ describe('bulkEnqueueExecution()', () => {
executionId: '456def',
apiKey: null,
source: asHttpRequestExecutionSource(request),
actionTypeId: 'my-action-type',
},
]);

Expand All @@ -3112,6 +3118,7 @@ describe('bulkEnqueueExecution()', () => {
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
actionTypeId: 'my-action-type',
},
{
id: uuidv4(),
Expand All @@ -3120,6 +3127,7 @@ describe('bulkEnqueueExecution()', () => {
executionId: '456def',
apiKey: null,
source: asHttpRequestExecutionSource(request),
actionTypeId: 'my-action-type',
},
];
await expect(actionsClient.bulkEnqueueExecution(opts)).resolves.toMatchInlineSnapshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
ExecutionEnqueuer,
ExecuteOptions as EnqueueExecutionOptions,
BulkExecutionEnqueuer,
ExecutionResponse,
} from '../create_execute_function';
import { ActionsAuthorization } from '../authorization/actions_authorization';
import {
Expand Down Expand Up @@ -114,7 +115,7 @@ export interface ConstructorOptions {
inMemoryConnectors: InMemoryConnector[];
actionExecutor: ActionExecutorContract;
ephemeralExecutionEnqueuer: ExecutionEnqueuer<RunNowResult>;
bulkExecutionEnqueuer: BulkExecutionEnqueuer<void>;
bulkExecutionEnqueuer: BulkExecutionEnqueuer<ExecutionResponse>;
request: KibanaRequest;
authorization: ActionsAuthorization;
auditLogger?: AuditLogger;
Expand All @@ -139,7 +140,7 @@ export interface ActionsClientContext {
request: KibanaRequest;
authorization: ActionsAuthorization;
ephemeralExecutionEnqueuer: ExecutionEnqueuer<RunNowResult>;
bulkExecutionEnqueuer: BulkExecutionEnqueuer<void>;
bulkExecutionEnqueuer: BulkExecutionEnqueuer<ExecutionResponse>;
auditLogger?: AuditLogger;
usageCounter?: UsageCounter;
connectorTokenClient: ConnectorTokenClientContract;
Expand Down Expand Up @@ -766,7 +767,9 @@ export class ActionsClient {
});
}

public async bulkEnqueueExecution(options: EnqueueExecutionOptions[]): Promise<void> {
public async bulkEnqueueExecution(
options: EnqueueExecutionOptions[]
): Promise<ExecutionResponse> {
const sources: Array<ActionExecutionSource<unknown>> = [];
options.forEach((option) => {
if (option.source) {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/actions/server/actions_config.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const createActionsConfigMock = () => {
validateEmailAddresses: jest.fn().mockReturnValue(undefined),
getMaxAttempts: jest.fn().mockReturnValue(3),
enableFooterInEmail: jest.fn().mockReturnValue(true),
getMaxQueued: jest.fn().mockReturnValue(1000),
};
return mocked;
};
Expand Down
17 changes: 17 additions & 0 deletions x-pack/plugins/actions/server/actions_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,20 @@ describe('getMaxAttempts()', () => {
expect(maxAttempts).toEqual(3);
});
});

describe('getMaxQueued()', () => {
test('returns the queued actions max defined in config', () => {
const acu = getActionsConfigurationUtilities({
...defaultActionsConfig,
queued: { max: 1 },
});
const max = acu.getMaxQueued();
expect(max).toEqual(1);
});

test('returns the default queued actions max', () => {
const acu = getActionsConfigurationUtilities(defaultActionsConfig);
const max = acu.getMaxQueued();
expect(max).toEqual(1000000);
});
});
10 changes: 9 additions & 1 deletion x-pack/plugins/actions/server/actions_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import url from 'url';
import { curry } from 'lodash';
import { pipe } from 'fp-ts/lib/pipeable';

import { ActionsConfig, AllowedHosts, EnabledActionTypes, CustomHostSettings } from './config';
import {
ActionsConfig,
AllowedHosts,
EnabledActionTypes,
CustomHostSettings,
DEFAULT_QUEUED_MAX,
} from './config';
import { getCanonicalCustomHostUrl } from './lib/custom_host_settings';
import { ActionTypeDisabledError } from './lib';
import { ProxySettings, ResponseSettings, SSLSettings } from './types';
Expand Down Expand Up @@ -54,6 +60,7 @@ export interface ActionsConfigurationUtilities {
options?: ValidateEmailAddressesOptions
): string | undefined;
enableFooterInEmail: () => boolean;
getMaxQueued: () => number;
}

function allowListErrorMessage(field: AllowListingField, value: string) {
Expand Down Expand Up @@ -217,5 +224,6 @@ export function getActionsConfigurationUtilities(
);
},
enableFooterInEmail: () => config.enableFooterInEmail,
getMaxQueued: () => config.queued?.max || DEFAULT_QUEUED_MAX,
};
}
8 changes: 8 additions & 0 deletions x-pack/plugins/actions/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export enum EnabledActionTypes {
const MAX_MAX_ATTEMPTS = 10;
const MIN_MAX_ATTEMPTS = 1;

const MIN_QUEUED_MAX = 1;
export const DEFAULT_QUEUED_MAX = 1000000;

const preconfiguredActionSchema = schema.object({
name: schema.string({ minLength: 1 }),
actionTypeId: schema.string({ minLength: 1 }),
Expand Down Expand Up @@ -130,6 +133,11 @@ export const configSchema = schema.object({
})
),
enableFooterInEmail: schema.boolean({ defaultValue: true }),
queued: schema.maybe(
schema.object({
max: schema.maybe(schema.number({ min: MIN_QUEUED_MAX, defaultValue: DEFAULT_QUEUED_MAX })),
})
),
});

export type ActionsConfig = TypeOf<typeof configSchema>;
Expand Down
Loading

0 comments on commit a759617

Please sign in to comment.