Skip to content

Commit

Permalink
feat: Expose exitCode to step level metrics (#4861)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Coufal <tcoufal@redhat.com>
  • Loading branch information
tumido authored Jan 12, 2021
1 parent 45c792a commit f38c9a2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ step.
|----------|------------|
| `status` | Phase status of the metric-emitting template |
| `duration` | Duration of the metric-emitting template in seconds (only applicable in `Template`-level metrics, for `Workflow`-level use `workflow.duration`) |
| `exitCode` | Exit code of the metric-emitting template |
| `inputs.parameters.<NAME>` | Input parameter of the metric-emitting template |
| `outputs.parameters.<NAME>` | Output parameter of the metric-emitting template |
| `outputs.result` | Output result of the metric-emitting template |
Expand Down
2 changes: 2 additions & 0 deletions workflow/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ const (
LocalVarStatus = "status"
// LocalVarResourcesDuration is a step level variable (currently only available in metric emission) that tracks the resources duration of the step
LocalVarResourcesDuration = "resourcesDuration"
// LocalVarExitCode is a step level variable (currently only available in metric emission) that tracks the step's exit code
LocalVarExitCode = "exitCode"

KubeConfigDefaultMountPath = "/kube/config"
KubeConfigDefaultVolumeName = "kubeconfig"
Expand Down
3 changes: 3 additions & 0 deletions workflow/controller/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ func (woc *wfOperationCtx) prepareMetricScope(node *wfv1.NodeStatus) (map[string
if node.Outputs.Result != nil {
localScope["outputs.result"] = *node.Outputs.Result
}
if node.Outputs.ExitCode != nil {
localScope[common.LocalVarExitCode] = *node.Outputs.ExitCode
}
for _, param := range node.Outputs.Parameters {
key := fmt.Sprintf("outputs.parameters.%s", param.Name)
localScope[key] = param.Value.String()
Expand Down
1 change: 1 addition & 0 deletions workflow/controller/steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func TestResourceDurationMetric(t *testing.T) {
localScope, _ := woc.prepareMetricScope(&node)
assert.Equal(t, "33", localScope["resourcesDuration.cpu"])
assert.Equal(t, "24", localScope["resourcesDuration.memory"])
assert.Equal(t, "0", localScope["exitCode"])
}
}

Expand Down

0 comments on commit f38c9a2

Please sign in to comment.