Skip to content

Commit 1a9af4a

Browse files
committed
Use ContextEval with Cel to ensure timeouts are respected
Signed-off-by: Juho Majasaari <[email protected]>
1 parent 1e89e16 commit 1a9af4a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func NewCelProgram(s string) (CelProgram, error) {
174174
return program, fmt.Errorf("error compiling CEL program: %s", issues.Err())
175175
}
176176

177-
celProg, err := env.Program(ast)
177+
celProg, err := env.Program(ast, cel.InterruptCheckFrequency(100))
178178
if err != nil {
179179
return program, fmt.Errorf("error creating CEL program: %s", err)
180180
}

prober/http.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func matchRegularExpressions(reader io.Reader, httpConfig config.HTTPProbe, logg
6767
return true
6868
}
6969

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

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

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

611611
if success && (httpConfig.FailIfBodyJSONMatchesCel != nil || httpConfig.FailIfBodyJSONNotMatchesCel != nil) {
612-
success = matchCelExpressions(byteCounter, httpConfig, logger)
612+
success = matchCelExpressions(ctx, byteCounter, httpConfig, logger)
613613
if success {
614614
probeFailedDueToCel.Set(0)
615615
} else {

0 commit comments

Comments
 (0)