Skip to content

Commit

Permalink
fix: add optional params to remoteread api for client_golang 1.20.x (#…
Browse files Browse the repository at this point in the history
…207)

* add optional params to remoteread api for client_golang 1.20.x
* go mod tidy bumped go version in go.mod

Signed-off-by: alexgreenbank <[email protected]>
  • Loading branch information
alexgreenbank authored Oct 1, 2024
1 parent bcf5728 commit 03b451c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 40 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/grafana/mimir-proxies

go 1.21.8
go 1.22

toolchain go1.22.5

require (
Expand Down
18 changes: 9 additions & 9 deletions pkg/remoteread/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func (c *Config) RegisterFlagsWithPrefix(prefix string, flags *flag.FlagSet) {
type API interface {
Query(ctx context.Context, query string, ts time.Time, opts ...v1.Option) (model.Value, v1.Warnings, error)
QueryRange(ctx context.Context, query string, r v1.Range, opts ...v1.Option) (model.Value, v1.Warnings, error)
Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)
LabelNames(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)
LabelValues(ctx context.Context, label string, matches []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error)
Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time, opts ...v1.Option) ([]model.LabelSet, v1.Warnings, error)
LabelNames(ctx context.Context, matches []string, startTime time.Time, endTime time.Time, opts ...v1.Option) ([]string, v1.Warnings, error)
LabelValues(ctx context.Context, label string, matches []string, startTime time.Time, endTime time.Time, opts ...v1.Option) (model.LabelValues, v1.Warnings, error)
}

type errorMappingAPI struct {
Expand Down Expand Up @@ -84,19 +84,19 @@ func (e errorMappingAPI) QueryRange(ctx context.Context, query string, r v1.Rang
return e.api.QueryRange(ctx, query, r, opts...)
}

func (e errorMappingAPI) Series(ctx context.Context, matches []string, startTime, endTime time.Time) (_ []model.LabelSet, _ v1.Warnings, err error) {
func (e errorMappingAPI) Series(ctx context.Context, matches []string, startTime, endTime time.Time, opts ...v1.Option) (_ []model.LabelSet, _ v1.Warnings, err error) {
defer func() { err = mapAPIError(err) }()
return e.api.Series(ctx, matches, startTime, endTime)
return e.api.Series(ctx, matches, startTime, endTime, opts...)
}

func (e errorMappingAPI) LabelNames(ctx context.Context, matches []string, startTime, endTime time.Time) (_ []string, _ v1.Warnings, err error) {
func (e errorMappingAPI) LabelNames(ctx context.Context, matches []string, startTime, endTime time.Time, opts ...v1.Option) (_ []string, _ v1.Warnings, err error) {
defer func() { err = mapAPIError(err) }()
return e.api.LabelNames(ctx, matches, startTime, endTime)
return e.api.LabelNames(ctx, matches, startTime, endTime, opts...)
}

func (e errorMappingAPI) LabelValues(ctx context.Context, label string, matches []string, startTime, endTime time.Time) (_ model.LabelValues, _ v1.Warnings, err error) {
func (e errorMappingAPI) LabelValues(ctx context.Context, label string, matches []string, startTime, endTime time.Time, opts ...v1.Option) (_ model.LabelValues, _ v1.Warnings, err error) {
defer func() { err = mapAPIError(err) }()
return e.api.LabelValues(ctx, label, matches, startTime, endTime)
return e.api.LabelValues(ctx, label, matches, startTime, endTime, opts...)
}

func NewAPI(cfg Config, options ...APIOption) (API, error) {
Expand Down
69 changes: 45 additions & 24 deletions pkg/remoteread/apimock/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/remoteread/measured_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,35 @@ func (ma *MeasuredAPI) QueryRange(ctx context.Context, query string, r v1.Range,
return ma.api.QueryRange(ctx, query, r, opts...)
}

func (ma *MeasuredAPI) Series(ctx context.Context, matches []string, startTime, endTime time.Time) (ls []model.LabelSet, w v1.Warnings, err error) {
func (ma *MeasuredAPI) Series(ctx context.Context, matches []string, startTime, endTime time.Time, opts ...v1.Option) (ls []model.LabelSet, w v1.Warnings, err error) {
sp, ctx := opentracing.StartSpanFromContextWithTracer(ctx, ma.tracer, "remoteread.Series")
defer sp.Finish()
sp.LogKV("matches", strings.Join(matches, ","), "startTime", startTime, "endTime", endTime)

defer func(t0 time.Time) {
ma.recorder.measure("Series", ma.timeNow().Sub(t0), err)
}(ma.timeNow())
return ma.api.Series(ctx, matches, startTime, endTime)
return ma.api.Series(ctx, matches, startTime, endTime, opts...)
}

func (ma *MeasuredAPI) LabelNames(ctx context.Context, matches []string, startTime, endTime time.Time) (s []string, w v1.Warnings, err error) {
func (ma *MeasuredAPI) LabelNames(ctx context.Context, matches []string, startTime, endTime time.Time, opts ...v1.Option) (s []string, w v1.Warnings, err error) {
sp, ctx := opentracing.StartSpanFromContextWithTracer(ctx, ma.tracer, "remoteread.LabelNames")
defer sp.Finish()
sp.LogKV("matches", strings.Join(matches, ","), "startTime", startTime, "endTime", endTime)

defer func(t0 time.Time) {
ma.recorder.measure("LabelNames", ma.timeNow().Sub(t0), err)
}(ma.timeNow())
return ma.api.LabelNames(ctx, matches, startTime, endTime)
return ma.api.LabelNames(ctx, matches, startTime, endTime, opts...)
}

func (ma *MeasuredAPI) LabelValues(ctx context.Context, label string, matches []string, startTime, endTime time.Time) (v model.LabelValues, w v1.Warnings, err error) {
func (ma *MeasuredAPI) LabelValues(ctx context.Context, label string, matches []string, startTime, endTime time.Time, opts ...v1.Option) (v model.LabelValues, w v1.Warnings, err error) {
sp, ctx := opentracing.StartSpanFromContextWithTracer(ctx, ma.tracer, "remoteread.LabelValues")
defer sp.Finish()
sp.LogKV("label", label, "matches", strings.Join(matches, ","), "startTime", startTime, "endTime", endTime)

defer func(t0 time.Time) {
ma.recorder.measure("LabelValues", ma.timeNow().Sub(t0), err)
}(ma.timeNow())
return ma.api.LabelValues(ctx, label, matches, startTime, endTime)
return ma.api.LabelValues(ctx, label, matches, startTime, endTime, opts...)
}

0 comments on commit 03b451c

Please sign in to comment.