fix(ui): acknowledgement silences should only match active alerts

This commit is contained in:
Łukasz Mierzwa
2020-02-21 10:11:22 +00:00
parent ee8b391c5b
commit eac4b2fe85
4 changed files with 12 additions and 9 deletions

View File

@@ -39,7 +39,7 @@ const newPendingSilence = (
payload: GenerateAlertmanagerSilenceData(
moment.utc(),
moment.utc().add(durationSeconds, "seconds"),
MatchersFromGroup(group, []),
MatchersFromGroup(group, [], group.alerts, true),
author,
`${
commentPrefix ? commentPrefix + " " : ""

View File

@@ -48,7 +48,8 @@ beforeEach(() => {
alerts = [
MockAlert([], { foo: "bar" }, "active"),
MockAlert([], { foo: "baz" }, "suppressed")
MockAlert([], { foo: "baz" }, "active"),
MockAlert([], { foo: "ignore" }, "suppressed")
];
group = MockAlertGroup({ alertname: "Fake Alert" }, alerts, [], {}, {});
});

View File

@@ -36,7 +36,7 @@ const SilenceTabNames = Object.freeze({
Browser: "browser"
});
const MatchersFromGroup = (group, stripLabels, alerts) => {
const MatchersFromGroup = (group, stripLabels, alerts, onlyActive) => {
let matchers = [];
// add matchers for all shared labels in this group
@@ -55,12 +55,14 @@ const MatchersFromGroup = (group, stripLabels, alerts) => {
let labels = {};
const allAlerts = alerts ? alerts : group.alerts;
for (const alert of allAlerts) {
for (const [key, value] of Object.entries(alert.labels)) {
if (!stripLabels.includes(key)) {
if (!labels[key]) {
labels[key] = new Set();
if (!onlyActive || alert.state === "active") {
for (const [key, value] of Object.entries(alert.labels)) {
if (!stripLabels.includes(key)) {
if (!labels[key]) {
labels[key] = new Set();
}
labels[key].add(value);
}
labels[key].add(value);
}
}
}

View File

@@ -160,7 +160,7 @@ describe("SilenceFormStore.data", () => {
);
});
it("fillMatchersFromGroup() creates correct matcher object for a group with only a subset of alets passed", () => {
it("fillMatchersFromGroup() creates correct matcher object for a group with only a subset of alerts passed", () => {
const group = MockGroup();
store.data.fillMatchersFromGroup(group, [], [group.alerts[0]]);
expect(store.data.matchers).toHaveLength(4);