Alerting: Fix target rule group for moving alert rule group (#92816)

This commit is contained in:
Tom Ratcliffe 2024-09-02 15:28:12 +01:00 committed by GitHub
parent f26f655615
commit d1dc595692
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 86 additions and 2 deletions

View File

@ -1,5 +1,50 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Moving a Data source managed rule should move a rule in a namespace to another existing namespace 1`] = `
[
{
"body": {
"name": "group-1",
"rules": [
{
"alert": "alert1",
"annotations": {
"summary": "test alert",
},
"expr": "up = 1",
"labels": {
"severity": "warning",
},
},
],
},
"headers": [
[
"content-type",
"application/json",
],
[
"accept",
"application/json, text/plain, */*",
],
],
"method": "POST",
"url": "http://localhost/api/ruler/mimir/api/v1/rules/namespace-2?subtype=mimir",
},
{
"body": "",
"headers": [
[
"accept",
"application/json, text/plain, */*",
],
],
"method": "DELETE",
"url": "http://localhost/api/ruler/mimir/api/v1/rules/namespace-1/group-1?subtype=mimir",
},
]
`;
exports[`Moving a Data source managed rule should move a rule in an existing group to a new group 1`] = `
[
{
@ -125,7 +170,7 @@ exports[`Moving a Data source managed rule should move a rule in an existing gro
],
],
"method": "POST",
"url": "http://localhost/api/ruler/mimir/api/v1/rules/namespace-1?subtype=mimir",
"url": "http://localhost/api/ruler/mimir/api/v1/rules/namespace-2?subtype=mimir",
},
{
"body": "",

View File

@ -184,6 +184,45 @@ describe('Moving a Data source managed rule', () => {
expect(serializedRequests).toMatchSnapshot();
});
it('should move a rule in a namespace to another existing namespace', async () => {
const capture = captureRequests((r) => r.method === 'POST' || r.method === 'DELETE');
const ruleToMove = group1.rules[0];
const coreRuleGroup = {
dataSourceName: MIMIR_DATASOURCE_UID,
groupName: group1.name,
};
const currentRuleGroupID: RuleGroupIdentifier = {
...coreRuleGroup,
namespaceName: NAMESPACE_1,
};
const targetRuleGroupID: RuleGroupIdentifier = {
...coreRuleGroup,
namespaceName: NAMESPACE_2,
};
const ruleID = fromRulerRuleAndRuleGroupIdentifier(currentRuleGroupID, ruleToMove);
const { user } = render(
<MoveRuleTestComponent
currentRuleGroupIdentifier={currentRuleGroupID}
targetRuleGroupIdentifier={targetRuleGroupID}
ruleID={ruleID}
rule={ruleToMove}
/>
);
await user.click(byRole('button').get());
expect(await byText(/success/i).find()).toBeInTheDocument();
const requests = await capture;
const serializedRequests = await serializeRequests(requests);
expect(serializedRequests).toMatchSnapshot();
});
it('should fail if the rule group does not exist', async () => {
const groupToUpdate = group1;
const ruleToUpdate = groupToUpdate.rules[0];

View File

@ -114,7 +114,7 @@ export function useMoveRuleToRuleGroup() {
const result = await upsertRuleGroup({
rulerConfig: targetGroupRulerConfig,
namespace: currentRuleGroup.namespaceName,
namespace: targetRuleGroup.namespaceName,
payload: newTargetGroup,
notificationOptions: { successMessage },
}).unwrap();