Skip to content

Commit 58b3636

Browse files
[RAM] Fix bulk edit references (#153370)
## Summary Fix: #152961 #152960 #153175 ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Kibana Machine <[email protected]>
1 parent a87c758 commit 58b3636

File tree

2 files changed

+87
-2
lines changed
  • x-pack
    • plugins/alerting/server/rules_client/methods
    • test/alerting_api_integration/security_and_spaces/group3/tests/alerting

2 files changed

+87
-2
lines changed

x-pack/plugins/alerting/server/rules_client/methods/bulk_edit.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
getBulkSnoozeAttributes,
4747
getBulkUnsnoozeAttributes,
4848
verifySnoozeScheduleLimit,
49+
injectReferencesIntoParams,
4950
} from '../common';
5051
import {
5152
alertingAuthorizationFilterOpts,
@@ -435,10 +436,16 @@ async function updateRuleAttributesAndParamsInMemory<Params extends RuleTypePara
435436

436437
validateScheduleInterval(context, attributes.schedule.interval, ruleType.id, rule.id);
437438

439+
const params = injectReferencesIntoParams<Params, RuleTypeParams>(
440+
rule.id,
441+
ruleType,
442+
attributes.params,
443+
rule.references || []
444+
);
438445
const { modifiedParams: ruleParams, isParamsUpdateSkipped } = paramsModifier
439-
? await paramsModifier(attributes.params as Params)
446+
? await paramsModifier(params)
440447
: {
441-
modifiedParams: attributes.params as Params,
448+
modifiedParams: params,
442449
isParamsUpdateSkipped: true,
443450
};
444451

x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_edit.ts

+78
Original file line numberDiff line numberDiff line change
@@ -610,5 +610,83 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
610610
});
611611
});
612612
}
613+
614+
describe('do NOT delete reference for rule type like', () => {
615+
const es = getService('es');
616+
617+
it('.esquery', async () => {
618+
const space1 = UserAtSpaceScenarios[1].space.id;
619+
const { body: createdRule } = await supertest
620+
.post(`${getUrlPrefix(space1)}/api/alerting/rule`)
621+
.set('kbn-xsrf', 'foo')
622+
.send(
623+
getTestRuleData({
624+
params: {
625+
searchConfiguration: {
626+
query: { query: 'host.name:*', language: 'kuery' },
627+
index: 'logs-*',
628+
},
629+
timeField: '@timestamp',
630+
searchType: 'searchSource',
631+
timeWindowSize: 5,
632+
timeWindowUnit: 'm',
633+
threshold: [1000],
634+
thresholdComparator: '>',
635+
size: 100,
636+
aggType: 'count',
637+
groupBy: 'all',
638+
termSize: 5,
639+
excludeHitsFromPreviousRun: true,
640+
},
641+
consumer: 'alerts',
642+
schedule: { interval: '1m' },
643+
tags: [],
644+
name: 'Es Query',
645+
rule_type_id: '.es-query',
646+
actions: [],
647+
})
648+
)
649+
.expect(200);
650+
objectRemover.add(space1, createdRule.id, 'rule', 'alerting');
651+
652+
const searchRule = () =>
653+
es.search<{ references: unknown }>({
654+
index: '.kibana*',
655+
query: {
656+
bool: {
657+
filter: [
658+
{
659+
term: {
660+
_id: `alert:${createdRule.id}`,
661+
},
662+
},
663+
],
664+
},
665+
},
666+
fields: ['alert.params', 'references'],
667+
});
668+
669+
const {
670+
hits: { hits: alertHitsV1 },
671+
} = await searchRule();
672+
673+
await supertest
674+
.post(`${getUrlPrefix(space1)}/internal/alerting/rules/_bulk_edit`)
675+
.set('kbn-xsrf', 'foo')
676+
.send({
677+
ids: [createdRule.id],
678+
operations: [{ operation: 'set', field: 'apiKey' }],
679+
});
680+
681+
const {
682+
hits: { hits: alertHitsV2 },
683+
} = await searchRule();
684+
685+
expect(alertHitsV1[0].fields).to.eql(alertHitsV2[0].fields);
686+
expect(alertHitsV1[0]?._source?.references ?? true).to.eql(
687+
alertHitsV2[0]?._source?.references ?? false
688+
);
689+
});
690+
});
613691
});
614692
}

0 commit comments

Comments
 (0)