feat(ui): allow generating silence form content from a subset of group alerts

This commit is contained in:
Łukasz Mierzwa
2018-09-08 21:11:15 +01:00
parent 01f3c25160
commit bc799856f2
2 changed files with 38 additions and 2 deletions
+4 -2
View File
@@ -87,7 +87,8 @@ class SilenceFormStore {
}
},
fillMatchersFromGroup(group) {
// if alerts argument is not passed all group alerts will be used
fillMatchersFromGroup(group, alerts) {
let matchers = [];
// add matchers for all shared labels in this group
@@ -102,7 +103,8 @@ class SilenceFormStore {
// add matchers for all unique labels in this group
let labels = {};
for (const alert of group.alerts) {
const allAlerts = alerts ? alerts : group.alerts;
for (const alert of allAlerts) {
for (const [key, value] of Object.entries(alert.labels)) {
if (!labels[key]) {
labels[key] = new Set();
+34
View File
@@ -123,6 +123,40 @@ describe("SilenceFormStore.data", () => {
);
});
it("fillMatchersFromGroup() creates correct matcher object for a group with only a subset of alets passed", () => {
const group = MockGroup();
store.data.fillMatchersFromGroup(group, [group.alerts[0]]);
expect(store.data.matchers).toHaveLength(4);
expect(store.data.matchers).toContainEqual(
expect.objectContaining({
name: "alertname",
values: [{ label: "FakeAlert", value: "FakeAlert" }],
isRegex: false
})
);
expect(store.data.matchers).toContainEqual(
expect.objectContaining({
name: "job",
values: [{ label: "mock", value: "mock" }],
isRegex: false
})
);
expect(store.data.matchers).toContainEqual(
expect.objectContaining({
name: "instance",
values: [{ label: "prod1", value: "prod1" }],
isRegex: false
})
);
expect(store.data.matchers).toContainEqual(
expect.objectContaining({
name: "cluster",
values: [{ label: "prod", value: "prod" }],
isRegex: false
})
);
});
it("toAlertmanagerPayload creates payload that matches snapshot", () => {
const group = MockGroup();
store.data.fillMatchersFromGroup(group);