fix(cloudwatch): warn on unsupported Logs Insights filter operators (#2170)

parseFilter scans for the leftmost '!=', '==' or '=' outside a quoted
value, so the '=' inside '>=', '<=' and '=~' won. For '>=' and '<=' the
comparison character was absorbed into the field name ("@message >"),
which resolves to null for every row, and passesFilters treats null as
non-matching; for '=~' the value became the literal "~ /ERROR/". Either
way the query came back with no rows and no warning, because as far as
parseFilter was concerned it had found a valid operator.

Stop the scan when a position starts one of those three operators, so
control reaches the "Ignoring unsupported Logs Insights filter" warning
that '<', '>', 'like', 'not like' and 'in' already hit, and the stage is
dropped instead. Quote tracking is untouched, so a '>=' inside a quoted
value is still just part of the value.

The docs table describing how unsupported syntax degrades had the same
two cases inverted: '=~' listed as warn-and-drop when it mis-parsed, and
bare '<' / '>' as silent-zero-rows when they already warned. Folded into
the one row that now matches the code, and the compound and/or mis-parse
this change does not fix got its own row instead of staying implied.

Refs #2042
This commit is contained in:
soreavis authored and GitHub committed 2026-08-12 10:52:24 -04:00
1 parent 819bfedc6c
commit f1c81977ec
3 files changed
+57 -6

No files matched your search

@@ -482,6 +482,43 @@ class CloudWatchLogsInsightsQueryTest {
assertTrue(state.rows().get(0).get("@message").contains("kept"));
}
@Test
void unsupportedFilterOperatorsDropTheStageInsteadOfMisparsing() {
String group = "search/query-operators";
String stream = "s-1";
createGroupStream(service, group, stream);
put(group, stream, BASE_MS + 1000, "INFO", "JOB-1", "info-line");
put(group, stream, BASE_MS + 2000, "ERROR", "JOB-1", "error-line");
// '>=', '<=' and '=~' used to lose their comparison character to the equality scan, leaving a
// dead field ("level >") that silently matched nothing. None of these is supported, so each one
// drops the whole stage with a warning and every row comes back.
for (String expr : List.of("level >= 'INFO'", "level <= 'INFO'", "level =~ /INFO/", ">= 'INFO'",
"level > 'INFO'", "level < 'INFO'", "level like /INFO/", "level not like /INFO/",
"level in ['INFO']")) {
assertEquals(2, rowsFor(group, "fields @message | filter " + expr).size(),
"unsupported operator must drop the whole filter stage: " + expr);
}
}
@Test
void supportedFilterOperatorsStillParse() {
String group = "search/query-equality";
String stream = "s-1";
createGroupStream(service, group, stream);
put(group, stream, BASE_MS + 1000, "INFO", "JOB-1", "info-line");
put(group, stream, BASE_MS + 2000, "ERROR", "JOB-1", "error-line");
putRaw(service, group, stream, BASE_MS + 3000, idLog("REQ>=42", "quoted"));
assertEquals(1, rowsFor(group, "fields @message | filter level = 'ERROR'").size());
assertEquals(1, rowsFor(group, "fields @message | filter level == 'ERROR'").size());
assertEquals(2, rowsFor(group, "fields @message | filter level != 'ERROR'").size());
// A '>=' inside the quoted value is not an operator — the real '=' still wins.
assertEquals("REQ>=42",
rowsFor(group, "fields params.id | filter params.id = 'REQ>=42'").get(0).get("params.id"));
}
@Test
void statisticsReportScannedAndMatched() {
String group = "data-studio/insights";
@@ -595,6 +632,15 @@ class CloudWatchLogsInsightsQueryTest {
return svc;
}
/** Run {@code query} over the full window on the default service and return its completed rows. */
private List<LinkedHashMap<String, String>> rowsFor(String group, String query) {
long startSec = BASE_MS / 1000 - 10;
CloudWatchLogsService.QueryState state = service.getQueryResults(
service.startQuery(List.of(group), startSec, startSec + 86400, query, null, REGION));
assertEquals("Complete", state.status());
return state.rows();
}
private void createGroupStream(CloudWatchLogsService svc, String group, String stream) {
svc.createLogGroup(group, null, null, REGION);
svc.createLogStream(group, stream, REGION);