Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): fix matcher filtering the silence form #5818

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(ui): fix matcher filtering the silence form
Fixes #5817
  • Loading branch information
prymitive committed Mar 8, 2024
commit 69366848a9bbe469a17c9d3c0c25c1b82038d0dd
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.119

### Fixed

- `silenceForm.strip.labels` did't strip labels that are in the filter bar #5817.

## v0.118

### Fixed
Expand Down
146 changes: 146 additions & 0 deletions ui/src/Components/SilenceModal/SilenceForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,152 @@ describe("<SilenceForm /> matchers", () => {
]);
});

it("ignores matches from silenceForm.strip.labels", () => {
const filter = (name: string, matcher: string, value: string) => {
const f = NewUnappliedFilter(`${name}${matcher}${value}`);
f.name = name;
f.matcher = matcher;
f.value = value;
return f;
};

const filterCombos = (name: string) =>
Object.entries(QueryOperators).map(([k, v]) =>
filter(name, v, `${name}${k}`),
);

alertStore.settings.setValues({
...alertStore.settings.values,
...{
silenceForm: {
strip: { labels: ["cluster"] },
defaultAlertmanagers: [],
},
},
});

alertStore.filters.setFilterValues([
...filterCombos(StaticLabels.AlertName),
...filterCombos(StaticLabels.AlertManager),
...filterCombos(StaticLabels.Receiver),
...filterCombos(StaticLabels.State),
...filterCombos(StaticLabels.SilencedBy),
...filterCombos("cluster"),
...filterCombos("foo"),
]);
silenceFormStore.data.setAutofillMatchers(true);
const tree = MountedSilenceForm();
const matchers = tree.find("Memo(SilenceMatch)");
expect(matchers).toHaveLength(8);
expect(silenceFormStore.data.matchers).toHaveLength(8);
expect(silenceFormStore.data.matchers).toEqual([
{
id: "14",
isRegex: false,
isEqual: true,
name: "alertname",
values: [
{
label: "alertnameEqual",
value: "alertnameEqual",
wasCreated: true,
},
],
},
{
id: "15",
isRegex: false,
isEqual: false,
name: "alertname",
values: [
{
label: "alertnameNotEqual",
value: "alertnameNotEqual",
wasCreated: true,
},
],
},
{
id: "16",
isRegex: true,
isEqual: true,
name: "alertname",
values: [
{
label: ".*alertnameRegex.*",
value: ".*alertnameRegex.*",
wasCreated: true,
},
],
},
{
id: "17",
isRegex: true,
isEqual: false,
name: "alertname",
values: [
{
label: ".*alertnameNegativeRegex.*",
value: ".*alertnameNegativeRegex.*",
wasCreated: true,
},
],
},
{
id: "18",
isRegex: false,
isEqual: true,
name: "foo",
values: [
{
label: "fooEqual",
value: "fooEqual",
wasCreated: true,
},
],
},
{
id: "19",
isRegex: false,
isEqual: false,
name: "foo",
values: [
{
label: "fooNotEqual",
value: "fooNotEqual",
wasCreated: true,
},
],
},
{
id: "20",
isRegex: true,
isEqual: true,
name: "foo",
values: [
{
label: ".*fooRegex.*",
value: ".*fooRegex.*",
wasCreated: true,
},
],
},
{
id: "21",
isRegex: true,
isEqual: false,
name: "foo",
values: [
{
label: ".*fooNegativeRegex.*",
value: ".*fooNegativeRegex.*",
wasCreated: true,
},
],
},
]);
});

it("doesn't use filters to populate default matchers when silenceFormStore.data.autofillMatchers=false", () => {
const filter = (name: string, matcher: string, value: string) => {
const f = NewUnappliedFilter(`${name}${matcher}${value}`);
Expand Down
5 changes: 4 additions & 1 deletion ui/src/Components/SilenceModal/SilenceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ const SilenceForm: FC<{
(f.matcher === QueryOperators.Equal ||
f.matcher === QueryOperators.NotEqual ||
f.matcher === QueryOperators.Regex ||
f.matcher === QueryOperators.NegativeRegex),
f.matcher === QueryOperators.NegativeRegex) &&
!alertStore.settings.values.silenceForm.strip.labels.includes(
f.name,
),
)
.forEach((f) => {
const matcher = NewEmptyMatcher();
Expand Down