Skip to content

Commit

Permalink
add a feature flag that enables added behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mchrome committed Apr 10, 2024
1 parent a084086 commit ad2e1cf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion cmd/carbonapi/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type ConfigType struct {
SendGlobsAsIs *bool `mapstructure:"sendGlobsAsIs"`
AlwaysSendGlobsAsIs *bool `mapstructure:"alwaysSendGlobsAsIs"`
ExtractTagsFromArgs bool `mapstructure:"extractTagsFromArgs"`
PassFunctionsToBackend bool `mapstructure:"passFunctionsToBackend"`
MaxBatchSize int `mapstructure:"maxBatchSize"`
Zipper string `mapstructure:"zipper"`
Upstreams zipperCfg.Config `mapstructure:"upstreams"`
Expand Down Expand Up @@ -138,7 +139,7 @@ func (c ConfigType) String() string {

func (c *ConfigType) SetZipper(zipper zipper.CarbonZipper) (err error) {
c.ZipperInstance = zipper
c.Evaluator, err = expr.NewEvaluator(c.Limiter, c.ZipperInstance)
c.Evaluator, err = expr.NewEvaluator(c.Limiter, c.ZipperInstance, c.PassFunctionsToBackend)
return
}

Expand Down
11 changes: 6 additions & 5 deletions expr/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import (
var ErrZipperNotInit = errors.New("zipper not initialized")

type Evaluator struct {
limiter limiter.SimpleLimiter
zipper zipper.CarbonZipper
limiter limiter.SimpleLimiter
zipper zipper.CarbonZipper
passFunctionsToBackend bool
}

func (eval Evaluator) Fetch(ctx context.Context, exprs []parser.Expr, from, until int64, values map[parser.MetricRequest][]*types.MetricData) (map[parser.MetricRequest][]*types.MetricData, error) {
Expand Down Expand Up @@ -53,7 +54,7 @@ func (eval Evaluator) Fetch(ctx context.Context, exprs []parser.Expr, from, unti
Until: fetchRequest.StopTime,
}

if m.ConsolidationFunc != "" {
if eval.passFunctionsToBackend && m.ConsolidationFunc != "" {
fetchRequest.FilterFunctions = append(fetchRequest.FilterFunctions, &pb.FilteringFunction{
Name: "consolidateBy",
Arguments: []string{m.ConsolidationFunc},
Expand Down Expand Up @@ -147,11 +148,11 @@ func (eval Evaluator) Eval(ctx context.Context, exp parser.Expr, from, until int
}

// NewEvaluator create evaluator with limiter and zipper
func NewEvaluator(limiter limiter.SimpleLimiter, zipper zipper.CarbonZipper) (*Evaluator, error) {
func NewEvaluator(limiter limiter.SimpleLimiter, zipper zipper.CarbonZipper, passFunctionsToBackend bool) (*Evaluator, error) {
if zipper == nil {
return nil, ErrZipperNotInit
}
return &Evaluator{limiter: limiter, zipper: zipper}, nil
return &Evaluator{limiter: limiter, zipper: zipper, passFunctionsToBackend: passFunctionsToBackend}, nil
}

// EvalExpr is the main expression evaluator.
Expand Down
8 changes: 4 additions & 4 deletions expr/expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func TestEvalExpr(t *testing.T) {
&data,
}

eval, err := NewEvaluator(nil, th.NewTestZipper(nil))
eval, err := NewEvaluator(nil, th.NewTestZipper(nil), false)
if err == nil {
_, err = EvalExpr(context.Background(), eval, exp, request.From, request.Until, metricMap)
}
Expand Down Expand Up @@ -361,7 +361,7 @@ func TestEvalExpression(t *testing.T) {
for _, tt := range tests {
testName := tt.Target
t.Run(testName, func(t *testing.T) {
eval, err := NewEvaluator(nil, th.NewTestZipper(nil))
eval, err := NewEvaluator(nil, th.NewTestZipper(nil), false)
if err == nil {
th.TestEvalExpr(t, eval, &tt)
} else {
Expand Down Expand Up @@ -464,7 +464,7 @@ func TestRewriteExpr(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
eval, err := NewEvaluator(nil, th.NewTestZipper(nil))
eval, err := NewEvaluator(nil, th.NewTestZipper(nil), false)
if err == nil {
rewritten, newTargets, err := RewriteExpr(context.Background(), eval, tt.e, 0, 1, tt.m)

Expand Down Expand Up @@ -521,7 +521,7 @@ func TestEvalCustomFromUntil(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
originalMetrics := th.DeepClone(tt.m)
exp, _, _ := parser.ParseExpr(tt.target)
eval, err := NewEvaluator(nil, th.NewTestZipper(nil))
eval, err := NewEvaluator(nil, th.NewTestZipper(nil), false)
if err == nil {
g, err := EvalExpr(context.Background(), eval, exp, tt.from, tt.until, tt.m)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion expr/functions/moving/moving_refetch/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestMovingRefetch(t *testing.T) {
for n, tt := range tests {
testName := tt.Target
t.Run(testName+"#"+strconv.Itoa(n), func(t *testing.T) {
eval, err := expr.NewEvaluator(nil, th.NewTestZipper(M))
eval, err := expr.NewEvaluator(nil, th.NewTestZipper(M), false)
if err == nil {
th.TestEvalExprWithRange(t, eval, &tt)
} else {
Expand Down
2 changes: 1 addition & 1 deletion expr/rewrite/aboveSeries/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestDiffSeries(t *testing.T) {
for _, tt := range tests {
testName := tt.Target
t.Run(testName, func(t *testing.T) {
eval, err := expr.NewEvaluator(nil, th.NewTestZipper(nil))
eval, err := expr.NewEvaluator(nil, th.NewTestZipper(nil), false)
if err == nil {
th.TestRewriteExpr(t, eval, &tt)
} else {
Expand Down

0 comments on commit ad2e1cf

Please sign in to comment.