app/vtselect: apply extra_filters to the Jaeger and Tempo APIs - #238
app/vtselect: apply extra_filters to the Jaeger and Tempo APIs#238Vandit1604 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
1 issue found across 8 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/vtselect/traces/tracecommon/tracecommon.go">
<violation number="1" location="app/vtselect/traces/tracecommon/tracecommon.go:72">
P1: When extra_filters is set, the Jaeger/Tempo trace-by-ID lookup (`/api/traces/<trace_id>`) returns empty for every trace, even ones inside the allowed tenant. NewQueryContext applies the extra filter to cp.Query before every query runs, including the internal trace-ID index lookup in findTraceIDTimeSplitTimeRange. Index rows only carry trace_id_idx, trace_id, start_time, end_time and _time (never resource_attr:service.name or user attributes), so a field filter like `"resource_attr:service.name":=alpha` matches none of them, the lookup fails with ErrOutOfRetention and GetTrace returns nil. Apply the extra filters only to the span-data queries (e.g. the traceID-list and span queries), not to the trace_id index-stream lookup, or the added e2e test never covers this path.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
| func (cp *CommonParams) NewQueryContext(ctx context.Context) *logstorage.QueryContext { | ||
| // Every traces API builds its own Query and then calls this, so applying the extra filters | ||
| // here covers all of them. AddExtraFilters ANDs the filters in, so a repeated call is harmless. | ||
| for _, f := range cp.ExtraFilters { |
There was a problem hiding this comment.
P1: When extra_filters is set, the Jaeger/Tempo trace-by-ID lookup (/api/traces/<trace_id>) returns empty for every trace, even ones inside the allowed tenant. NewQueryContext applies the extra filter to cp.Query before every query runs, including the internal trace-ID index lookup in findTraceIDTimeSplitTimeRange. Index rows only carry trace_id_idx, trace_id, start_time, end_time and _time (never resource_attr:service.name or user attributes), so a field filter like "resource_attr:service.name":=alpha matches none of them, the lookup fails with ErrOutOfRetention and GetTrace returns nil. Apply the extra filters only to the span-data queries (e.g. the traceID-list and span queries), not to the trace_id index-stream lookup, or the added e2e test never covers this path.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/vtselect/traces/tracecommon/tracecommon.go, line 72:
<comment>When extra_filters is set, the Jaeger/Tempo trace-by-ID lookup (`/api/traces/<trace_id>`) returns empty for every trace, even ones inside the allowed tenant. NewQueryContext applies the extra filter to cp.Query before every query runs, including the internal trace-ID index lookup in findTraceIDTimeSplitTimeRange. Index rows only carry trace_id_idx, trace_id, start_time, end_time and _time (never resource_attr:service.name or user attributes), so a field filter like `"resource_attr:service.name":=alpha` matches none of them, the lookup fails with ErrOutOfRetention and GetTrace returns nil. Apply the extra filters only to the span-data queries (e.g. the traceID-list and span queries), not to the trace_id index-stream lookup, or the added e2e test never covers this path.</comment>
<file context>
@@ -57,11 +58,21 @@ type CommonParams struct {
func (cp *CommonParams) NewQueryContext(ctx context.Context) *logstorage.QueryContext {
+ // Every traces API builds its own Query and then calls this, so applying the extra filters
+ // here covers all of them. AddExtraFilters ANDs the filters in, so a repeated call is harmless.
+ for _, f := range cp.ExtraFilters {
+ cp.Query.AddExtraFilters(f)
+ }
</file context>
|
Closing this. I missed #184, which does the same thing and has been open since June. Sorry @immanuwell, that one is yours. I should have checked the open PRs on the issue before starting. |
Describe Your Changes
The Jaeger and Tempo APIs ignored the
extra_filtersandextra_stream_filtersquery args.Only
getCommonParamsinapp/vtselect/logsql/logsql.goread these args. That function serves the native LogsQL endpoints. Jaeger and Tempo usetracecommon.GetCommonParams, which did not read them.vmauth injects these args to keep a user inside its own data. When they are dropped, that user sees other services.
This is master. Two services,
alphaandbeta, andextra_filters={"resource_attr:service.name":"alpha"}:After the change the last three return
["alpha"],[]andalpha.How
Every Jaeger and Tempo path sets
cp.Queryand then callscp.NewQueryContext. SoGetCommonParamsparses the args once, andNewQueryContextapplies them. Every query endpoint of both APIs goes through that point.parseExtraFiltersand the two functions next to it moved fromapp/vtselect/logsqlinto a newapp/vtselect/extrafilterspackage, because both sides need them now. The bodies do not change. Their tests moved with them.The background service graph task builds its own
CommonParamsfrom a tenant ID. It has no HTTP request, so it stays unfiltered.One other change
A malformed
extra_filtersnow returns a 4xx from the Jaeger and Tempo APIs. Before, the arg was ignored. The LogsQL endpoints already behave this way.Tests
apptest/tests/extra_filters_test.goingests two services. It checks Jaeger services, Jaeger operations and the Tempo tag values API. I added a smallTempoAPITagValueshelper, becauseapptesthad no Tempo support.app/vtselect/traces/tracecommon/tracecommon_test.gocovers the parsing, repeated args, malformed input, and thatNewQueryContextapplies the filters.I removed the fix and ran the tests. All three end to end checks failed, and the unit test failed.
Checklist
make vet fmtpass, full test suite passesFixes #178