[Chore]: Make the search depth and page size unsigned on the internal query types
Requirement
The internal query types carry search bounds as signed int while the values they stand for can never be negative, and the wire types they are translated to and from are not signed the same way. Every translation is therefore a conversion that a reviewer, gosec and CodeQL each have to reason about separately, and the query service has to refuse negative values that the type could have ruled out.
Today:
| Field | Internal type | Wire type (jaeger.storage.v2) |
|---|---|---|
tracestore.TraceQueryParams.SearchDepth |
int |
int32 |
tracestore.Pagination.PageSize |
int |
uint32 |
The PageSize conversion in the remote-storage client (internal/storage/v2/grpc/tracereader.go) already carries a //nolint:gosec // G115, and CodeQL's go/incorrect-integer-conversion flags the same line once an HTTP parser feeds it a strconv-parsed value (seen on #9613). normalizeEnvelope refuses SearchDepth < 0 at runtime for a value that should not be representable.
Proposal
Make every depth and size field on the internal structs in tracestore and querysvc unsigned, so that a negative bound is unrepresentable and the conversions become widenings or exact copies:
TraceQueryParams.SearchDepth,Pagination.PageSize, and theMaxSearchDepthandMaxPageSizeconstants, ininternal/storage/v2/api/tracestore.querysvc.DefaultSearchDepthandDefaultPageSize, and thenormalizeEnvelopeandprepareSpanSearchQuerychecks, which lose their negative branches.- The api_v3 and storage/v2 translations in
cmd/jaeger/internal/extension/jaegerquery/internal/apiv3,internal/storage/v2/grpc, and every backend that readsSearchDepth(ClickHouse, Elasticsearch, Cassandra, Badger, memory). - The HTTP parsers, which then parse these values with
strconv.ParseUintand drop their explicit negative checks.
Whether the search_depth wire field should also move from int32 to uint32 is a jaeger-idl question and out of scope here; the internal type can be unsigned regardless, with one bounded conversion at that wire boundary.
Exit
No nolint:gosec on a depth or size conversion, no open go/incorrect-integer-conversion alert on these paths, and no runtime check for a negative depth or size anywhere in querysvc.
Source: jaegertracing/jaeger