Skip to content

fix: set Failed/Succeeded counter for single-run Orders#430

Open
olzemal wants to merge 1 commit into
mainfrom
fix/418-status-counters
Open

fix: set Failed/Succeeded counter for single-run Orders#430
olzemal wants to merge 1 commit into
mainfrom
fix/418-status-counters

Conversation

@olzemal

@olzemal olzemal commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What

Closes #418

Checklist

  • Tests added/updated
  • No breaking changes (or upgrade path documented above)
  • Readable commit history (squashed and cleaned up as desired)
  • AI code review considered and comments resolved

Summary by CodeRabbit

  • Bug Fixes
    • Improved artifact workflow status counter reporting so succeeded and failed counts are updated correctly when workflows reach terminal states.
    • Order status now refreshes not only on phase changes, but also when success/failure counters and related scheduling details change.
  • Tests
    • Strengthened controller tests to verify succeeded/failed counters are incremented as expected.
    • Enhanced end-to-end checks to confirm every artifact workflow reports a succeeded count greater than 0 after the order reaches a succeeded state.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@olzemal, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0297faba-9139-4666-ba62-abd37e25a43b

📥 Commits

Reviewing files that changed from the base of the PR and between b81b3d4 and e05b322.

📒 Files selected for processing (4)
  • pkg/controller/artifactworkflow_controller_test.go
  • pkg/controller/order_controller.go
  • pkg/controller/workflow_handler.go
  • test/e2e/e2e_test.go
📝 Walkthrough

Walkthrough

This PR updates ArtifactWorkflow status handling so succeeded and failed counters are set from Argo Workflow phase, propagated into Order status, and verified in controller and e2e tests.

Changes

ArtifactWorkflow status counter propagation

Layer / File(s) Summary
Set terminal counters in workflow handler
pkg/controller/workflow_handler.go
CheckArgoResources sets Status.Succeeded or Status.Failed from Argo Workflow terminal phases and updates status when those fields change.
Propagate status fields in order reconciliation
pkg/controller/order_controller.go
Order reconciliation now compares Phase, Succeeded, Failed, and LastScheduled, copies workflow status on any difference, and uses anyStatusChanged to decide whether to update order status.
Assert succeeded and failed counters in tests
pkg/controller/artifactworkflow_controller_test.go, test/e2e/e2e_test.go
Controller tests now assert succeeded/failed counters in success, failure, and error cases, and the e2e test checks that order-status succeeded counters are greater than 0.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SingleWorkflowHandler
  participant ArgoWorkflow
  participant ArtifactWorkflow
  participant OrderReconciler
  participant Order

  SingleWorkflowHandler->>ArgoWorkflow: read wf.Status.Phase
  SingleWorkflowHandler->>ArtifactWorkflow: set succeeded/failed counter
  SingleWorkflowHandler->>ArtifactWorkflow: update status when changed
  OrderReconciler->>ArtifactWorkflow: compare workflow status fields
  OrderReconciler->>Order: copy WorkflowStatus when any field differs
  OrderReconciler->>Order: update order status when anyStatusChanged
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description only includes What and Checklist; it omits Why, Testing, and Notes for reviewers. Add the missing Why, Testing, and Notes for reviewers sections to match the template.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: populating Failed/Succeeded counters for single-run Orders.
Linked Issues check ✅ Passed The controller and handler updates preserve Succeeded/Failed counters and the tests cover the non-cron Order behavior in #418.
Out of Scope Changes check ✅ Passed The code changes and test updates are focused on the reported counter bug and do not introduce clear unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/418-status-counters

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/controller/workflow_handler.go (1)

86-100: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Unconditional forced update causes redundant status writes on every reconcile.

Once the phase becomes terminal, updated is unconditionally forced to true on every reconcile even if Succeeded/Failed is already set to the target value, triggering an unnecessary Status().Update() call (Line 103) repeatedly for the lifetime of the resource.

♻️ Proposed fix: only mark updated when the value actually changes
 	switch wf.Status.Phase {
 	case wfv1alpha1.WorkflowSucceeded:
-		h.aw.Status.Succeeded = 1
-		updated = true
+		if h.aw.Status.Succeeded != 1 {
+			h.aw.Status.Succeeded = 1
+			updated = true
+		}
 	case wfv1alpha1.WorkflowError, wfv1alpha1.WorkflowFailed:
-		h.aw.Status.Failed = 1
-		updated = true
-	default:
-		break
+		if h.aw.Status.Failed != 1 {
+			h.aw.Status.Failed = 1
+			updated = true
+		}
 	}
🤖 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 `@pkg/controller/workflow_handler.go` around lines 86 - 100, The workflow
status update path in setStatusFromWorkflow and the switch on wf.Status.Phase is
forcing updated to true even when h.aw.Status.Succeeded or h.aw.Status.Failed is
already set, causing repeated Status().Update() calls. Change the logic so
h.aw.Status.Succeeded/Failed is only assigned and updated is only set when the
current value actually differs from the desired terminal value, while keeping
the existing behavior for non-terminal phases.
🤖 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 `@test/e2e/e2e_test.go`:
- Around line 226-233: The current `artifactWorkflows` check in the e2e test can
still pass when `.status.artifactWorkflows` is empty, so strengthen the
assertion around the `kubectl get`/`strings.FieldsSeq` loop in `e2e_test.go` to
verify the template output is non-empty before iterating. Use the existing
`run`, `strings.FieldsSeq`, and `strconv.Atoi` flow, but add an explicit
non-empty assertion on the `output` (or collected fields) so the succeeded-count
check is guaranteed to run.

---

Nitpick comments:
In `@pkg/controller/workflow_handler.go`:
- Around line 86-100: The workflow status update path in setStatusFromWorkflow
and the switch on wf.Status.Phase is forcing updated to true even when
h.aw.Status.Succeeded or h.aw.Status.Failed is already set, causing repeated
Status().Update() calls. Change the logic so h.aw.Status.Succeeded/Failed is
only assigned and updated is only set when the current value actually differs
from the desired terminal value, while keeping the existing behavior for
non-terminal phases.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2cb1e428-f8d3-4171-b61f-c9f07ea15eb5

📥 Commits

Reviewing files that changed from the base of the PR and between 8931873 and 4adab38.

📒 Files selected for processing (4)
  • pkg/controller/artifactworkflow_controller_test.go
  • pkg/controller/order_controller.go
  • pkg/controller/workflow_handler.go
  • test/e2e/e2e_test.go

Comment thread test/e2e/e2e_test.go
@coveralls

coveralls commented Jul 1, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28522681173

Warning

No base build found for commit 69b4106 on main.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 84.534%

Details

  • Patch coverage: 25 of 25 lines across 2 files are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 944
Covered Lines: 798
Line Coverage: 84.53%
Coverage Strength: 1492.73 hits per line

💛 - Coveralls

@olzemal olzemal force-pushed the fix/418-status-counters branch from 4adab38 to b81b3d4 Compare July 1, 2026 13:36
@olzemal

olzemal commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@olzemal

olzemal commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@olzemal olzemal force-pushed the fix/418-status-counters branch from b81b3d4 to e05b322 Compare July 1, 2026 13:51

@yocaba yocaba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Succeeded / Failed Counter in Order Status stays at 0 for non-cron Orders

4 participants