fix(apiv3): Support query.attributes filter in GET /api/v3/traces#8687
Conversation
The parseFindTracesQuery handler always initialized Attributes as an
empty pcommon.Map, silently ignoring any query.attributes value sent
by the client. The proto comment documents the expected format as a
URL-encoded JSON string map (e.g. {"http.status_code":"200"}).
Parse that JSON into a map[string]string and convert it via
jptrace.PlainMapToPcommonMap so storage backends receive the requested
tag filters. Return a 400 Bad Request with a descriptive error when the
value is not valid JSON.
Closes jaegertracing#7594
Signed-off-by: Pulkit Saraf <pulkit@armoriq.io>
Signed-off-by: Pulkit Saraf <prateeksaraf9@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Yuri Shkuro <github@ysh.us>
The parseFindTracesQuery function was extracted from http_gateway.go into query_parser.go in jaegertracing#8646. Adapt the attributes parsing logic to live in its new home and update the test to use mock.MatchedBy for pcommon.Map comparison (pointer equality doesn't work across separately created maps). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Yuri Shkuro <github@ysh.us>
Avoids the intermediate attrs variable by initializing queryParams with pcommon.NewMap() upfront and overwriting Attributes only when needed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Yuri Shkuro <github@ysh.us>
Convert parseFindTracesQuery from a method returning a bool sentinel into a package-level function returning an error, moving all HTTP concerns to the callers. Add query_parser_test.go with direct unit tests covering all param permutations (including the previously uncovered RawTraces path). Trim TestHTTPGatewayFindTracesErrors to a single case that verifies parse errors are propagated as HTTP 400. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Yuri Shkuro <github@ysh.us>
There was a problem hiding this comment.
Pull request overview
Adds support for query.attributes filtering to the APIv3 HTTP GET /api/v3/traces endpoint by parsing the parameter into TraceQueryParams.Attributes, and refactors query parsing to return structured errors that callers translate into HTTP 400 responses.
Changes:
- Parse
query.attributesas a JSON object (map[string]string) and convert it topcommon.Mapfor trace searches. - Refactor
parseFindTracesQueryinto a standalone function returning(*TraceQueryParams, error)and centralize HTTP 400 handling in gateway handlers. - Add dedicated unit tests for query parsing and streamline HTTP gateway parse-error tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/query_parser.go | Adds query.attributes parsing and refactors parsing to return errors instead of writing HTTP responses. |
| cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/http_gateway.go | Updates trace search handlers to use the new parser signature and uniform 400 handling. |
| cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/query_parser_test.go | Introduces unit tests covering parsing permutations and error paths, including attributes. |
| cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/http_gateway_test.go | Simplifies parse-error tests and adds an attributes propagation test for /api/v3/traces. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Yuri Shkuro <github@ysh.us>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8687 +/- ##
==========================================
+ Coverage 96.56% 96.59% +0.02%
==========================================
Files 334 334
Lines 17830 17835 +5
==========================================
+ Hits 17217 17227 +10
+ Misses 459 455 -4
+ Partials 154 153 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…in tests Add validation that startTimeMin is strictly before startTimeMax, returning 400 Bad Request if not. Fix all test helpers to use a proper tMin < tMax ordering (tMin = now-1h, tMax = now) instead of the confusing inverted pattern that triggered a bot review comment. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Yuri Shkuro <github@ysh.us>
| if !timeMinParsed.Before(timeMaxParsed) { | ||
| return nil, fmt.Errorf("%s must be before %s", paramTimeMin, paramTimeMax) | ||
| } |
Which problem is this PR solving?
The
GET /api/v3/tracesendpoint silently ignoredquery.attributes— any tag/attribute filters sent by the client were dropped. The gRPCFindTracesRequestalready accepts amap<string,string> attributesfield, but the HTTP gateway never parsed it.This PR is based on the work in #8574 (by @Pulkit7070), rebased and adapted after the query parser was extracted into
query_parser.goin #8646, and extended with a decoupling refactor and dedicated unit tests.Description of the changes
query_parser.goparamAttributes = "query.attributes"constant.parseFindTracesQuery, parse thequery.attributesquery param as a URL-encoded JSON string map (matching the format documented in the proto:{"http.status_code":"200","error":"true"}), converting it viajptrace.PlainMapToPcommonMap. Returns400 Bad Requestwith a descriptive message for malformed JSON.parseFindTracesQueryfromhttp.ResponseWriter: convert it from a receiver method with aboolsentinel return into a plain function returning(*querysvc.TraceQueryParams, error), moving all HTTP concerns to the callers.http_gateway.goparseFindTracesQuerynow do a singletryHandleError(..., http.StatusBadRequest).query_parser_test.go(new file)parseFindTracesQuerycovering all param permutations (canonical and deprecated aliases), defaults, attributes, and every error path — includingRawTraceswhich was previously uncovered.http_gateway_test.goTestHTTPGatewayFindTracesErrorstrimmed to a single case that verifies parse errors are propagated as HTTP 400; detailed parse error cases moved toquery_parser_test.go.How was this change tested?
All tests pass.
🤖 Generated with Claude Code