Skip to content

Commit

Permalink
Use ContextEval with Cel to ensure timeouts are respected
Browse files Browse the repository at this point in the history
Signed-off-by: Juho Majasaari <[email protected]>
  • Loading branch information
juho9000 committed Aug 8, 2024
1 parent 59ff2b4 commit b9b903b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func NewCelProgram(s string) (CelProgram, error) {
return program, fmt.Errorf("error compiling CEL program: %s", issues.Err())
}

celProg, err := env.Program(ast)
celProg, err := env.Program(ast, cel.InterruptCheckFrequency(100))
if err != nil {
return program, fmt.Errorf("error creating CEL program: %s", err)
}
Expand Down
8 changes: 4 additions & 4 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func matchRegularExpressions(reader io.Reader, httpConfig config.HTTPProbe, logg
return true
}

func matchCelExpressions(reader io.Reader, httpConfig config.HTTPProbe, logger log.Logger) bool {
func matchCelExpressions(ctx context.Context, reader io.Reader, httpConfig config.HTTPProbe, logger log.Logger) bool {
body, err := io.ReadAll(reader)
if err != nil {
level.Error(logger).Log("msg", "Error reading HTTP body", "err", err)
Expand All @@ -85,7 +85,7 @@ func matchCelExpressions(reader io.Reader, httpConfig config.HTTPProbe, logger l
}

if httpConfig.FailIfBodyJSONMatchesCel != nil {
result, details, err := httpConfig.FailIfBodyJSONMatchesCel.Eval(evalPayload)
result, details, err := httpConfig.FailIfBodyJSONMatchesCel.ContextEval(ctx, evalPayload)
if err != nil {
level.Error(logger).Log("msg", "Error evaluating CEL expression", "err", err)
return false
Expand All @@ -101,7 +101,7 @@ func matchCelExpressions(reader io.Reader, httpConfig config.HTTPProbe, logger l
}

if httpConfig.FailIfBodyJSONNotMatchesCel != nil {
result, details, err := httpConfig.FailIfBodyJSONNotMatchesCel.Eval(evalPayload)
result, details, err := httpConfig.FailIfBodyJSONNotMatchesCel.ContextEval(ctx, evalPayload)
if err != nil {
level.Error(logger).Log("msg", "Error evaluating CEL expression", "err", err)
return false
Expand Down Expand Up @@ -609,7 +609,7 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
}

if success && (httpConfig.FailIfBodyJSONMatchesCel != nil || httpConfig.FailIfBodyJSONNotMatchesCel != nil) {
success = matchCelExpressions(byteCounter, httpConfig, logger)
success = matchCelExpressions(ctx, byteCounter, httpConfig, logger)
if success {
probeFailedDueToCel.Set(0)
} else {
Expand Down

0 comments on commit b9b903b

Please sign in to comment.