Skip to content

Commit

Permalink
Alerting update route throttle property is missing (#59580)
Browse files Browse the repository at this point in the history
* Added throttle property to update method of alertClient

* Fixed failing snapshot

* Fixed type check errors

* Fixed null update for siem throttle
  • Loading branch information
YulNaumenko authored Mar 7, 2020
1 parent 9ab4aa0 commit b960c6a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const patchRules = async ({
type,
references,
version,
throttle,
}: PatchRuleParams): Promise<PartialAlert | null> => {
const rule = await readRules({ alertsClient, ruleId, id });
if (rule == null) {
Expand Down Expand Up @@ -73,6 +74,7 @@ export const patchRules = async ({
type,
references,
version,
throttle,
});

const nextParams = defaults(
Expand Down Expand Up @@ -108,6 +110,7 @@ export const patchRules = async ({
id: rule.id,
data: {
tags: addTags(tags ?? rule.tags, rule.params.ruleId, immutable ?? rule.params.immutable),
throttle: throttle ?? rule.throttle ?? null,
name: calculateName({ updatedName: name, originalName: rule.name }),
schedule: {
interval: calculateInterval(interval, rule.schedule.interval),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const updatePrepackagedRules = async (
threat,
references,
version,
throttle,
} = rule;

// Note: we do not pass down enabled as we do not want to suddenly disable
Expand Down Expand Up @@ -73,6 +74,7 @@ export const updatePrepackagedRules = async (
threat,
references,
version,
throttle,
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const updateRules = async ({
type,
references,
version,
throttle,
}: UpdateRuleParams): Promise<PartialAlert | null> => {
const rule = await readRules({ alertsClient, ruleId, id });
if (rule == null) {
Expand Down Expand Up @@ -72,6 +73,7 @@ export const updateRules = async ({
type,
references,
version,
throttle,
});

const update = await alertsClient.update({
Expand All @@ -81,6 +83,7 @@ export const updateRules = async ({
name,
schedule: { interval },
actions: rule.actions,
throttle: throttle ?? rule.throttle ?? null,
params: {
description,
ruleId: rule.params.ruleId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface RuleAlertParams {
threat: ThreatParams[] | undefined | null;
type: 'query' | 'saved_query';
version: number;
throttle?: string;
}

export type RuleTypeParams = Omit<RuleAlertParams, 'name' | 'enabled' | 'interval' | 'tags'>;
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/alerting/server/alerts_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,7 @@ describe('update()', () => {
params: {
bar: true,
},
throttle: null,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -2101,6 +2102,7 @@ describe('update()', () => {
"tags": Array [
"foo",
],
"throttle": null,
"updatedBy": "elastic",
}
`);
Expand Down Expand Up @@ -2186,6 +2188,7 @@ describe('update()', () => {
params: {
bar: true,
},
throttle: '5m',
actions: [
{
group: 'default',
Expand Down Expand Up @@ -2254,6 +2257,7 @@ describe('update()', () => {
"tags": Array [
"foo",
],
"throttle": "5m",
"updatedBy": "elastic",
}
`);
Expand Down Expand Up @@ -2332,6 +2336,7 @@ describe('update()', () => {
params: {
bar: true,
},
throttle: '5m',
actions: [
{
group: 'default',
Expand Down Expand Up @@ -2401,6 +2406,7 @@ describe('update()', () => {
"tags": Array [
"foo",
],
"throttle": "5m",
"updatedBy": "elastic",
}
`);
Expand Down Expand Up @@ -2441,6 +2447,7 @@ describe('update()', () => {
params: {
bar: true,
},
throttle: null,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -2509,6 +2516,7 @@ describe('update()', () => {
params: {
bar: true,
},
throttle: null,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -2613,6 +2621,7 @@ describe('update()', () => {
params: {
bar: true,
},
throttle: '5m',
actions: [
{
group: 'default',
Expand Down Expand Up @@ -2742,6 +2751,7 @@ describe('update()', () => {
params: {
bar: true,
},
throttle: null,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -2772,6 +2782,7 @@ describe('update()', () => {
params: {
bar: true,
},
throttle: null,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -2808,6 +2819,7 @@ describe('update()', () => {
params: {
bar: true,
},
throttle: null,
actions: [
{
group: 'default',
Expand Down Expand Up @@ -2843,6 +2855,7 @@ describe('update()', () => {
params: {
bar: true,
},
throttle: null,
actions: [
{
group: 'default',
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/alerts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ interface UpdateOptions {
schedule: IntervalSchedule;
actions: NormalizedAlertAction[];
params: Record<string, any>;
throttle: string | null;
};
}

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/routes/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('updateAlertRoute', () => {
"tags": Array [
"bar",
],
"throttle": null,
},
"id": "1",
},
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/alerting/server/routes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ export const updateAlertRoute = (router: IRouter, licenseState: LicenseState) =>
}
const alertsClient = context.alerting.getAlertsClient();
const { id } = req.params;
const { name, actions, params, schedule, tags } = req.body;
const { name, actions, params, schedule, tags, throttle } = req.body;
return res.ok({
body: await alertsClient.update({
id,
data: { name, actions, params, schedule, tags },
data: { name, actions, params, schedule, tags, throttle },
}),
});
})
Expand Down

0 comments on commit b960c6a

Please sign in to comment.