Skip to content

Commit

Permalink
Log Cel expressions on failures
Browse files Browse the repository at this point in the history
Signed-off-by: Juho Majasaari <[email protected]>
  • Loading branch information
juho9000 committed Aug 29, 2024
1 parent dd56f5f commit 9131539
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ func (sc *SafeConfig) ReloadConfig(confFile string, logger log.Logger) (err erro
// CelProgram encapsulates a cel.Program and makes it YAML marshalable.
type CelProgram struct {
cel.Program
expression string
Expression string
}

// NewCelProgram creates a new CEL Program and returns an error if the
// passed-in CEL expression does not compile.
func NewCelProgram(s string) (CelProgram, error) {
program := CelProgram{
expression: s,
Expression: s,
}

env, err := cel.NewEnv(
Expand Down Expand Up @@ -200,8 +200,8 @@ func (c *CelProgram) UnmarshalYAML(unmarshal func(interface{}) error) error {

// MarshalYAML implements the yaml.Marshaler interface.
func (c CelProgram) MarshalYAML() (interface{}, error) {
if c.expression != "" {
return c.expression, nil
if c.Expression != "" {
return c.Expression, nil
}
return nil, nil
}
Expand Down
4 changes: 2 additions & 2 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func matchCelExpressions(ctx context.Context, reader io.Reader, httpConfig confi
return false
}
if result.Type() == cel.BoolType && result.Value().(bool) {
level.Error(logger).Log("msg", "Body matched CEL expression", "expression", httpConfig.FailIfBodyJSONMatchesCel)
level.Error(logger).Log("msg", "Body matched CEL expression", "expression", httpConfig.FailIfBodyJSONMatchesCel.Expression)
return false
}
}
Expand All @@ -111,7 +111,7 @@ func matchCelExpressions(ctx context.Context, reader io.Reader, httpConfig confi
return false
}
if result.Type() == cel.BoolType && !result.Value().(bool) {
level.Error(logger).Log("msg", "Body did not match CEL expression", "expression", httpConfig.FailIfBodyJSONNotMatchesCel)
level.Error(logger).Log("msg", "Body did not match CEL expression", "expression", httpConfig.FailIfBodyJSONNotMatchesCel.Expression)
return false
}
}
Expand Down

0 comments on commit 9131539

Please sign in to comment.