Skip to content

Commit

Permalink
feat(promhandler): use optimized API for Series queries
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Jun 17, 2024
1 parent ca0d905 commit 4a37f01
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions internal/promhandler/promhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"golang.org/x/exp/maps"
"golang.org/x/sync/errgroup"

"github.com/go-faster/oteldb/internal/metricstorage"
"github.com/go-faster/oteldb/internal/promapi"
)

Expand Down Expand Up @@ -416,6 +417,38 @@ func (h *PromAPI) GetSeries(ctx context.Context, params promapi.GetSeriesParams)
_ = q.Close()
}()

var result storage.SeriesSet
if osq, ok := q.(metricstorage.OptimizedSeriesQuerier); ok {
result = osq.OnlySeries(ctx, false, mint.UnixMilli(), maxt.UnixMilli(), matchers...)
} else {
result, err = h.querySeries(ctx, q, mint, maxt, matchers, params)
if err != nil {
return nil, err
}
}

var data []promapi.LabelSet
for result.Next() {
series := result.At()
data = append(data, series.Labels().Map())
}
if err := result.Err(); err != nil {
return nil, executionErr("select", err)
}

return &promapi.SeriesResponse{
Status: "success",
Warnings: result.Warnings().AsStrings("", 0),
Data: data,
}, nil
}

func (h *PromAPI) querySeries(ctx context.Context,
q storage.Querier,
mint, maxt time.Time,
matchers [][]*labels.Matcher,
params promapi.GetSeriesParams,
) (storage.SeriesSet, error) {
var (
hints = &storage.SelectHints{
Start: mint.UnixMilli(),
Expand Down Expand Up @@ -454,21 +487,7 @@ func (h *PromAPI) GetSeries(ctx context.Context, params promapi.GetSeriesParams)
} else {
result = q.Select(ctx, false, hints, matchers[0]...)
}

var data []promapi.LabelSet
for result.Next() {
series := result.At()
data = append(data, series.Labels().Map())
}
if err := result.Err(); err != nil {
return nil, executionErr("select", err)
}

return &promapi.SeriesResponse{
Status: "success",
Warnings: result.Warnings().AsStrings("", 0),
Data: data,
}, nil
return result, nil
}

// PostSeries implements postSeries operation.
Expand Down

0 comments on commit 4a37f01

Please sign in to comment.