fix(apiv3): Sort dependency links for deterministic ordering - #9127
fix(apiv3): Sort dependency links for deterministic ordering#9127lopster568 wants to merge 1 commit into
Conversation
GetDependencies returned links in the order the storage layer produced them, which is built from a map and therefore not stable across queries. Sort by parent then child so the response order is deterministic. Signed-off-by: Roshan Singh <rosh.s568@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes nondeterministic ordering in the api_v3 gRPC GetDependencies response by sorting dependency links before returning them, ensuring repeated identical queries produce a stable link order (aligning behavior with the HTTP handler and the MCP tool).
Changes:
- Sort dependency links by
parentthenchildinapiv3.Handler.GetDependenciesto make response ordering deterministic. - Add a unit test that feeds unsorted dependency links via a mock reader and asserts the returned order is sorted.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/grpc_handler.go | Sorts dependency links (parent, then child) before building the api_v3 response to ensure deterministic ordering. |
| cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/grpc_handler_test.go | Adds a regression test asserting GetDependencies returns links in sorted order even when storage returns an unsorted slice. |
CI Summary ReportMetrics ComparisonView changed metricsFor label-level diff details, open the CI run and expand the "Compare metrics and generate summary" step logs. metrics_snapshot_badger_e2e — ⬇️ download diff
Code Coverage✅ Coverage 98% (baseline 98%) ➡️ View CI run | View publish logs |
|
@lopster568 why does the sorting need to be done in the transport later (grpc handler)? Query Service is the business layer, the data should not look different depending on whether you hit HTTP or GRPC endpoints. |
Which problem is this PR solving?
Description of the changes
apiv3.Handler.GetDependenciesreturned links in the order the storage layer produced them, which is built from a map and therefore not stable across queries. This sorts them by parent then child before building the response, so repeated queries return the same order. Same approach as the HTTP handler (#9119) and the MCP tool (#8403).How was this change tested?
TestGetDependenciesSortsLinks: feeds the mock reader unsorted links and asserts the response is sorted. Fails onmain, passes with the change.make fmt,make lint(0 issues),make test(4073 tests, 0 failures) all pass.GetDependenciesis at 100% coverage.Checklist
make lint testAI Usage in this PR (choose one)
See AI Usage Policy.