-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prometheus): relax length limit for pipe-only EqualsRegex filters (
- Loading branch information
1 parent
52852fb
commit 24b0ccb
Showing
8 changed files
with
210 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package filodb.core.query | ||
|
||
/** | ||
* Storage for utility functions. | ||
*/ | ||
object QueryUtils { | ||
val REGEX_CHARS = Array('.', '?', '+', '*', '|', '{', '}', '[', ']', '(', ')', '"', '\\') | ||
|
||
private val regexCharsMinusPipe = (REGEX_CHARS.toSet - '|').toArray | ||
|
||
/** | ||
* Returns true iff the argument string contains any special regex chars. | ||
*/ | ||
def containsRegexChars(str: String): Boolean = { | ||
str.exists(REGEX_CHARS.contains(_)) | ||
} | ||
|
||
/** | ||
* Returns true iff the argument string contains no special regex | ||
* characters except the pipe character ('|'). | ||
* True is also returned when the string contains no pipes. | ||
*/ | ||
def containsPipeOnlyRegex(str: String): Boolean = { | ||
str.forall(!regexCharsMinusPipe.contains(_)) | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
core/src/test/scala/filodb.core/query/QueryUtilsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package filodb.core.query | ||
|
||
import org.scalatest.funspec.AnyFunSpec | ||
import org.scalatest.matchers.must.Matchers | ||
import org.scalatest.matchers.should.Matchers.convertToAnyShouldWrapper | ||
|
||
class QueryUtilsSpec extends AnyFunSpec with Matchers{ | ||
it("should correctly identify regex chars") { | ||
val testsNoRegex = Seq( | ||
"", | ||
",", | ||
"no regex-1234!@#%&_,/`~=<>';:" | ||
) | ||
// includes one test for each single regex char | ||
val testsRegex = QueryUtils.REGEX_CHARS.map(c => c.toString) ++ Seq( | ||
"\\", | ||
"\\\\", | ||
"foo\\.bar", // escape chars don't affect the result (at least for now). | ||
"foo\\\\.bar", | ||
"foo|bar", | ||
"foo\\|bar", | ||
".foo\\|bar" | ||
) | ||
for (test <- testsNoRegex) { | ||
QueryUtils.containsRegexChars(test) shouldEqual false | ||
} | ||
for (test <- testsRegex) { | ||
QueryUtils.containsRegexChars(test) shouldEqual true | ||
} | ||
} | ||
|
||
it ("should correctly identify non-pipe regex chars") { | ||
val testsPipeOnly = Seq( | ||
"", | ||
"|", | ||
"||||", | ||
"a|b|c|d|e", | ||
"foobar-1|2|34!@|#%&_,|/`~=<>|';:", | ||
// NOTE: some regex chars are missing from QueryUtils.REGEX_CHARS. | ||
// This is intentional to preserve existing behavior. | ||
"^foo|bar$" | ||
) | ||
// includes one test for each single non-pipe regex char | ||
val testsNonPipeOnly = QueryUtils.REGEX_CHARS.filter(c => c != '|').map(c => c.toString) ++ Seq( | ||
"\\", | ||
"\\\\", | ||
"foo\\|bar", // escape chars don't affect the result (at least for now). | ||
"foo\\\\|bar", | ||
"foo.bar.baz|", | ||
"!@#$%^&*()_+{}[];':\"" | ||
) | ||
for (test <- testsPipeOnly) { | ||
QueryUtils.containsPipeOnlyRegex(test) shouldEqual true | ||
} | ||
for (test <- testsNonPipeOnly) { | ||
QueryUtils.containsPipeOnlyRegex(test) shouldEqual false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters