Skip to content

Commit

Permalink
feat: Don't store empty command results
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Aug 16, 2023
1 parent bfbe09c commit 492b361
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/controllers/kluctl_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,16 +679,24 @@ func (pt *preparedTarget) handleCommandResult(ctx context.Context, cmdErr error,
// the ref is not properly set by addGitInfo due to the way the repo cache checks out by commit
cmdResult.GitInfo.Ref = &pt.pp.co.CheckedOutRef

if pt.pp.r.ResultStore != nil {
summary := cmdResult.BuildSummary()
needStore := summary.NewObjects != 0 ||
summary.ChangedObjects != 0 ||
summary.OrphanObjects != 0 ||
summary.DeletedObjects != 0 ||
len(summary.Errors) != 0 ||
len(summary.Warnings) != 0

if !needStore {
log.Info("skipping storing of empty command result")
} else if pt.pp.r.ResultStore != nil {
log.Info(fmt.Sprintf("Writing command result %s", cmdResult.Id))
err = pt.pp.r.ResultStore.WriteCommandResult(cmdResult)
if err != nil {
log.Error(err, "Writing command result failed")
}
}

summary := cmdResult.BuildSummary()

log.Info(fmt.Sprintf("command finished with err=%v", cmdErr))
defer pt.exportCommandResultMetricsToProm(summary)

Expand Down

0 comments on commit 492b361

Please sign in to comment.