From 7572b26fbab8affb6894d78f9f2070217aacfc3f Mon Sep 17 00:00:00 2001 From: cici37 Date: Thu, 10 Mar 2022 14:50:35 -0800 Subject: [PATCH] Bump cel-go to v0.10.1 --- go.mod | 2 +- go.sum | 4 ++-- .../src/k8s.io/apiextensions-apiserver/go.mod | 2 +- .../src/k8s.io/apiextensions-apiserver/go.sum | 4 ++-- vendor/github.com/google/cel-go/cel/program.go | 13 +++++++++++-- .../github.com/google/cel-go/checker/cost.go | 15 +++++++-------- .../google/cel-go/interpreter/decorators.go | 2 -- .../google/cel-go/interpreter/interpreter.go | 7 +++++-- .../google/cel-go/interpreter/runtimecost.go | 18 +++++++----------- vendor/modules.txt | 4 ++-- 10 files changed, 38 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index c8c646bdb90..d246e0baba2 100644 --- a/go.mod +++ b/go.mod @@ -269,7 +269,7 @@ replace ( github.com/golangplus/testing => github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e github.com/google/btree => github.com/google/btree v1.0.1 github.com/google/cadvisor => github.com/google/cadvisor v0.43.0 - github.com/google/cel-go => github.com/google/cel-go v0.10.0 + github.com/google/cel-go => github.com/google/cel-go v0.10.1 github.com/google/cel-spec => github.com/google/cel-spec v0.6.0 github.com/google/go-cmp => github.com/google/go-cmp v0.5.5 github.com/google/gofuzz => github.com/google/gofuzz v1.1.0 diff --git a/go.sum b/go.sum index 5978a129df8..e8dccd9045d 100644 --- a/go.sum +++ b/go.sum @@ -221,8 +221,8 @@ github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= github.com/google/cadvisor v0.43.0 h1:z0ULgYPKZ7L/c7Zjq+ZD6ltklWwYdCSvBMgSjNC/hGo= github.com/google/cadvisor v0.43.0/go.mod h1:+RdMSbc3FVr5NYCD2dOEJy/LI0jYJ/0xJXkzWXEyiFQ= -github.com/google/cel-go v0.10.0 h1:SBdarVzHoCXsTjqX+Lsgg9asSO7bViwgizzDi9kBigg= -github.com/google/cel-go v0.10.0/go.mod h1:U7ayypeSkw23szu4GaQTPJGx66c20mx8JklMSxrmI1w= +github.com/google/cel-go v0.10.1 h1:MQBGSZGnDwh7T/un+mzGKOMz3x+4E/GDPprWjDL+1Jg= +github.com/google/cel-go v0.10.1/go.mod h1:U7ayypeSkw23szu4GaQTPJGx66c20mx8JklMSxrmI1w= github.com/google/cel-spec v0.6.0/go.mod h1:Nwjgxy5CbjlPrtCWjeDjUyKMl8w41YBYGjsyDdqk0xA= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= diff --git a/staging/src/k8s.io/apiextensions-apiserver/go.mod b/staging/src/k8s.io/apiextensions-apiserver/go.mod index 2982f5d403e..f05140bd8cf 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/go.mod +++ b/staging/src/k8s.io/apiextensions-apiserver/go.mod @@ -7,7 +7,7 @@ go 1.16 require ( github.com/emicklei/go-restful v2.9.5+incompatible github.com/gogo/protobuf v1.3.2 - github.com/google/cel-go v0.10.0 + github.com/google/cel-go v0.10.1 github.com/google/go-cmp v0.5.5 github.com/google/gofuzz v1.1.0 github.com/google/uuid v1.1.2 diff --git a/staging/src/k8s.io/apiextensions-apiserver/go.sum b/staging/src/k8s.io/apiextensions-apiserver/go.sum index e82c4a12efe..a26d61cbe1a 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/go.sum +++ b/staging/src/k8s.io/apiextensions-apiserver/go.sum @@ -229,8 +229,8 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= -github.com/google/cel-go v0.10.0 h1:SBdarVzHoCXsTjqX+Lsgg9asSO7bViwgizzDi9kBigg= -github.com/google/cel-go v0.10.0/go.mod h1:U7ayypeSkw23szu4GaQTPJGx66c20mx8JklMSxrmI1w= +github.com/google/cel-go v0.10.1 h1:MQBGSZGnDwh7T/un+mzGKOMz3x+4E/GDPprWjDL+1Jg= +github.com/google/cel-go v0.10.1/go.mod h1:U7ayypeSkw23szu4GaQTPJGx66c20mx8JklMSxrmI1w= github.com/google/cel-spec v0.6.0/go.mod h1:Nwjgxy5CbjlPrtCWjeDjUyKMl8w41YBYGjsyDdqk0xA= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= diff --git a/vendor/github.com/google/cel-go/cel/program.go b/vendor/github.com/google/cel-go/cel/program.go index 467f4d6b59b..f0971607241 100644 --- a/vendor/github.com/google/cel-go/cel/program.go +++ b/vendor/github.com/google/cel-go/cel/program.go @@ -102,6 +102,8 @@ func (ed *EvalDetails) State() interpreter.EvalState { return ed.state } +// ActualCost returns the tracked cost through the course of execution when `CostTracking` is enabled. +// Otherwise, returns nil if the cost was not enabled. func (ed *EvalDetails) ActualCost() *uint64 { if ed.costTracker == nil { return nil @@ -291,6 +293,9 @@ func (p *prog) Eval(input interface{}) (v ref.Val, det *EvalDetails, err error) // ContextEval implements the Program interface. func (p *prog) ContextEval(ctx context.Context, input interface{}) (ref.Val, *EvalDetails, error) { + if ctx == nil { + return nil, nil, fmt.Errorf("context can not be nil") + } // Configure the input, making sure to wrap Activation inputs in the special ctxActivation which // exposes the #interrupted variable and manages rate-limited checks of the ctx.Done() state. var vars interpreter.Activation @@ -360,16 +365,20 @@ func (gen *progGen) Eval(input interface{}) (ref.Val, *EvalDetails, error) { // ContextEval implements the Program interface method. func (gen *progGen) ContextEval(ctx context.Context, input interface{}) (ref.Val, *EvalDetails, error) { + if ctx == nil { + return nil, nil, fmt.Errorf("context can not be nil") + } // The factory based Eval() differs from the standard evaluation model in that it generates a // new EvalState instance for each call to ensure that unique evaluations yield unique stateful // results. state := interpreter.NewEvalState() - det := &EvalDetails{state: state} + costTracker := &interpreter.CostTracker{} + det := &EvalDetails{state: state, costTracker: costTracker} // Generate a new instance of the interpretable using the factory configured during the call to // newProgram(). It is incredibly unlikely that the factory call will generate an error given // the factory test performed within the Program() call. - p, err := gen.factory(state, &interpreter.CostTracker{}) + p, err := gen.factory(state, costTracker) if err != nil { return nil, det, err } diff --git a/vendor/github.com/google/cel-go/checker/cost.go b/vendor/github.com/google/cel-go/checker/cost.go index 68eaf8be19c..4e1ea5aadb3 100644 --- a/vendor/github.com/google/cel-go/checker/cost.go +++ b/vendor/github.com/google/cel-go/checker/cost.go @@ -37,7 +37,7 @@ type CostEstimator interface { EstimateSize(element AstNode) *SizeEstimate // EstimateCallCost returns the estimated cost of an invocation, or nil if // the estimator has no estimate to provide. - EstimateCallCost(overloadId string, target *AstNode, args []AstNode) *CallEstimate + EstimateCallCost(function, overloadID string, target *AstNode, args []AstNode) *CallEstimate } // CallEstimate includes a CostEstimate for the call, and an optional estimate of the result object size. @@ -384,7 +384,7 @@ func (c *coster) costCall(e *exprpb.Expr) CostEstimate { fnCost := CostEstimate{Min: uint64(math.MaxUint64), Max: 0} var resultSize *SizeEstimate for _, overload := range ref.GetOverloadId() { - overloadCost := c.functionCost(overload, &targetType, argTypes, argCosts) + overloadCost := c.functionCost(call.GetFunction(), overload, &targetType, argTypes, argCosts) fnCost = fnCost.Union(overloadCost.CostEstimate) if overloadCost.ResultSize != nil { if resultSize == nil { @@ -425,9 +425,8 @@ func (c *coster) costCreateStruct(e *exprpb.Expr) CostEstimate { str := e.GetStructExpr() if str.MessageName != "" { return c.costCreateMessage(e) - } else { - return c.costCreateMap(e) } + return c.costCreateMap(e) } func (c *coster) costCreateMap(e *exprpb.Expr) CostEstimate { @@ -480,7 +479,7 @@ func (c *coster) sizeEstimate(t AstNode) SizeEstimate { return SizeEstimate{Min: 0, Max: math.MaxUint64} } -func (c *coster) functionCost(overloadId string, target *AstNode, args []AstNode, argCosts []CostEstimate) CallEstimate { +func (c *coster) functionCost(function, overloadID string, target *AstNode, args []AstNode, argCosts []CostEstimate) CallEstimate { argCostSum := func() CostEstimate { var sum CostEstimate for _, a := range argCosts { @@ -489,11 +488,11 @@ func (c *coster) functionCost(overloadId string, target *AstNode, args []AstNode return sum } - if est := c.estimator.EstimateCallCost(overloadId, target, args); est != nil { + if est := c.estimator.EstimateCallCost(function, overloadID, target, args); est != nil { callEst := *est return CallEstimate{CostEstimate: callEst.Add(argCostSum())} } - switch overloadId { + switch overloadID { // O(n) functions case overloads.StartsWithString, overloads.EndsWithString, overloads.StringToBytes, overloads.BytesToString: if len(args) == 1 { @@ -544,7 +543,7 @@ func (c *coster) functionCost(overloadId string, target *AstNode, args []AstNode lhsSize := c.sizeEstimate(args[0]) rhsSize := c.sizeEstimate(args[1]) resultSize := lhsSize.Add(rhsSize) - switch overloadId { + switch overloadID { case overloads.AddList: // list concatenation is O(1), but we handle it here to track size return CallEstimate{CostEstimate: CostEstimate{Min: 1, Max: 1}.Add(argCostSum()), ResultSize: &resultSize} diff --git a/vendor/github.com/google/cel-go/interpreter/decorators.go b/vendor/github.com/google/cel-go/interpreter/decorators.go index cd24cbc74a6..9e37e185680 100644 --- a/vendor/github.com/google/cel-go/interpreter/decorators.go +++ b/vendor/github.com/google/cel-go/interpreter/decorators.go @@ -259,8 +259,6 @@ func maybeOptimizeSetMembership(i Interpretable, inlist InterpretableCall) (Inte if !types.IsError(iv) { valueSet[iv] = types.True } - default: - break } } return &evalSetMembership{ diff --git a/vendor/github.com/google/cel-go/interpreter/interpreter.go b/vendor/github.com/google/cel-go/interpreter/interpreter.go index c46feea8a5d..a59b3e61d11 100644 --- a/vendor/github.com/google/cel-go/interpreter/interpreter.go +++ b/vendor/github.com/google/cel-go/interpreter/interpreter.go @@ -101,8 +101,6 @@ func EvalStateObserver(state EvalState) EvalObserver { } } -// TODO: Replace all usages of ExhaustiveEval with ExhaustiveEvalWrapper - // ExhaustiveEval replaces operations that short-circuit with versions that evaluate // expressions and couples this behavior with the TrackState() decorator to provide // insight into the evaluation state of the entire expression. EvalState must be @@ -115,6 +113,11 @@ func ExhaustiveEval() InterpretableDecorator { } } +// InterruptableEval annotates comprehension loops with information that indicates they +// should check the `#interrupted` state within a custom Activation. +// +// The custom activation is currently managed higher up in the stack within the 'cel' package +// and should not require any custom support on behalf of callers. func InterruptableEval() InterpretableDecorator { return decInterruptFolds() } diff --git a/vendor/github.com/google/cel-go/interpreter/runtimecost.go b/vendor/github.com/google/cel-go/interpreter/runtimecost.go index 9e9287b63ef..d8233804175 100644 --- a/vendor/github.com/google/cel-go/interpreter/runtimecost.go +++ b/vendor/github.com/google/cel-go/interpreter/runtimecost.go @@ -12,10 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package interpreter provides functions to evaluate parsed expressions with -// the option to augment the evaluation with inputs and functions supplied at -// evaluation time. - package interpreter import ( @@ -35,7 +31,7 @@ import ( // estimate to provide. CEL attempts to provide reasonable estimates for its standard function library, so CallCost // should typically not need to provide an estimate for CELs standard function. type ActualCostEstimator interface { - CallCost(overloadId string, args []ref.Val) *uint64 + CallCost(function, overloadID string, args []ref.Val, result ref.Val) *uint64 } // CostObserver provides an observer that tracks runtime cost. @@ -46,7 +42,7 @@ func CostObserver(tracker *CostTracker) EvalObserver { // TODO: Push identifiers on to the stack before observing constant qualifiers that apply to them // and enable the below pop. Once enabled this can case can be collapsed into the Qualifier case. //tracker.stack.pop(1) - tracker.cost += 1 + tracker.cost++ case InterpretableConst: // zero cost case InterpretableAttribute: @@ -59,10 +55,10 @@ func CostObserver(tracker *CostTracker) EvalObserver { // Ternary has no direct cost. All cost is from the conditional and the true/false branch expressions. case Qualifier: tracker.stack.pop(1) - tracker.cost += 1 + tracker.cost++ case InterpretableCall: if argVals, ok := tracker.stack.pop(len(t.Args())); ok { - tracker.cost += tracker.costCall(t, argVals) + tracker.cost += tracker.costCall(t, argVals, val) } case InterpretableConstructor: switch t.Type() { @@ -97,10 +93,10 @@ func (c CostTracker) ActualCost() uint64 { return c.cost } -func (c CostTracker) costCall(call InterpretableCall, argValues []ref.Val) uint64 { +func (c CostTracker) costCall(call InterpretableCall, argValues []ref.Val, result ref.Val) uint64 { var cost uint64 if c.Estimator != nil { - callCost := c.Estimator.CallCost(call.OverloadID(), argValues) + callCost := c.Estimator.CallCost(call.Function(), call.OverloadID(), argValues, result) if callCost != nil { cost += *callCost return cost @@ -160,7 +156,7 @@ func (c CostTracker) costCall(call InterpretableCall, argValues []ref.Val) uint6 // - Computing the size of strings, byte sequences, lists and maps. // - Logical operations and all operators on fixed width scalars (comparisons, equality) // - Any functions that don't have a declared cost either here or in provided ActualCostEstimator. - cost += 1 + cost++ } return cost diff --git a/vendor/modules.txt b/vendor/modules.txt index dff7518bb81..3948e4f66bd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -371,7 +371,7 @@ github.com/google/cadvisor/utils/sysfs github.com/google/cadvisor/utils/sysinfo github.com/google/cadvisor/version github.com/google/cadvisor/watcher -# github.com/google/cel-go v0.10.0 => github.com/google/cel-go v0.10.0 +# github.com/google/cel-go v0.10.1 => github.com/google/cel-go v0.10.1 github.com/google/cel-go/cel github.com/google/cel-go/checker github.com/google/cel-go/checker/decls @@ -2541,7 +2541,7 @@ sigs.k8s.io/yaml # github.com/golangplus/testing => github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e # github.com/google/btree => github.com/google/btree v1.0.1 # github.com/google/cadvisor => github.com/google/cadvisor v0.43.0 -# github.com/google/cel-go => github.com/google/cel-go v0.10.0 +# github.com/google/cel-go => github.com/google/cel-go v0.10.1 # github.com/google/cel-spec => github.com/google/cel-spec v0.6.0 # github.com/google/go-cmp => github.com/google/go-cmp v0.5.5 # github.com/google/gofuzz => github.com/google/gofuzz v1.1.0