Skip to content

Commit

Permalink
fix: Ensure resourceDuration variables in metrics are always in secon…
Browse files Browse the repository at this point in the history
…ds (argoproj#4411)

Signed-off-by: Simon Behar <[email protected]>
  • Loading branch information
simster7 committed Oct 28, 2020
1 parent 3aeb174 commit 462e55e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ step.
| `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 |
| `resourcesDuration` | Resources duration as a string. Can also be indexed for a selected resource, if available (may be one of `resourcesDuration.cpu` or `resourcesDuration.memory`. For more info, see the [Resource Duration](resource-duration.md) doc.|
| `resourcesDuration.{cpu,memory}` | Resources duration **in seconds**. Must be one of `resourcesDuration.cpu` or `resourcesDuration.memory`, if available. For more info, see the [Resource Duration](resource-duration.md) doc.|

### Realtime Metrics

Expand Down
3 changes: 1 addition & 2 deletions workflow/controller/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,8 @@ func (woc *wfOperationCtx) prepareMetricScope(node *wfv1.NodeStatus) (map[string
}

if node.ResourcesDuration != nil {
localScope[common.LocalVarResourcesDuration] = node.ResourcesDuration.String()
for name, duration := range node.ResourcesDuration {
localScope[fmt.Sprintf("%s.%s", common.LocalVarResourcesDuration, name)] = duration.String()
localScope[fmt.Sprintf("%s.%s", common.LocalVarResourcesDuration, name)] = fmt.Sprint(duration.Duration().Seconds())
}
}

Expand Down
6 changes: 2 additions & 4 deletions workflow/controller/steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ func TestResourceDurationMetric(t *testing.T) {
err := yaml.Unmarshal([]byte(nodeStatus), &node)
if assert.NoError(t, err) {
localScope, _ := woc.prepareMetricScope(&node)
assert.Contains(t, localScope["resourcesDuration"], "24s*(100Mi memory)")
assert.Contains(t, localScope["resourcesDuration"], "33s*(1 cpu)")
assert.Equal(t, "33s", localScope["resourcesDuration.cpu"])
assert.Equal(t, "24s", localScope["resourcesDuration.memory"])
assert.Equal(t, "33", localScope["resourcesDuration.cpu"])
assert.Equal(t, "24", localScope["resourcesDuration.memory"])
}
}

0 comments on commit 462e55e

Please sign in to comment.