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

Alerting: Add fuzzy search to alert list view #63931

Merged
merged 12 commits into from Mar 9, 2023

Conversation

konrad147
Copy link
Contributor

@konrad147 konrad147 commented Mar 1, 2023

What is this feature?

This feature adds fuzzy search to the alert list view search

Entities capable of being fuzzy searched:

  • namespaces/folders
  • evaluation groups
  • rule names

Additionally changes the search behavior to only apply on enter instead of debouncing on input.

Why do we need this feature?
We want to allow users to make typos and non-full names when searching

Who is this feature for?
Alerting users

Which issue(s) does this PR fix?:
Fixes #62587

Search in multiple words
image

Typos
image

@konrad147 konrad147 added this to the 9.5.0 milestone Mar 1, 2023
@konrad147 konrad147 self-assigned this Mar 1, 2023
@konrad147 konrad147 requested review from joshhunt and a team as code owners March 1, 2023 12:23
@konrad147 konrad147 changed the title Add basic fuzzy search Alerting: Add fuzzy search to alert list view Mar 1, 2023
@@ -2693,9 +2693,6 @@ exports[`better eslint`] = {
"public/app/features/alerting/unified/components/rules/RuleDetailsDataSources.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/features/alerting/unified/components/rules/RulesFilter.tsx:5381": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

public/app/features/alerting/unified/RuleList.test.tsx Outdated Show resolved Hide resolved
@@ -76,37 +77,64 @@ export const useFilteredRules = (namespaces: CombinedRuleNamespace[], filterStat
return useMemo(() => filterRules(namespaces, filterState), [namespaces, filterState]);
};

const ufuzzy = new uFuzzy({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we add a link to the ufuzzy docs here so we can find out what these params mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or just note that they're effectively Damerau–Levenshtein distance allowances for each term/word in the needle. (typo tolerance)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I kinda guessed as much (though I'm not familiar with the Damerau variant) :)

Copy link
Contributor

@leeoniya leeoniya Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the Damerau variant

it just treats adjacent transpositions as an edit distance of 1 instead of 2 (removal + insertion). now you're familiar with it 🤣

but i'll tell you a secret: uFuzzy just constructs a regex with all the variations 🐵. since building actual M x N string distance tables in JS for every item would be 🐢 🐌 🦥

https://github.com/leeoniya/uFuzzy/blob/1665a1427388e7c77e442dd3ca882882e7f3949d/src/uFuzzy.js#L225-L253

@@ -26,32 +26,37 @@ beforeAll(() => {
});

describe('filterRules', function () {
it('should filter out rules by name filter', function () {
// Typos there are deliberate to test the fuzzy search
it.each(['cpu', 'hi usage', 'usge'])('should filter out rules by name filter = "%s"', function (nameFilter) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Member

@soniaAguilarPeiron soniaAguilarPeiron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one! 🙌

@konrad147 konrad147 merged commit 5179a83 into main Mar 9, 2023
6 checks passed
@konrad147 konrad147 deleted the alerting/62587-alert-rules-fuzzy-search branch March 9, 2023 15:24
eleijonmarck pushed a commit that referenced this pull request Mar 13, 2023
* Add basic fuzzy search

* Add fuzzy search to rule name, group and namespace filters

* Add tests

* Apply sort order when filtering

* Filter rules on Enter instead of onChange

* Add minor rule stats performance improvements

* Fix tests

* Remove unused code, add ufuzzy inline docs

* Use form submit to set query string, add debounce docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Support regex or fuzzy matching on rule names in the alerting rule search box.
4 participants