This is an automated email from the ASF dual-hosted git repository.
rbstp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 16c5b928c fix(argoCD): avoid duplication of latest deployments (#8862)
16c5b928c is described below
commit 16c5b928c42a277e2c06c1b6082e12dcf58d1443
Author: Anton Tarasevich <[email protected]>
AuthorDate: Tue Apr 28 17:19:37 2026 +0300
fix(argoCD): avoid duplication of latest deployments (#8862)
---
.../argocd/tasks/sync_operation_extractor.go | 24 +++++++++++++++++
.../argocd/tasks/sync_operation_extractor_test.go | 30 +++++++++++++++++++++-
2 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/backend/plugins/argocd/tasks/sync_operation_extractor.go
b/backend/plugins/argocd/tasks/sync_operation_extractor.go
index ae90584dc..6ea7f7858 100644
--- a/backend/plugins/argocd/tasks/sync_operation_extractor.go
+++ b/backend/plugins/argocd/tasks/sync_operation_extractor.go
@@ -188,6 +188,12 @@ func ExtractSyncOperations(taskCtx plugin.SubTaskContext)
errors.Error {
isOperationState := apiOp.Phase != ""
+ // operationState always represents the same sync as
the latest history entry
+ // (when phase=Succeeded). Skip it to avoid the
duplicate DeploymentId.
+ if isOperationState &&
isRedundantOperationState(apiOp.Phase) {
+ return nil, nil
+ }
+
// For multi-source apps ArgoCD sets revisions[]
instead of revision. Resolve
// the single commit SHA we care about before deciding
whether to skip this entry.
if apiOp.Revision == "" {
@@ -534,3 +540,21 @@ func isCommitSHA(s string) bool {
}
return true
}
+
+// isRedundantOperationState reports whether an operationState entry should be
+// skipped because it duplicates the most recent history entry.
+//
+// ArgoCD exposes a completed sync in two places:
+// - status.history[] — authoritative log, one entry per sync
+// - status.operationState — mirrors the last sync while it is current
+//
+// When phase is Succeeded the operationState is always already present in
+// history[]. Emitting it would produce a second ArgocdSyncOperation whose
+// DeploymentId differs by one second (startedAt vs deployedAt), creating a
+// duplicate deployment in DORA metrics.
+//
+// In-flight (Running, Terminating) and terminal-failure (Failed, Error) states
+// are not yet — or may never be — written to history, so they must be kept.
+func isRedundantOperationState(phase string) bool {
+ return phase == "Succeeded"
+}
diff --git a/backend/plugins/argocd/tasks/sync_operation_extractor_test.go
b/backend/plugins/argocd/tasks/sync_operation_extractor_test.go
index 59f95e5ad..f3f9e23ca 100644
--- a/backend/plugins/argocd/tasks/sync_operation_extractor_test.go
+++ b/backend/plugins/argocd/tasks/sync_operation_extractor_test.go
@@ -143,7 +143,7 @@ func TestIsCommitSHA(t *testing.T) {
assert.True(t, isCommitSHA("AABBCCDD11223344AABBCCDD11223344AABBCCDD"))
assert.False(t, isCommitSHA("2.6.2"))
assert.False(t, isCommitSHA(""))
- assert.False(t, isCommitSHA("5dd95b4efd7e9b668c361bbddb8d7f1e56c32ac"))
// 39 chars
+ assert.False(t, isCommitSHA("5dd95b4efd7e9b668c361bbddb8d7f1e56c32ac"))
// 39 chars
assert.False(t,
isCommitSHA("5dd95b4efd7e9b668c361bbddb8d7f1e56c32ac12")) // 41 chars
}
@@ -216,3 +216,31 @@ func TestIsGitHostedURL(t *testing.T) {
assert.False(t, isGitHostedURL("s3://my-bucket/charts"))
assert.False(t, isGitHostedURL(""))
}
+
+// ── isRedundantOperationState
─────────────────────────────────────────────────
+
+func TestIsRedundantOperationState_SucceededIsSkipped(t *testing.T) {
+ assert.True(t, isRedundantOperationState("Succeeded"),
+ "Succeeded operationState always duplicates the latest history
entry")
+}
+
+func TestIsRedundantOperationState_NonTerminalPhasesAreKept(t *testing.T) {
+ for _, phase := range []string{"Running", "Terminating"} {
+ assert.False(t, isRedundantOperationState(phase),
+ "in-flight phase %q is not yet in history and must be
kept", phase)
+ }
+}
+
+func TestIsRedundantOperationState_FailurePhasesAreKept(t *testing.T) {
+ for _, phase := range []string{"Failed", "Error"} {
+ assert.False(t, isRedundantOperationState(phase),
+ "failure phase %q may never reach history and must be
kept", phase)
+ }
+}
+
+func TestIsRedundantOperationState_HistoryEntryHasNoPhase(t *testing.T) {
+ // History entries have phase="" — isOperationState is false before this
+ // function is called, but double-check the function itself is safe with
+ // an empty string so the guard can never accidentally suppress history
rows.
+ assert.False(t, isRedundantOperationState(""))
+}