pre-seed metrics from imagebuilds#278
Conversation
To avoid losing data on restarts, pre-seed the metrics based on CRs Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com> Assisted-by: claude-opus-4.6
📝 WalkthroughWalkthroughThe PR extends ImageBuild status with a ChangesImageBuild Metrics Seeding and Previous Phase Tracking
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/controller/imagebuild/metrics.go`:
- Around line 152-154: The current seeding only increments FlashTotal when
b.Status.FlashTaskRunName != "" (standalone flash); update the seeding logic to
also detect pipeline-based flashes and increment FlashTotal for them.
Concretely, extend the conditional that checks b.Status.FlashTaskRunName to also
call a helper like isPipelineFlashCompleted(b) (or reuse the same
completion-detection logic from recordPipelineFlashMetrics / checkBuildProgress)
so that builds which completed flashing inline in the pipeline are counted
during startup; ensure the helper mirrors the exact completion criteria used by
recordPipelineFlashMetrics/checkBuildProgress to avoid double-counting.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 82c84b19-3f85-4768-8f71-271b3cc97d8e
⛔ Files ignored due to path filters (1)
config/crd/bases/automotive.sdv.cloud.redhat.com_imagebuilds.yamlis excluded by!config/crd/bases/**
📒 Files selected for processing (4)
api/v1alpha1/imagebuild_types.gointernal/controller/imagebuild/controller.gointernal/controller/imagebuild/metrics.gointernal/controller/imagebuild/metrics_test.go
| if b.Status.FlashTaskRunName != "" { | ||
| FlashTotal.WithLabelValues(target, status).Add(1) | ||
| } |
There was a problem hiding this comment.
FlashTotal seeding misses pipeline-based flash builds.
b.Status.FlashTaskRunName != "" is only set by the standalone flash path (createFlashTaskRun → handleFlashingState). For builds where flash runs inline in the build pipeline (recordPipelineFlashMetrics / checkBuildProgress), FlashTaskRunName is never populated. After an operator restart, those builds' flash counts won't be pre-seeded into FlashTotal.
A targeted fix for pipeline flash (where flash completing implies build success):
🛠️ Proposed fix
- if b.Status.FlashTaskRunName != "" {
- FlashTotal.WithLabelValues(target, status).Add(1)
- }
+ // Standalone flash (separate TaskRun) — FlashTaskRunName is set directly.
+ // Pipeline flash (inline task) — infer from spec: if flash was enabled and
+ // the build succeeded, the pipeline flash step must have completed.
+ flashRan := b.Status.FlashTaskRunName != "" ||
+ (b.Spec.IsFlashEnabled() && status == buildStatusSuccess)
+ if flashRan {
+ FlashTotal.WithLabelValues(target, status).Add(1)
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if b.Status.FlashTaskRunName != "" { | |
| FlashTotal.WithLabelValues(target, status).Add(1) | |
| } | |
| // Standalone flash (separate TaskRun) — FlashTaskRunName is set directly. | |
| // Pipeline flash (inline task) — infer from spec: if flash was enabled and | |
| // the build succeeded, the pipeline flash step must have completed. | |
| flashRan := b.Status.FlashTaskRunName != "" || | |
| (b.Spec.IsFlashEnabled() && status == buildStatusSuccess) | |
| if flashRan { | |
| FlashTotal.WithLabelValues(target, status).Add(1) | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/controller/imagebuild/metrics.go` around lines 152 - 154, The
current seeding only increments FlashTotal when b.Status.FlashTaskRunName != ""
(standalone flash); update the seeding logic to also detect pipeline-based
flashes and increment FlashTotal for them. Concretely, extend the conditional
that checks b.Status.FlashTaskRunName to also call a helper like
isPipelineFlashCompleted(b) (or reuse the same completion-detection logic from
recordPipelineFlashMetrics / checkBuildProgress) so that builds which completed
flashing inline in the pipeline are counted during startup; ensure the helper
mirrors the exact completion criteria used by
recordPipelineFlashMetrics/checkBuildProgress to avoid double-counting.
…trics pre-seed metrics from imagebuilds
To avoid losing data on restarts, pre-seed the metrics based on CRs
Summary
Related Issues
Type of Change
Testing
make test)make lint)make manifests generate)Summary by CodeRabbit
New Features
Bug Fixes
Tests