Skip to content

Commit

Permalink
feat: DAG/TASK Custom Metrics Example (#5894)
Browse files Browse the repository at this point in the history
  • Loading branch information
everton-nasc authored May 14, 2021
1 parent 830a159 commit 128861c
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Workflow is the definition of a workflow resource

- [`dag-continue-on-fail.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-continue-on-fail.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)
Expand Down Expand Up @@ -461,6 +463,8 @@ WorkflowSpec is the specification of a Workflow.

- [`dag-continue-on-fail.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-continue-on-fail.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)
Expand Down Expand Up @@ -859,6 +863,8 @@ CronWorkflowSpec is the specification of a CronWorkflow

- [`dag-continue-on-fail.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-continue-on-fail.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)
Expand Down Expand Up @@ -1214,6 +1220,8 @@ WorkflowTemplateSpec is a spec of WorkflowTemplate.

- [`dag-continue-on-fail.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-continue-on-fail.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)
Expand Down Expand Up @@ -1546,6 +1554,8 @@ Arguments to a template

- [`daemon-step.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/daemon-step.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)
Expand Down Expand Up @@ -1731,6 +1741,8 @@ Metrics are a list of metrics emitted from a Workflow/Template
<br>

- [`custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/custom-metrics.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)
</details>

### Fields
Expand Down Expand Up @@ -2258,6 +2270,8 @@ Parameter indicate a passed string parameter to a service template with an optio

- [`dag-conditional-parameters.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-conditional-parameters.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)
Expand Down Expand Up @@ -2406,6 +2420,8 @@ Prometheus is a prometheus metric to be emitted
<br>

- [`custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/custom-metrics.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)
</details>

### Fields
Expand Down Expand Up @@ -2555,6 +2571,8 @@ DAGTemplate is a template subtype for directed acyclic graph templates

- [`dag-continue-on-fail.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-continue-on-fail.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)
Expand Down Expand Up @@ -2712,6 +2730,8 @@ Inputs are the mechanism for passing parameters, artifacts, volumes from one tem

- [`daemon-step.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/daemon-step.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)
Expand Down Expand Up @@ -3573,6 +3593,8 @@ Counter is a Counter prometheus metric
<br>

- [`custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/custom-metrics.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)
</details>

### Fields
Expand All @@ -3589,6 +3611,8 @@ Gauge is a Gauge prometheus metric
<br>

- [`custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/custom-metrics.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)
</details>

### Fields
Expand Down Expand Up @@ -3644,6 +3668,8 @@ MetricLabel is a single label for a prometheus metric

- [`dag-conditional-parameters.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-conditional-parameters.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`data-transformations.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/data-transformations.yaml)

- [`exit-handler-with-artifacts.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-handler-with-artifacts.yaml)
Expand Down Expand Up @@ -3761,6 +3787,8 @@ DAGTask represents a node in the graph during DAG execution

- [`dag-continue-on-fail.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-continue-on-fail.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)
Expand Down Expand Up @@ -3977,6 +4005,8 @@ Item expands a single workflow step into multiple parallel steps The value of It

- [`ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/ci.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)

- [`loops-dag.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/loops-dag.yaml)
Expand Down Expand Up @@ -4256,6 +4286,8 @@ ObjectMeta is metadata that all persisted resources must have, which includes al

- [`dag-continue-on-fail.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-continue-on-fail.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)
Expand Down Expand Up @@ -4840,6 +4872,8 @@ A single application container that you want to run within a pod.

- [`dag-continue-on-fail.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-continue-on-fail.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)
Expand Down Expand Up @@ -5501,6 +5535,8 @@ PersistentVolumeClaimSpec describes the common attributes of storage devices and

- [`dag-continue-on-fail.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-continue-on-fail.yaml)

- [`dag-custom-metrics.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-custom-metrics.yaml)

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`dag-diamond-steps.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-diamond-steps.yaml)
Expand Down
103 changes: 103 additions & 0 deletions examples/dag-custom-metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# The following workflow executes the tasks in parallel and emit the data for each task
# DAG <-- The custom metric will emit the status and duration for entire workflow
# / \
# / \
# / \
# / \
# / \
# / \
# / \
# / \
# / \
# / \
# TEST-TWO TEST-ONE
# / \ / \
# / \ / \
# / \ / \
# / \ / \
# TEST-TWO-B TEST-TWO-A TEST-ONE-B TEST-ONE-B <-- The custom metric will emit the status and duration for each task in parallel

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dag-task-
spec:
entrypoint: dag-task
metrics: # Custom metric workflow level
prometheus:
- name: playground_workflow_duration
help: "Duration gauge by workflow level"
labels:
- key: "playground_id_workflow"
value: "test"
- key: status
value: "{{workflow.status}}"
gauge:
realtime: false
value: "{{workflow.duration}}"
- name: playground_workflow_result_counter
help: "Count of workflow execution by result status - workflow level"
labels:
- key: "playground_id_workflow_counter"
value: "test"
- key: status
value: "{{workflow.status}}"
counter:
value: "1"
templates:
- name: dag-task
dag:
tasks:
- name: TEST-ONE
template: echo
arguments:
parameters:
- name: message
value: "console output-->TEST-{{item.command}}"
- name: tag
value: "{{item.tag}}"
withItems:
- { tag: TEST-ONE-A, command: ONE-A }
- { tag: TEST-ONE-B, command: ONE-B }

- name: TEST-TWO
template: echo
arguments:
parameters:
- name: message
value: "console output-->TEST-{{item.command}}"
- name: tag
value: "{{item.tag}}"
withItems:
- { tag: TEST-TWO-A, command: TWO-A }
- { tag: TEST-TWO-B, command: TWO-B }

- name: echo
inputs:
parameters:
- name: message
- name: tag
metrics: # Custom metric template level
prometheus:
- name: playground_workflow_duration_task_seconds
help: "Duration gauge by task name in seconds - task level"
labels:
- key: "playground_task_name"
value: "{{inputs.parameters.tag}}"
- key: status
value: "{{status}}"
gauge:
realtime: false
value: "{{duration}}"
- name: playground_workflow_result_task_counter
help: "Count of task execution by result status - task level"
labels:
- key: "playground_task_name_counter"
value: "{{inputs.parameters.tag}}"
- key: status
value: "{{status}}"
counter:
value: "1"
container:
image: alpine:3.7
command: [echo, "{{inputs.parameters.message}}"]

0 comments on commit 128861c

Please sign in to comment.