mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(cloudwatch): match FilterLogEvents with the filter pattern syntax (#5903)
FilterLogEvents kept an event when its message contained filterPattern as
a substring. A JSON pattern such as { $.template = "sign-in-code" } then
never matched, and terms matched where AWS does not: an unquoted
sign-in-code, which AWS reads with its own term rules, matched every
message containing those characters.
Measured on AWS (eu-west-1, 2026-10-16) on five events, JSON, plain and
mixed: JSON patterns over nested paths and numbers, case-sensitive terms,
quoted phrases, ?alternatives and -exclusions each matched exactly the
events the parser Floci already uses for metric and subscription filters
matches. So FilterLogEvents now parses its pattern with it, once, before
the scan, and an invalid one is refused with InvalidParameterException
whatever the group holds.
The error text is the parser's own, as for PutMetricFilter and
TestMetricFilter; AWS words these differently per action, which is left
for a change of its own.
Tests: the measured events and patterns in CloudWatchLogsServiceTest and,
through the SDK, CloudWatchLogsFilterPatternTest, which fails on main.
This commit is contained in:
1 parent
c229311f8f
commit
964756145e
4 files changed
+170
-8
No files matched your search
+6
-2
@@ -932,6 +932,11 @@ public class CloudWatchLogsService implements ResourceProvider, Resettable {
|
||||
String nextToken, String region) {
|
||||
int maxEvents = Math.min(limit > 0 ? limit : Integer.MAX_VALUE,
|
||||
maxEventsPerQuery);
|
||||
// The filter pattern syntax metric and subscription filters use: terms, quoted phrases,
|
||||
// ?alternatives, -exclusions, JSON and space-delimited patterns. Parsed before the scan,
|
||||
// so an invalid pattern is refused whatever the group holds.
|
||||
FilterPattern pattern = filterPattern == null || filterPattern.isBlank()
|
||||
? null : requireFilterPattern(filterPattern);
|
||||
|
||||
String groupPrefix = groupKeyPrefix(region) + groupName + "::";
|
||||
List<String> requested = streamNames == null ? List.of() : streamNames;
|
||||
@@ -957,8 +962,7 @@ public class CloudWatchLogsService implements ResourceProvider, Resettable {
|
||||
List<FilteredEvent> matches = all.stream()
|
||||
.filter(f -> (startTime == null || f.event().getTimestamp() >= startTime)
|
||||
&& (endTime == null || f.event().getTimestamp() <= endTime))
|
||||
.filter(f -> filterPattern == null || filterPattern.isBlank()
|
||||
|| f.event().getMessage().contains(filterPattern))
|
||||
.filter(f -> pattern == null || pattern.match(f.event().getMessage()).matched())
|
||||
.sorted(Comparator.comparing(FilteredEvent::event, EVENT_ORDER))
|
||||
.toList();
|
||||
|
||||
|
||||
Reference in new issue
Block a user