Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure per-check logger carries the check name throughout execution #1196

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions internal/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,11 @@ func (c *craneEngine) ExecuteChecks(ctx context.Context) error {
// execute checks
logger.V(log.DBG).Info("executing checks")
for _, executedCheck := range c.checks {
logger := logger.WithValues("check", executedCheck.Name())
ctx := logr.NewContext(ctx, logger)
c.results.TestedImage = c.image

logger.V(log.DBG).Info("running check", "check", executedCheck.Name())
logger.V(log.DBG).Info("running check")
if executedCheck.Metadata().Level == check.LevelOptional || executedCheck.Metadata().Level == check.LevelWarn {
logger.Info(fmt.Sprintf("Check %s is not currently being enforced.", executedCheck.Name()))
}
Expand All @@ -230,7 +232,7 @@ func (c *craneEngine) ExecuteChecks(ctx context.Context) error {
checkElapsedTime := time.Since(checkStartTime)

if err != nil {
logger.WithValues("result", "ERROR", "err", err.Error()).Info("check completed", "check", executedCheck.Name())
logger.WithValues("result", "ERROR", "err", err.Error()).Info("check completed")
result := certification.Result{Check: executedCheck, ElapsedTime: checkElapsedTime}
c.results.Errors = appendUnlessOptional(c.results.Errors, *result.WithError(err))
continue
Expand All @@ -239,16 +241,16 @@ func (c *craneEngine) ExecuteChecks(ctx context.Context) error {
if !checkPassed {
// if a test doesn't pass but is of level warn include it in warning results, instead of failed results
if executedCheck.Metadata().Level == check.LevelWarn {
logger.WithValues("result", "WARNING").Info("check completed", "check", executedCheck.Name())
logger.WithValues("result", "WARNING").Info("check completed")
c.results.Warned = appendUnlessOptional(c.results.Warned, certification.Result{Check: executedCheck, ElapsedTime: checkElapsedTime})
continue
}
logger.WithValues("result", "FAILED").Info("check completed", "check", executedCheck.Name())
logger.WithValues("result", "FAILED").Info("check completed")
c.results.Failed = appendUnlessOptional(c.results.Failed, certification.Result{Check: executedCheck, ElapsedTime: checkElapsedTime})
continue
}

logger.WithValues("result", "PASSED").Info("check completed", "check", executedCheck.Name())
logger.WithValues("result", "PASSED").Info("check completed")
c.results.Passed = appendUnlessOptional(c.results.Passed, certification.Result{Check: executedCheck, ElapsedTime: checkElapsedTime})
}

Expand Down
Loading