Skip to content

Commit

Permalink
Propagate warnings from remote engines
Browse files Browse the repository at this point in the history
This is a follow up commit to thanos-io#298 which
enables propagating warnings from remote engines into the distributed
query context.

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
  • Loading branch information
fpetkovski committed Aug 16, 2023
1 parent c64fc7b commit 4b01e49
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions engine/distributed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"testing"
"time"

"github.com/efficientgo/core/errors"
"github.com/efficientgo/core/testutil"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage"

"github.com/thanos-io/promql-engine/api"
"github.com/thanos-io/promql-engine/engine"
Expand Down Expand Up @@ -329,3 +331,32 @@ func TestDistributedAggregations(t *testing.T) {
}
}
}

func TestDistributedEngineWarnings(t *testing.T) {
querier := &storage.MockQueryable{
MockQuerier: &storage.MockQuerier{
SelectMockFunction: func(sortSeries bool, hints *storage.SelectHints, matchers ...*labels.Matcher) storage.SeriesSet {
return newWarningsSeriesSet(storage.Warnings{errors.New("test warning")})
},
},
}

opts := engine.Opts{
EngineOpts: promql.EngineOpts{
MaxSamples: math.MaxInt64,
Timeout: 1 * time.Minute,
},
}
remote := engine.NewRemoteEngine(opts, querier, math.MinInt64, math.MaxInt64, nil)
ng := engine.NewDistributedEngine(opts, api.NewStaticEndpoints([]api.RemoteEngine{remote}))
var (
start = time.UnixMilli(0)
end = time.UnixMilli(600)
step = 30 * time.Second
)
q, err := ng.NewRangeQuery(context.Background(), nil, nil, "test", start, end, step)
testutil.Ok(t, err)

res := q.Exec(context.Background())
testutil.Equals(t, 1, len(res.Warnings))
}
2 changes: 2 additions & 0 deletions execution/remote/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/thanos-io/promql-engine/execution/model"
"github.com/thanos-io/promql-engine/execution/scan"
engstore "github.com/thanos-io/promql-engine/execution/storage"
"github.com/thanos-io/promql-engine/execution/warnings"
"github.com/thanos-io/promql-engine/query"
)

Expand Down Expand Up @@ -102,6 +103,7 @@ func (s *storageAdapter) GetSeries(ctx context.Context, _, _ int) ([]engstore.Si

func (s *storageAdapter) executeQuery(ctx context.Context) {
result := s.query.Exec(ctx)
warnings.AddToContext(result.Warnings, ctx)
if result.Err != nil {
s.err = result.Err
return
Expand Down

0 comments on commit 4b01e49

Please sign in to comment.