Skip to content

fix(logs): resolve trailing-colon query ARNs - #5954

Merged
pgermosen merged 2 commits into
floci-io:mainfrom
aniketshukla1:fix/logs-query-trailing-colon-5947
Oct 19, 2026
Merged

pgermosen merged 2 commits into
floci-io:mainfrom
aniketshukla1:fix/logs-query-trailing-colon-5947

Conversation

@aniketshukla1

@aniketshukla1 aniketshukla1 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #5947.

  • Resolve the bare trailing-colon log group ARN sent by Grafana in StartQuery.logGroupIdentifiers, without changing name selectors or the shared ARN resolver used by other Logs APIs.
  • Limit this tolerance to a complete Logs ARN with a partition, nonempty regional field, 12-digit account, and valid log group name followed by one colon. Malformed ARNs, wrong-service ARNs, compound :*: suffixes, plain names ending in a colon, and missing groups still fail.
  • Add real JSON-protocol integration coverage for names, canonical ARNs, :*, and the colon form obtained by removing * from DescribeLogGroups.arn; cover commercial, GovCloud, and China partitions plus mixed-identifier deduplication.

Type of change

  • Bug fix (fix:)
  • New feature (feat:)
  • Breaking change (feat!: or fix!:)
  • Docs / chore

AWS Compatibility

The incorrect behavior was resolving the Grafana identifier to a group name that still included its trailing colon, causing ResourceNotFoundException for an existing group. The canonical ARN and :* forms already worked.

This is a narrowly scoped Floci client-compatibility tolerance. The AWS StartQuery reference documents the canonical ARN, not the bare-colon spelling. Live AWS acceptance of that spelling remains unverified; this PR does not claim otherwise. Existing selector validation, group existence checks, and other APIs' ARN handling are unchanged.

Validation:

  • Original reproduction: 9 HTTP cases, with the three partition-specific colon cases and the mixed-identifier case failing as expected; five controls passed.
  • Guard regressions reproduced malformed-ARN, wrong-service, and :*: acceptance in the initial implementation before tightening it. A separate mutation removing the ARN-only guard was caught by the non-ARN-marker regression.
  • Review follow-up: reproduced 11 failures covering empty/invalid ARN fields and the two name-only selectors; added six passing controls for the name selectors' existing name/canonical-ARN/:* forms. A mutation allowing empty or short account fields was caught by two regression cases, then restored.
  • Final focused run: 212 tests passed, 0 failures/errors/skips across CloudWatchLogsQueryIdentifiersIntegrationTest, CloudWatchLogsHandlerTest, CloudWatchLogsInsightsQueryTest, CloudWatchLogsInputConstraintTest, and CloudWatchLogsServiceTest.
  • ./mvnw -o -B -ntp checkstyle:check, make docs-check partition-check, and git diff --check passed.
  • Tested on Java 25 / Quarkus 3.40.1 using real HTTP JSON requests to Floci. The full test suite, native image, external SDK/CLI suite, live Grafana, and live AWS were not run locally.

Checklist

  • ./mvnw test passes locally
  • New or updated integration test added
  • Commit messages follow Conventional Commits
  • I have no more than 2 open, non-draft pull requests and no more than 4 open pull requests in total (drafts included) in this repository (maintainers and dependency bots are exempt).

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix StartQuery resolution of Grafana trailing-colon log group ARNs

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Resolve Grafana’s trailing-colon log group ARNs in StartQuery without changing other Logs APIs.
• Preserve failures for invalid identifiers and missing groups; retain single scans for equivalent
 identifiers.
• Add HTTP integration coverage across three AWS partitions and document the compatibility boundary.
Diagram

graph TD
  Request["StartQuery request"] --> Guard{"Valid colon ARN?"} -->|yes| Normalize["Remove trailing colon"] --> Dedup["Deduplicate groups"] --> Lookup["Check group existence"] --> Results["Query results"]
  Guard -->|no| Existing["Existing ARN resolver"] --> Dedup
Loading
High-Level Assessment

Keep the StartQuery-specific normalization. Changing the shared ARN extractor would alter other Logs APIs, while broad suffix stripping would accept identifiers outside the intended compatibility case.

Files changed (3) +171 / -3

Bug fix (1) +17 / -3
CloudWatchLogsHandler.javaResolve qualifying trailing-colon ARNs in StartQuery +17/-3

Resolve qualifying trailing-colon ARNs in StartQuery

• Routes StartQuery selectors through a query-specific resolver that removes the trailing colon only from a Logs ARN containing a valid log group name. Other values retain the existing extraction behavior.

src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java

Tests (1) +147 / -0
CloudWatchLogsQueryIdentifiersIntegrationTest.javaCover query identifiers through the Logs JSON API +147/-0

Cover query identifiers through the Logs JSON API

• Tests names, canonical ARNs, wildcard ARNs, and Grafana-style colon ARNs across commercial, GovCloud, and China regions. Verifies mixed-identifier deduplication and rejection of malformed, unrelated, or absent groups.

src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsQueryIdentifiersIntegrationTest.java

Documentation (1) +7 / -0
cloudwatch.mdDocument StartQuery identifier compatibility +7/-0

Document StartQuery identifier compatibility

• Describes supported log group identifier forms, deduplication, and the Grafana trailing-colon tolerance. Clarifies that AWS documents canonical ARNs and that other APIs are unaffected.

docs/services/cloudwatch.md

@qodo-code-review

qodo-code-review Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Malformed log group ARNs start queries ✓ Resolved
Description
resolveQueryLogGroupName treats resourceIfArnFor as proof of a valid Logs ARN, although that
helper permits empty partition, region, and account fields. When /app exists,
arn::logs:::log-group:/app: is rewritten to /app, so StartQuery accepts a malformed identifier
that previously failed the group lookup.
Code

src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java[R416-420]

+        String resource = AwsArnUtils.resourceIfArnFor(identifier, "logs").orElse("");
+        String prefix = "log-group:";
+        if (resource.startsWith(prefix) && resource.length() > prefix.length() && resource.endsWith(":")) {
+            String name = resource.substring(prefix.length(), resource.length() - 1);
+            if (name.length() <= 512 && LOG_GROUP_NAME.matcher(name).matches()) {
Relevance

●●● Strong

Malformed ARN acceptance contradicts the PR’s stated guard intent; recent malformed-owner ARN
validation was accepted.

PR-#5810

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The ARN helper recognizes any six-field arn value with logs as its service and returns its
resource without validating the other fields. The new resolver then validates only the extracted
group name, and the service looks that name up in the request region.

src/main/java/io/github/hectorvent/floci/core/common/AwsArnUtils.java[122-160]
src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java[414-425]
src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsService.java[1118-1141]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The trailing-colon resolver accepts malformed ARN-shaped strings because the shared ARN helper checks only the number of fields and service.
### Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java[414-425]
- src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsQueryIdentifiersIntegrationTest.java[85-98]
### Recommended Fix
Require a syntactically valid Logs log-group ARN, including valid nonempty partition, region, and account fields, before stripping the final colon. Add a regression case using `arn::logs:::log-group:<existing-name>:` and assert that it fails.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Name selectors accept trailing-colon ARNs ✓ Resolved
Description
handleStartQuery applies resolveQueryLogGroupName to logGroupName and logGroupNames, rather
than limiting the new rewrite to logGroupIdentifiers. Supplying a trailing-colon ARN in either
name selector now resolves an existing group and starts a query, whereas those values previously
retained the colon and failed the existence check.
Code

src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java[R397-399]

+        request.path("logGroupNames").forEach(n -> logGroupNames.add(resolveQueryLogGroupName(n.asText())));
        if (request.has("logGroupName")) {
-            logGroupNames.add(extractLogGroupNameFromArn(request.path("logGroupName").asText()));
+            logGroupNames.add(resolveQueryLogGroupName(request.path("logGroupName").asText()));
Relevance

●●● Strong

Scope regression affects selectors explicitly outside the PR’s stated identifier-only tolerance;
recent ARN validation fixes were accepted.

PR-#5810

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Both name selectors now call the new resolver, which strips the terminal colon from a Logs ARN. The
old extractor strips only :*; the service subsequently checks the resolved group name without
retaining which selector supplied it.

src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java[396-425]
src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java[682-691]
src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsService.java[1118-1141]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The trailing-colon ARN compatibility rewrite also applies to the two name selectors, outside the intended `logGroupIdentifiers` scope.
### Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsHandler.java[396-401]
- src/test/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsQueryIdentifiersIntegrationTest.java[44-58]
### Recommended Fix
Keep the previous extraction behavior for `logGroupName` and `logGroupNames`, and call `resolveQueryLogGroupName` only for `logGroupIdentifiers`. Add regression requests showing that trailing-colon ARNs in the name selectors are not newly accepted.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
❌ Tickets: failed to load — Ticket collection could not establish complete evidence
✅ Compliance rules (platform): 8 rules
✅ Cross-repo context — repo relationships
Review mode: Auto: ⚖️ Balanced: Localized runtime behavior change with ARN edge cases warrants careful review.

Grey Divider

Tip of the day
💡 Did you know, you can import rules and skills only from the repositories your team follows

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@pgermosen pgermosen added bug Something isn't working cloudwatch Amazon CloudWatch (Logs & Metrics) labels Oct 19, 2026

@pgermosen pgermosen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@aniketshukla1 thanks, keeping the colon form to logGroupIdentifiers and to a full Logs ARN reads right, and it is what Grafana sends: buildLogGroupIdentifiers trims only the *, in its monitoring-account branch.

(follow-up, separate PR) Every ARN form still drops the ARN's account and region, so an identifier naming another account queries the caller's group of the same name instead of failing.

@pgermosen
pgermosen merged commit 916e725 into floci-io:main Oct 19, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cloudwatch Amazon CloudWatch (Logs & Metrics)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] CloudWatch Logs: StartQuery fails with ResourceNotFoundException when a logGroupIdentifiers ARN ends in a bare colon

2 participants