mirror of
https://github.com/prymitive/karma
synced 2026-09-04 11:27:19 +00:00
feat(ui): allow generating silence form content from a subset of group alerts
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user