访问指标标签的 CronWorkflow 名称

Access CronWorkflow name for metrics labels

我有一个发送以下指标的 CronWorkflow:

apiVersion: argoproj.io/v1alpha1
kind: CronWorkflow
metadata:
  name: my-cron-wf
spec:
  schedule: "0 * * * *"
  suspend: false
  workflowSpec:
    metrics:
      prometheus:
        - name: wf_exec_duration_gauge
          help: "Duration gauge by workflow name and status"
          labels:
            - key: name
              value: my-cron-wf
            - key: status
              value: "{{workflow.status}}"
          gauge:
            value: "{{workflow.duration}}"

我想使用变量使用 CronWorkflow 名称填充指标的标签名称以避免复制它,但我没有找到它的变量。 我尝试使用 {{workflow.name}} 但它等于生成的工作流名称而不是所需的 CronWorkflow 名称。

我使用 Kustomize 来管理 argo 工作流资源,所以如果有 kustomize-way 来实现这一点,那就太好了.

Argo 工作流程automatically adds the name of the Cron Workflow as a label on the workflow. That label is accessible as a variable

apiVersion: argoproj.io/v1alpha1
kind: CronWorkflow
metadata:
  name: my-cron-wf
spec:
  schedule: "0 * * * *"
  suspend: false
  workflowSpec:
    metrics:
      prometheus:
        - name: wf_exec_duration_gauge
          help: "Duration gauge by workflow name and status"
          labels:
            - key: name
              value: "{{workflow.labels.workflows.argoproj.io/cron-workflow}}"
            - key: status
              value: "{{workflow.status}}"
          gauge:
            value: "{{workflow.duration}}"