Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new cron workflow trigger counter metric #13274

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ Metrics for the [Four Golden Signals](https://sre.google/sre-book/monitoring-dis
Some metric attributes may have high cardinality and are marked with ⚠️ to warn you. You may need to disable this metric or disable the attribute.
<!-- titles should be the exact metric name for deep-linking, alphabetical ordered -->
<!-- titles are without argo_workflows prefix -->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably add a new line above and below this comment. A bit surprised markdownlint didn't require that

#### `cronworkflows_triggered_total`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> v3.6 and after

Version reference

A counter of the number of times a CronWorkflow has been
Joibel marked this conversation as resolved.
Show resolved Hide resolved

| attribute | explanation |
|-------------|-------------------------------------------|
| `name` | ⚠️ The name of the CronWorkflow. |
| `namespace` | The namespace in which the pod is running |

#### `gauge`

A gauge of the number of workflows currently in the cluster in each phase. The `Running` count does not mean that a workflows pods are running, just that the controller has scheduled them. A workflow can be stuck in `Running` with pending pods for a long time.
Expand Down
1 change: 1 addition & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ These notes explain the differences in using the Prometheus `/metrics` endpoint

The following are new metrics:

* `cronworkflows_triggered_total`
* `is_leader`
* `k8s_request_duration`
* `pods_total_count`
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package e2e

import (
"testing"
"time"

"github.com/gavv/httpexpect/v2"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -109,6 +110,22 @@ func (s *MetricsSuite) TestFailedMetric() {
})
}

func (s *MetricsSuite) TestCronTriggeredCounter() {
s.Given().
CronWorkflow(`@testdata/cronworkflow-metrics.yaml`).
When().
CreateCronWorkflow().
Wait(1 * time.Minute). // This pattern is used in cron_test.go too
Then().
ExpectCron(func(t *testing.T, cronWf *wfv1.CronWorkflow) {
s.e(s.T()).GET("").
Expect().
Status(200).
Body().
Contains(`cronworkflows_triggered_total{name="test-cron-metric",namespace="argo"} 1`)
})
}

func TestMetricsSuite(t *testing.T) {
suite.Run(t, new(MetricsSuite))
}
19 changes: 19 additions & 0 deletions test/e2e/testdata/cronworkflow-metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: argoproj.io/v1alpha1
kind: CronWorkflow
metadata:
name: test-cron-metric
spec:
schedule: "* * * * *"
concurrencyPolicy: "Allow"
startingDeadlineSeconds: 0
workflowSpec:
metadata:
labels:
workflows.argoproj.io/test: "true"
podGC:
strategy: OnPodCompletion
entrypoint: whalesay
templates:
- name: whalesay
container:
image: argoproj/argosay:v2
1 change: 1 addition & 0 deletions workflow/cron/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (woc *cronWfOperationCtx) run(ctx context.Context, scheduledRuntime time.Ti
defer woc.persistUpdate(ctx)

woc.log.Infof("Running %s", woc.name)
woc.metrics.CronWfTrigger(ctx, woc.name, woc.cronWf.ObjectMeta.Namespace)

// If the cron workflow has a schedule that was just updated, update its annotation
if woc.cronWf.IsUsingNewSchedule() {
Expand Down
25 changes: 25 additions & 0 deletions workflow/metrics/counter_cronworkflow_trigger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package metrics

import (
"context"
)

const (
nameCronTriggered = `cronworkflows_triggered_total`
)

func addCronWfTriggerCounter(_ context.Context, m *Metrics) error {
return m.createInstrument(int64Counter,
nameCronTriggered,
"Total number of cron workflows triggered",
"{cronworkflow}",
withAsBuiltIn(),
)
}

func (m *Metrics) CronWfTrigger(ctx context.Context, name, namespace string) {
m.addInt(ctx, nameCronTriggered, 1, instAttribs{
{name: labelCronWFName, value: name},
{name: labelWorkflowNamespace, value: namespace},
})
}
2 changes: 2 additions & 0 deletions workflow/metrics/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const (
labelBuildGitTreeState string = `git_treestate`
labelBuildGitTag string = `git_tag`

labelCronWFName string = `name`

labelErrorCause string = "cause"

labelLogLevel string = `level`
Expand Down
1 change: 1 addition & 0 deletions workflow/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func New(ctx context.Context, serviceName string, config *Config, callbacks Call
addPodPhaseCounter,
addPodMissingCounter,
addWorkflowPhaseGauge,
addCronWfTriggerCounter,
addOperationDurationHistogram,
addErrorCounter,
addLogCounter,
Expand Down
Loading