Skip to content

Commit

Permalink
fix(tempohandler): make autocomplete queries opt-in
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed May 23, 2024
1 parent 6c57007 commit 36bd388
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/oteldb/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (app *App) trySetupTempo() error {
engine := traceqlengine.NewEngine(app.traceQuerier, traceqlengine.Options{
TracerProvider: app.metrics.TracerProvider(),
})
tempo := tempohandler.NewTempoAPI(q, engine)
tempo := tempohandler.NewTempoAPI(q, engine, tempohandler.TempoAPIOptions{})

s, err := tempoapi.NewServer(tempo,
tempoapi.WithTracerProvider(app.metrics.TracerProvider()),
Expand Down
2 changes: 1 addition & 1 deletion integration/tempoe2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func setupDB(
if engineQuerier != nil {
engine = traceqlengine.NewEngine(engineQuerier, traceqlengine.Options{})
}
api := tempohandler.NewTempoAPI(querier, engine)
api := tempohandler.NewTempoAPI(querier, engine, tempohandler.TempoAPIOptions{})
tempoh, err := tempoapi.NewServer(api)
require.NoError(t, err)

Expand Down
12 changes: 12 additions & 0 deletions internal/tempohandler/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package tempohandler

// TempoAPIOptions describes [TempoAPI] options.
type TempoAPIOptions struct {
// EnableAutocompleteQuery whether if handler should parse
// the `q` parameter in tag requests
//
// See https://grafana.com/docs/tempo/latest/api_docs/#filtered-tag-values.
EnableAutocompleteQuery bool
}

func (opts *TempoAPIOptions) setDefaults() {}
29 changes: 23 additions & 6 deletions internal/tempohandler/tempohandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,24 @@ import (
type TempoAPI struct {
q tracestorage.Querier
engine *traceqlengine.Engine

enableAutocomplete bool
}

var _ tempoapi.Handler = (*TempoAPI)(nil)

// NewTempoAPI creates new TempoAPI.
func NewTempoAPI(q tracestorage.Querier, engine *traceqlengine.Engine) *TempoAPI {
func NewTempoAPI(
q tracestorage.Querier,
engine *traceqlengine.Engine,
opts TempoAPIOptions,
) *TempoAPI {
opts.setDefaults()

return &TempoAPI{
q: q,
engine: engine,
q: q,
engine: engine,
enableAutocomplete: opts.EnableAutocompleteQuery,
}
}

Expand Down Expand Up @@ -149,8 +158,13 @@ func parseLogfmt(q string) (tags map[string]string, _ error) {
func (h *TempoAPI) SearchTagValues(ctx context.Context, params tempoapi.SearchTagValuesParams) (resp *tempoapi.TagValues, _ error) {
lg := zctx.From(ctx)

attr := traceql.Attribute{Name: params.TagName}
query := traceql.ParseAutocomplete(params.Q.Or(`{}`))
var (
attr = traceql.Attribute{Name: params.TagName}
query traceql.Autocomplete
)
if q, ok := params.Q.Get(); ok && h.enableAutocomplete {
query = traceql.ParseAutocomplete(q)
}

iter, err := h.q.TagValues(ctx, attr, tracestorage.TagValuesOptions{
Query: query,
Expand Down Expand Up @@ -195,7 +209,10 @@ func (h *TempoAPI) SearchTagValuesV2(ctx context.Context, params tempoapi.Search
if err != nil {
return nil, err
}
query := traceql.ParseAutocomplete(params.Q.Or(`{}`))
var query traceql.Autocomplete
if q, ok := params.Q.Get(); ok && h.enableAutocomplete {
query = traceql.ParseAutocomplete(q)
}

iter, err := h.q.TagValues(ctx, attr, tracestorage.TagValuesOptions{
Query: query,
Expand Down

0 comments on commit 36bd388

Please sign in to comment.