Skip to content

[Serverless] Add exit_code tag to Cloud Run Jobs shutdown metric#41250

Merged
dd-mergequeue[bot] merged 14 commits into
mainfrom
nicholas.hulston/cloud-run-jobs-exit-code-tag
Sep 26, 2025
Merged

[Serverless] Add exit_code tag to Cloud Run Jobs shutdown metric#41250
dd-mergequeue[bot] merged 14 commits into
mainfrom
nicholas.hulston/cloud-run-jobs-exit-code-tag

Conversation

@nhulston

@nhulston nhulston commented Sep 24, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

Add an exit_code tag on the gcp.run.job.enhanced.task.ended metric.

Screenshot 2025-09-24 at 4 21 00 PM

Motivation

Will be used on the UI to display the exit code of each task, as well as to determine if the task succeeded (exit_code=0) or failed (exit_code!=0)

https://datadoghq.atlassian.net/browse/SVLS-7553

Describe how you validated your changes

Unit tests and manually deploying a container to Cloud Run Jobs with a custom build of the agent.

Additional Notes

This is easiest reviewed commit-by-commit

@github-actions github-actions Bot added the medium review PR review might take time label Sep 24, 2025
@agent-platform-auto-pr

agent-platform-auto-pr Bot commented Sep 24, 2025

Copy link
Copy Markdown
Contributor

Go Package Import Differences

Baseline: 00936fe
Comparison: c570e55

binaryosarchchange
serverlesslinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/serverless-init/exitcode
serverlesslinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/cmd/serverless-init/exitcode

@github-actions github-actions Bot added long review PR is complex, plan time to review it and removed medium review PR review might take time labels Sep 24, 2025
@nhulston nhulston added the qa/done QA done before merge and regressions are covered by tests label Sep 24, 2025
@cit-pr-commenter

cit-pr-commenter Bot commented Sep 24, 2025

Copy link
Copy Markdown

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: a98ddf17-0919-453d-ad27-845d299f0863

Baseline: 00936fe
Comparison: c570e55
Diff

Optimization Goals: ✅ No significant changes detected

Experiments ignored for regressions

Regressions in experiments with settings containing erratic: true are ignored.

perf experiment goal Δ mean % Δ mean % CI trials links
docker_containers_cpu % cpu utilization -0.22 [-3.27, +2.84] 1 Logs

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gate_logs % cpu utilization +1.06 [-1.70, +3.83] 1 Logs bounds checks dashboard
tcp_syslog_to_blackhole ingress throughput +0.86 [+0.80, +0.92] 1 Logs
quality_gate_metrics_logs memory utilization +0.72 [+0.50, +0.93] 1 Logs bounds checks dashboard
ddot_logs memory utilization +0.49 [+0.44, +0.54] 1 Logs
otlp_ingest_logs memory utilization +0.44 [+0.32, +0.55] 1 Logs
otlp_ingest_metrics memory utilization +0.34 [+0.22, +0.46] 1 Logs
uds_dogstatsd_20mb_12k_contexts_20_senders memory utilization +0.30 [+0.26, +0.34] 1 Logs
ddot_metrics_sum_cumulative memory utilization +0.09 [-0.03, +0.20] 1 Logs
file_to_blackhole_0ms_latency egress throughput +0.02 [-0.57, +0.61] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput +0.00 [-0.01, +0.01] 1 Logs
file_tree memory utilization -0.01 [-0.05, +0.02] 1 Logs
uds_dogstatsd_to_api ingress throughput -0.02 [-0.22, +0.19] 1 Logs
file_to_blackhole_100ms_latency egress throughput -0.02 [-0.58, +0.55] 1 Logs
file_to_blackhole_500ms_latency egress throughput -0.03 [-0.64, +0.58] 1 Logs
file_to_blackhole_1000ms_latency egress throughput -0.04 [-0.61, +0.53] 1 Logs
ddot_metrics memory utilization -0.18 [-0.34, -0.02] 1 Logs
docker_containers_cpu % cpu utilization -0.22 [-3.27, +2.84] 1 Logs
quality_gate_idle_all_features memory utilization -0.23 [-0.27, -0.20] 1 Logs bounds checks dashboard
ddot_metrics_sum_delta memory utilization -0.33 [-0.48, -0.17] 1 Logs
quality_gate_idle memory utilization -0.40 [-0.44, -0.37] 1 Logs bounds checks dashboard
ddot_metrics_sum_cumulativetodelta_exporter memory utilization -0.55 [-0.75, -0.35] 1 Logs
docker_containers_memory memory utilization -2.25 [-2.40, -2.11] 1 Logs

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed links
docker_containers_cpu simple_check_run 10/10
docker_containers_memory memory_usage 10/10
docker_containers_memory simple_check_run 10/10
file_to_blackhole_0ms_latency lost_bytes 10/10
file_to_blackhole_0ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency memory_usage 10/10
file_to_blackhole_100ms_latency lost_bytes 10/10
file_to_blackhole_100ms_latency memory_usage 10/10
file_to_blackhole_500ms_latency lost_bytes 10/10
file_to_blackhole_500ms_latency memory_usage 10/10
quality_gate_idle intake_connections 10/10 bounds checks dashboard
quality_gate_idle memory_usage 10/10 bounds checks dashboard
quality_gate_idle_all_features intake_connections 10/10 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 bounds checks dashboard
quality_gate_logs intake_connections 10/10 bounds checks dashboard
quality_gate_logs lost_bytes 10/10 bounds checks dashboard
quality_gate_logs memory_usage 10/10 bounds checks dashboard
quality_gate_metrics_logs cpu_usage 10/10 bounds checks dashboard
quality_gate_metrics_logs intake_connections 10/10 bounds checks dashboard
quality_gate_metrics_logs lost_bytes 10/10 bounds checks dashboard
quality_gate_metrics_logs memory_usage 10/10 bounds checks dashboard

Explanation

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

CI Pass/Fail Decision

Passed. All Quality Gates passed.

  • quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.

@agent-platform-auto-pr

agent-platform-auto-pr Bot commented Sep 24, 2025

Copy link
Copy Markdown
Contributor

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor 00936fe

Successful checks

Info

Quality gate Delta On disk size (MiB) Delta On wire size (MiB)
agent_deb_amd64 $${-0}$$ $${696.67}$$ < $${703.13}$$ $${-0.05}$$ $${175.34}$$ < $${178.38}$$
agent_deb_amd64_fips $${-0}$$ $${691.19}$$ < $${697.61}$$ $${-0}$$ $${173.92}$$ < $${177.15}$$
agent_heroku_amd64 $${0}$$ $${335.74}$$ < $${341.62}$$ $${+0}$$ $${88.89}$$ < $${91.52}$$
agent_msi $${0}$$ $${987.88}$$ < $${990.42}$$ $${-0.01}$$ $${150.79}$$ < $${152.42}$$
agent_rpm_amd64 $${-0}$$ $${696.66}$$ < $${703.12}$$ $${+0.03}$$ $${177.74}$$ < $${180.53}$$
agent_rpm_amd64_fips $${-0}$$ $${691.18}$$ < $${697.6}$$ $${+0.02}$$ $${176.06}$$ < $${178.87}$$
agent_rpm_arm64 $${-0}$$ $${682.76}$$ < $${689.82}$$ $${+0.01}$$ $${158.95}$$ < $${162.16}$$
agent_rpm_arm64_fips $${-0}$$ $${678.34}$$ < $${685.08}$$ $${-0.02}$$ $${157.83}$$ < $${161.11}$$
agent_suse_amd64 $${-0}$$ $${696.66}$$ < $${703.12}$$ $${+0.03}$$ $${177.74}$$ < $${180.53}$$
agent_suse_amd64_fips $${-0}$$ $${691.18}$$ < $${697.6}$$ $${+0.02}$$ $${176.06}$$ < $${178.87}$$
agent_suse_arm64 $${-0}$$ $${682.76}$$ < $${689.82}$$ $${+0.01}$$ $${158.95}$$ < $${162.16}$$
agent_suse_arm64_fips $${-0}$$ $${678.34}$$ < $${685.08}$$ $${-0.02}$$ $${157.83}$$ < $${161.11}$$
docker_agent_amd64 $${-0}$$ $${768.05}$$ < $${774.54}$$ $${-0}$$ $${263.07}$$ < $${266.46}$$
docker_agent_arm64 $${-0}$$ $${778.09}$$ < $${785.2}$$ $${-0}$$ $${249.14}$$ < $${252.92}$$
docker_agent_jmx_amd64 $${-0}$$ $${958.91}$$ < $${965.41}$$ $${+0}$$ $${331.72}$$ < $${335.08}$$
docker_agent_jmx_arm64 $${-0}$$ $${957.56}$$ < $${964.66}$$ $${+0}$$ $${313.77}$$ < $${317.54}$$
docker_cluster_agent_amd64 $${-0}$$ $${212.75}$$ < $${213.74}$$ $${+0}$$ $${72.18}$$ < $${73.2}$$
docker_cluster_agent_arm64 $${-0}$$ $${228.67}$$ < $${229.68}$$ $${-0}$$ $${68.46}$$ < $${69.48}$$
docker_cws_instrumentation_amd64 $${0}$$ $${7.06}$$ < $${7.12}$$ $${-0}$$ $${2.95}$$ < $${3.29}$$
docker_cws_instrumentation_arm64 $${0}$$ $${6.69}$$ < $${6.92}$$ $${+0}$$ $${2.7}$$ < $${3.07}$$
docker_dogstatsd_amd64 $${+0}$$ $${38.44}$$ < $${39.3}$$ $${+0}$$ $${14.84}$$ < $${15.76}$$
docker_dogstatsd_arm64 $${0}$$ $${37.12}$$ < $${37.94}$$ $${-0}$$ $${14.3}$$ < $${14.83}$$
dogstatsd_deb_amd64 $${0}$$ $${29.67}$$ < $${30.53}$$ $${-0}$$ $${7.82}$$ < $${8.75}$$
dogstatsd_deb_arm64 $${0}$$ $${28.26}$$ < $${29.12}$$ $${-0}$$ $${6.78}$$ < $${7.71}$$
dogstatsd_rpm_amd64 $${0}$$ $${29.67}$$ < $${30.53}$$ $${+0}$$ $${7.84}$$ < $${8.77}$$
dogstatsd_suse_amd64 $${0}$$ $${29.67}$$ < $${30.53}$$ $${+0}$$ $${7.84}$$ < $${8.77}$$
iot_agent_deb_amd64 $${0}$$ $${54.46}$$ < $${54.97}$$ $${-0}$$ $${13.6}$$ < $${14.45}$$
iot_agent_deb_arm64 $${0}$$ $${51.74}$$ < $${51.9}$$ $${+0}$$ $${11.73}$$ < $${12.63}$$
iot_agent_deb_armhf $${0}$$ $${51.3}$$ < $${51.84}$$ $${+0}$$ $${11.8}$$ < $${12.74}$$
iot_agent_rpm_amd64 $${0}$$ $${54.46}$$ < $${54.97}$$ $${-0}$$ $${13.62}$$ < $${14.47}$$
iot_agent_suse_amd64 $${0}$$ $${54.46}$$ < $${54.97}$$ $${-0}$$ $${13.62}$$ < $${14.47}$$

// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package exitcode

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this needs to live in its own package to avoid circular dependency

metricTimestamp := float64(time.Now().UnixNano()) / float64(time.Second)
tags := agent.GetExtraTags()
if len(extraTags) > 0 {
tags = append(append([]string{}, tags...), extraTags...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

copy the original tags so we don't modify the original

@nhulston
nhulston marked this pull request as ready for review September 25, 2025 13:59
@nhulston
nhulston requested review from a team as code owners September 25, 2025 13:59
return exitErr.ExitCode()
}

log.Debug("using default exit code 1")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is the default 1 and not nil or something? if the error is not a subprocess-failure-type error, why is this the place where we decide that it's "error-like" enough to merit calling it an exit status 1?

@nhulston nhulston Sep 25, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cc @duncanpharvey

I was keeping the logic of

func errorExitCode(err error) int {
// if error is of type exec.ExitError then propagate the exit code
var exitError *exec.ExitError
if errors.As(err, &exitError) {
exitCode := exitError.ExitCode()
log.Debugf("propagating exit code %v", exitCode)
return exitCode
}
// use exit code 1 if there is no exit code in the error to propagate
log.Debug("using default exit code 1")
return 1
}

but i think it makes sense here -- if err is not nil, then the exit code should not be 0, so 1 is the best default option

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe. i guess it depends on what this code is supposed to do.

if the code is supposed to extract the exit code from a runtime error, then it shouldn't invent one if it can't find a runtime error but found a different kind of error instead.

if the code is supposed to generate a numeric error code for us to include for error that may be a runtime error or not, the 1 default is sensible.

i would probably have stuck to former interpretation and let the caller do the "default is 1" logic (along with its logging; the fact that we're logging it is a hint that something fishy is going on).

it's a pretty minor thing so probably not something to really worry about of course.


// Shutdown emits the shutdown metric for CloudRun
func (c *CloudRun) Shutdown(agent serverlessMetrics.ServerlessMetricAgent) {
func (c *CloudRun) Shutdown(agent serverlessMetrics.ServerlessMetricAgent, _ error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if we're doing all this plumbing anyway, why not include the exit code in all of our shutdown metrics?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should we? This change here is just so we can include it in the Cloud Run Jobs UI, but we won't be using the exit_code tag for any other of the cloud services

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i suppose it's a product decision. is there a significant cost to adding this everywhere? seems like a pretty handy thing? though i guess if we don't need it, that's also fine.

Comment thread cmd/serverless-init/metric/metric.go
Comment thread cmd/serverless-init/main_test.go

@domalessi domalessi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Left a suggestion to make the release note more clear.

Comment thread releasenotes/notes/cloud-run-jobs-exit-code-tag-7ad4cb346978b9ed.yaml Outdated
---
enhancements:
- |
The `task.ended` enhanced shutdown metric for Cloud Run Jobs now includes the exit code as a tag.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we use the actual metric names here?

@apiarian-datadog

Copy link
Copy Markdown
Contributor

approved, though we should probably get some expert opinion re: the cardinality of the new tag we're adding.

@nhulston

Copy link
Copy Markdown
Contributor Author

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Sep 26, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-09-26 21:01:37 UTC ℹ️ Start processing command /merge


2025-09-26 21:01:44 UTC ℹ️ MergeQueue: waiting for PR to be ready

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2025-09-26 22:50:09 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in main is approximately 37m (p90).


2025-09-26 23:14:35 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue
dd-mergequeue Bot merged commit 2e94d58 into main Sep 26, 2025
273 checks passed
@dd-mergequeue
dd-mergequeue Bot deleted the nicholas.hulston/cloud-run-jobs-exit-code-tag branch September 26, 2025 23:14
@github-actions github-actions Bot added this to the 7.72.0 milestone Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

long review PR is complex, plan time to review it qa/done QA done before merge and regressions are covered by tests team/serverless-azure-gcp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants