mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
fix(ui): acknowledgement silences should only match active alerts
This commit is contained in:
@@ -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 + " " : ""
|
||||
|
||||
@@ -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, [], {}, {});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user