Skip to content

Commit

Permalink
[query] Add per query enforcer to graphite path (m3db#1459)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnikola authored Mar 15, 2019
1 parent dc35308 commit 2f49f6e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/query/executor/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ func (e *Engine) ExecuteExpr(
defer close(results)

perQueryEnforcer := e.globalEnforcer.Child(qcost.QueryLevel)
defer func() {
perQueryEnforcer.Close()
}()

defer perQueryEnforcer.Close()
req := newRequest(e, params)

nodes, edges, err := req.compile(ctx, parser)
Expand Down
5 changes: 4 additions & 1 deletion src/query/graphite/storage/m3_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ func (s *m3WrappedStore) FetchByQuery(
m3ctx, cancel := context.WithTimeout(ctx.RequestContext(), opts.Timeout)
defer cancel()
fetchOptions := storage.NewFetchOptions()
fetchOptions.Enforcer = s.enforcer
perQueryEnforcer := s.enforcer.Child(cost.QueryLevel)
defer perQueryEnforcer.Close()

fetchOptions.Enforcer = perQueryEnforcer
fetchOptions.FanoutOptions = &storage.FanoutOptions{
FanoutUnaggregated: storage.FanoutForceDisable,
FanoutAggregated: storage.FanoutDefault,
Expand Down
18 changes: 12 additions & 6 deletions src/query/graphite/storage/m3_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
"github.com/m3db/m3/src/query/storage"
"github.com/m3db/m3/src/query/storage/mock"
m3ts "github.com/m3db/m3/src/query/ts"
xcost "github.com/m3db/m3/src/x/cost"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -139,9 +139,15 @@ func TestFetchByQuery(t *testing.T) {
}

store.SetFetchResult(&storage.FetchResult{SeriesList: seriesList}, nil)
enforcers := []xcost.Enforcer{xcost.NewEnforcer(nil, nil, nil)}
enforcer, err := cost.NewChainedEnforcer("name", enforcers)
require.NoError(t, err)

ctrl := gomock.NewController(t)
defer ctrl.Finish()
childEnforcer := cost.NewMockChainedEnforcer(ctrl)
childEnforcer.EXPECT().Close()

enforcer := cost.NewMockChainedEnforcer(ctrl)
enforcer.EXPECT().Child(cost.QueryLevel).Return(childEnforcer).MinTimes(1)

wrapper := NewM3WrappedStorage(store, enforcer)
ctx := xctx.New()
ctx.SetRequestContext(context.TODO())
Expand All @@ -162,6 +168,6 @@ func TestFetchByQuery(t *testing.T) {
assert.Equal(t, "a", series.Name())
assert.Equal(t, []float64{3, 3, 3}, series.SafeValues())

// NB: ensure the fetch was called with enforcer propagated correctly
assert.Equal(t, enforcer, store.LastFetchOptions().Enforcer)
// NB: ensure the fetch was called with the base enforcer's child correctly
assert.Equal(t, childEnforcer, store.LastFetchOptions().Enforcer)
}

0 comments on commit 2f49f6e

Please sign in to comment.