mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(logs): read a minus followed by a space as an exclusion in a filter pattern (#9539)
A term filter pattern with a space between the minus and the excluded term, "ERROR" - "Unauthorized", was rejected with "expected a value", while AWS reads it as an exclusion, the same as "ERROR" -"Unauthorized". The term parser now skips whitespace after a minus and reads the next term as excluded, so metric filters, subscription filters and FilterLogEvents accept it alike.
This commit is contained in:
1 parent
40962031bf
commit
df8989cf5b
3 files changed
+11
-2
No files matched your search
@@ -249,7 +249,7 @@ Samples are readable with `GetMetricStatistics` and `GetMetricData`, and alarms
|
||||
The filter pattern syntax follows the AWS reference:
|
||||
|
||||
- Terms: `ERROR ARGUMENTS` (all present), `?ERROR ?ARGUMENTS` (any present), `ERROR -ARGUMENTS`
|
||||
(exclusion), `"exact phrase"`. Terms are case-sensitive substrings of the message.
|
||||
or `ERROR - ARGUMENTS` (exclusion), `"exact phrase"`. Terms are case-sensitive substrings of the message.
|
||||
- Regular expressions between percent signs, `%^[hc]at%`, with the operators and escapes AWS
|
||||
allows. Parentheses and characters outside ASCII are rejected, as on AWS.
|
||||
- JSON patterns: `{ $.eventType = "UpdateTrail" && $.code >= 400 }`, with `=`, `!=`, `<`, `<=`,
|
||||
|
||||
@@ -70,8 +70,10 @@ final class TermPattern extends FilterPattern {
|
||||
|
||||
private static Term readTerm(PatternCursor cursor) {
|
||||
Mode mode = Mode.INCLUDE;
|
||||
if (cursor.peek() == '-' && !cursor.lookingAt("- ")) {
|
||||
if (cursor.peek() == '-') {
|
||||
// AWS also reads "- term" as an exclusion.
|
||||
cursor.next();
|
||||
cursor.skipWhitespace();
|
||||
mode = Mode.EXCLUDE;
|
||||
} else if (cursor.peek() == '?' && !cursor.lookingAt("? ")) {
|
||||
cursor.next();
|
||||
|
||||
@@ -95,6 +95,13 @@ class FilterPatternTest {
|
||||
assertFalse(matches("ERROR -ARGUMENTS", "[ERROR 420] INVALID ARGUMENTS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMinusSeparatedFromItsTermBySpaceStillExcludesIt() {
|
||||
assertTrue(matches("\"ERROR\" - \"Unauthorized\"", "[ERROR 400] Bad request"));
|
||||
assertFalse(matches("\"ERROR\" - \"Unauthorized\"", "[ERROR 401] Unauthorized request"));
|
||||
assertFalse(matches("ERROR - ARGUMENTS", "[ERROR 419] MISSING ARGUMENTS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aQuotedSpaceMatchesEverythingWithASpaceAndAnEmptyPatternMatchesEverything() {
|
||||
assertTrue(matches("\" \"", "two words"));
|
||||
|
||||
Reference in new issue
Block a user