Skip to content

Commit

Permalink
fix: Merge templateDefaults into dag task tmpl. Fixes #12821 (#12833)
Browse files Browse the repository at this point in the history
Signed-off-by: oninowang <oninowang@tencent.com>
Co-authored-by: jswxstw <jswxstw@gmail.com>
(cherry picked from commit 465c7b6)
  • Loading branch information
jswxstw authored and agilgur5 committed Jun 14, 2024
1 parent e8f0cae commit 028f9ec
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/e2e/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ func (s *MetricsSuite) TestRetryMetrics() {
})
}

func (s *MetricsSuite) TestDAGMetrics() {
s.Given().
Workflow(`@testdata/workflow-dag-metrics.yaml`).
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeSucceeded).
Then().
ExpectWorkflow(func(t *testing.T, metadata *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
assert.Equal(t, wfv1.WorkflowSucceeded, status.Phase)
s.e(s.T()).GET("").
Expect().
Status(200).
Body().
Contains(`argo_workflows_result_counter{status="Succeeded"} 5`)
})
}

func TestMetricsSuite(t *testing.T) {
suite.Run(t, new(MetricsSuite))
}
47 changes: 47 additions & 0 deletions test/e2e/testdata/workflow-dag-metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dag-diamond-
spec:
entrypoint: diamond
templateDefaults:
metrics:
prometheus:
- name: result_counter
help: "Count of step execution by result status"
labels:
- key: status
value: "{{status}}"
counter:
value: "1"
templates:
- name: diamond
dag:
tasks:
- name: A
template: echo
arguments:
parameters: [{name: message, value: A}]
- name: B
depends: "A"
template: echo
arguments:
parameters: [{name: message, value: B}]
- name: C
depends: "A"
template: echo
arguments:
parameters: [{name: message, value: C}]
- name: D
depends: "B && C"
template: echo
arguments:
parameters: [{name: message, value: D}]

- name: echo
inputs:
parameters:
- name: message
container:
image: alpine:3.7
command: [echo, "{{inputs.parameters.message}}"]
4 changes: 4 additions & 0 deletions workflow/controller/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ func (woc *wfOperationCtx) executeDAGTask(ctx context.Context, dagCtx *dagContex
if node != nil && node.Fulfilled() {
// Collect the completed task metrics
_, tmpl, _, _ := dagCtx.tmplCtx.ResolveTemplate(task)
if err := woc.mergedTemplateDefaultsInto(tmpl); err != nil {
woc.markNodeError(node.Name, err)
return
}
if tmpl != nil && tmpl.Metrics != nil {
if prevNodeStatus, ok := woc.preExecutionNodePhases[node.ID]; ok && !prevNodeStatus.Fulfilled() {
localScope, realTimeScope := woc.prepareMetricScope(node)
Expand Down

0 comments on commit 028f9ec

Please sign in to comment.