Skip to content

[Cloud Run Jobs] Enhanced Metrics#39246

Merged
dd-mergequeue[bot] merged 23 commits into
mainfrom
nicholas.hulston/cloud-run-jobs-enhanced-metrics
Jul 30, 2025
Merged

[Cloud Run Jobs] Enhanced Metrics#39246
dd-mergequeue[bot] merged 23 commits into
mainfrom
nicholas.hulston/cloud-run-jobs-enhanced-metrics

Conversation

@nhulston

@nhulston nhulston commented Jul 24, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Fix flushing enhanced metrics at the end of a Cloud Run Job. The container shuts down immediately after execution is done, so we need to force flush dogstatsd
  • Rename Cloud Run Jobs start+end metrics to gcp.run.job.enhanced.task.started and gcp.run.job.enhanced.task.ended to clarify that each metric is per task, not per execution. And better align with the naming convention set by Step Functions
  • Add a gcp.run.job.enhanced.task.duration metric in unit milliseconds
  • Due to cyclic imports, I had to do some refactoring. I removed the originToMetricSource() method and instead, each cloudservice implements a GetSource() method
  • I added default descriptions and units for these metrics: https://github.com/DataDog/integrations-internal-core/pull/1926
Screenshot 2025-07-24 at 12 50 02 PM Screenshot 2025-07-24 at 12 49 49 PM Screenshot 2025-07-25 at 12 43 00 PM

Motivation

Better enhanced metrics for Cloud Run Jobs

Describe how you validated your changes

Tested manually and verified that all metrics are delivered with the correct values and tags.

Possible Drawbacks / Trade-offs

Additional Notes

@github-actions github-actions Bot added the medium review PR review might take time label Jul 24, 2025
Comment thread cmd/serverless-init/main.go Outdated
Comment on lines 115 to 118
func (d *ServerlessDemultiplexer) ForceFlushToSerializer(start time.Time, waitForSerializer bool) {
d.forceFlushToSerializer(start, waitForSerializer, false)
_, forceFlushAll := os.LookupEnv(cloudservice.CloudRunJobNameEnvVar)
d.forceFlushToSerializer(start, waitForSerializer, forceFlushAll)
}

@nhulston nhulston Jul 24, 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.

This is not optimal, but I can't think of any other way to do this. Unless we modify ForceFlushToSerializer in the Demultiplexer interface, which affects the entire agent, not just serverless

Update: I also tried enabling dogstatsd_flush_incomplete_buckets, but that did not solve the problem

@nhulston nhulston added the qa/done QA done before merge and regressions are covered by tests label Jul 24, 2025
@cit-pr-commenter

cit-pr-commenter Bot commented Jul 24, 2025

Copy link
Copy Markdown

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: 7f63181e-0c4f-41ec-9798-3656781a7f5e

Baseline: 22d66d9
Comparison: 5c4d05b
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 +4.58 [+1.42, +7.73] 1 Logs

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
docker_containers_cpu % cpu utilization +4.58 [+1.42, +7.73] 1 Logs
docker_containers_memory memory utilization +0.42 [+0.38, +0.47] 1 Logs
tcp_syslog_to_blackhole ingress throughput +0.29 [+0.22, +0.36] 1 Logs
otlp_ingest_metrics memory utilization +0.29 [+0.15, +0.43] 1 Logs
ddot_logs memory utilization +0.28 [+0.19, +0.38] 1 Logs
file_tree memory utilization +0.18 [+0.14, +0.22] 1 Logs
file_to_blackhole_0ms_latency egress throughput +0.06 [-0.53, +0.65] 1 Logs
file_to_blackhole_1000ms_latency egress throughput +0.05 [-0.55, +0.65] 1 Logs
quality_gate_idle_all_features memory utilization +0.05 [-0.01, +0.10] 1 Logs bounds checks dashboard
quality_gate_idle memory utilization +0.02 [-0.02, +0.05] 1 Logs bounds checks dashboard
uds_dogstatsd_to_api ingress throughput +0.01 [-0.32, +0.33] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput +0.00 [-0.02, +0.02] 1 Logs
file_to_blackhole_500ms_latency egress throughput -0.01 [-0.57, +0.55] 1 Logs
file_to_blackhole_100ms_latency egress throughput -0.04 [-0.69, +0.61] 1 Logs
otlp_ingest_logs memory utilization -0.10 [-0.23, +0.02] 1 Logs
quality_gate_logs % cpu utilization -0.13 [-2.88, +2.63] 1 Logs bounds checks dashboard
ddot_metrics memory utilization -0.24 [-0.36, -0.12] 1 Logs
uds_dogstatsd_20mb_12k_contexts_20_senders memory utilization -0.58 [-0.62, -0.54] 1 Logs
quality_gate_metrics_logs memory utilization -1.47 [-1.86, -1.08] 1 Logs bounds checks dashboard

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_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 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_metrics_logs, bounds check cpu_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 memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.

@agent-platform-auto-pr

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

Copy link
Copy Markdown
Contributor

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor 22d66d9

Successful checks

Info

Quality gate Delta On disk size (MiB) Delta On wire size (MiB)
agent_deb_amd64 $${0}$$ $${699.53}$$ < $${704.84}$$ $${-0.02}$$ $${177.12}$$ < $${178.58}$$
agent_deb_amd64_fips $${0}$$ $${697.78}$$ < $${703.09}$$ $${-0.03}$$ $${176.54}$$ < $${178.12}$$
agent_heroku_amd64 $${0}$$ $${349.7}$$ < $${355.37}$$ $${-0.01}$$ $${93.79}$$ < $${95.72}$$
agent_msi $${+0}$$ $${974.43}$$ < $${979.61}$$ $${-0.03}$$ $${147.61}$$ < $${149.31}$$
agent_rpm_amd64 $${0}$$ $${699.52}$$ < $${704.83}$$ $${+0.02}$$ $${178.75}$$ < $${180.22}$$
agent_rpm_amd64_fips $${0}$$ $${697.77}$$ < $${703.08}$$ $${-0.01}$$ $${178.42}$$ < $${179.85}$$
agent_rpm_arm64 $${0}$$ $${688.5}$$ < $${694.74}$$ $${+0.01}$$ $${161.81}$$ < $${163.96}$$
agent_rpm_arm64_fips $${0}$$ $${686.81}$$ < $${693.05}$$ $${+0.02}$$ $${160.86}$$ < $${163.0}$$
agent_suse_amd64 $${0}$$ $${699.52}$$ < $${704.83}$$ $${+0.02}$$ $${178.75}$$ < $${180.22}$$
agent_suse_amd64_fips $${0}$$ $${697.77}$$ < $${703.08}$$ $${-0.01}$$ $${178.42}$$ < $${179.85}$$
agent_suse_arm64 $${0}$$ $${688.5}$$ < $${694.74}$$ $${+0.01}$$ $${161.81}$$ < $${163.96}$$
agent_suse_arm64_fips $${0}$$ $${686.81}$$ < $${693.05}$$ $${+0.02}$$ $${160.86}$$ < $${163.0}$$
docker_agent_amd64 $${-0}$$ $${781.25}$$ < $${788.65}$$ $${-0}$$ $${269.25}$$ < $${272.01}$$
docker_agent_arm64 $${+0}$$ $${793.56}$$ < $${802.0}$$ $${+0.01}$$ $${256.08}$$ < $${259.7}$$
docker_agent_jmx_amd64 $${-0}$$ $${972.55}$$ < $${979.84}$$ $${+0}$$ $${338.3}$$ < $${340.95}$$
docker_agent_jmx_arm64 $${+0}$$ $${973.46}$$ < $${981.8}$$ $${-0}$$ $${321.09}$$ < $${324.65}$$
docker_cluster_agent_amd64 $${+0}$$ $${214.01}$$ < $${214.5}$$ $${-0}$$ $${72.75}$$ < $${73.51}$$
docker_cluster_agent_arm64 $${-0}$$ $${229.88}$$ < $${230.33}$$ $${-0}$$ $${68.99}$$ < $${69.77}$$
docker_cws_instrumentation_amd64 $${0}$$ $${7.07}$$ < $${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.53}$$ < $${39.57}$$ $${-0}$$ $${14.88}$$ < $${15.76}$$
docker_dogstatsd_arm64 $${0}$$ $${37.23}$$ < $${38.2}$$ $${+0}$$ $${14.34}$$ < $${14.83}$$
dogstatsd_deb_amd64 $${0}$$ $${29.77}$$ < $${31.4}$$ $${-0}$$ $${7.85}$$ < $${8.95}$$
dogstatsd_deb_arm64 $${0}$$ $${28.37}$$ < $${29.97}$$ $${-0}$$ $${6.81}$$ < $${7.89}$$
dogstatsd_rpm_amd64 $${0}$$ $${29.77}$$ < $${31.4}$$ $${-0}$$ $${7.86}$$ < $${8.96}$$
dogstatsd_suse_amd64 $${0}$$ $${29.77}$$ < $${31.4}$$ $${-0}$$ $${7.86}$$ < $${8.96}$$
iot_agent_deb_amd64 $${0}$$ $${54.12}$$ < $${54.55}$$ $${-0}$$ $${13.64}$$ < $${14.45}$$
iot_agent_deb_arm64 $${0}$$ $${51.44}$$ < $${51.9}$$ $${-0.01}$$ $${11.8}$$ < $${12.63}$$
iot_agent_deb_armhf $${0}$$ $${50.95}$$ < $${51.42}$$ $${+0.04}$$ $${11.92}$$ < $${12.74}$$
iot_agent_rpm_amd64 $${0}$$ $${54.12}$$ < $${54.55}$$ $${-0}$$ $${13.66}$$ < $${14.47}$$
iot_agent_rpm_arm64 $${0}$$ $${51.44}$$ < $${51.91}$$ $${-0}$$ $${11.82}$$ < $${12.65}$$
iot_agent_suse_amd64 $${0}$$ $${54.12}$$ < $${54.55}$$ $${-0}$$ $${13.66}$$ < $${14.47}$$

@nhulston
nhulston marked this pull request as ready for review July 25, 2025 13:55
@nhulston
nhulston requested review from a team as code owners July 25, 2025 13:55
Comment thread pkg/aggregator/demultiplexer_serverless.go Outdated
@nhulston
nhulston marked this pull request as draft July 25, 2025 14:44
Comment thread cmd/serverless-init/cloudservice/cloudrun_jobs.go Outdated
Comment thread cmd/serverless-init/cloudservice/cloudrun_jobs.go Outdated
@nhulston
nhulston marked this pull request as ready for review July 25, 2025 17:50
@nhulston
nhulston requested a review from vickenty July 25, 2025 17:52
Comment thread cmd/serverless-init/cloudservice/service.go
@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 Jul 25, 2025
Comment thread cmd/serverless-init/main.go Outdated
Comment thread cmd/serverless-init/cloudservice/cloudrun_jobs.go
Comment thread cmd/serverless-init/main.go Outdated
Comment thread pkg/aggregator/demultiplexer_serverless.go
Comment thread cmd/serverless-init/cloudservice/cloudrun_jobs.go
Comment thread cmd/serverless-init/cloudservice/cloudrun.go Outdated
@nhulston
nhulston requested a review from a team as a code owner July 29, 2025 20:29
@nhulston
nhulston force-pushed the nicholas.hulston/cloud-run-jobs-enhanced-metrics branch from 0a8585e to 0064446 Compare July 29, 2025 20:30
@github-actions

Copy link
Copy Markdown
Contributor

Serverless Benchmark Results

BenchmarkStartEndInvocation comparison between 3f3ad3c and e223db58ab282a256f0b5ecdfc06374e819a1fb4.

tl;dr

Use these benchmarks as an insight tool during development.

  1. Skim down the vs base column in each chart. If there is a ~, then there was no statistically significant change to the benchmark. Otherwise, ensure the estimated percent change is either negative or very small.

  2. The last row of each chart is the geomean. Ensure this percentage is either negative or very small.

What is this benchmarking?

The BenchmarkStartEndInvocation compares the amount of time it takes to call the start-invocation and end-invocation endpoints. For universal instrumentation languages (Dotnet, Golang, Java, Ruby), this represents the majority of the duration overhead added by our tracing layer.

The benchmark is run using a large variety of lambda request payloads. In the charts below, there is one row for each event payload type.

How do I interpret these charts?

The charts below comes from benchstat. They represent the statistical change in duration (sec/op), memory overhead (B/op), and allocations (allocs/op).

The benchstat docs explain how to interpret these charts.

Before the comparison table, we see common file-level configuration. If there are benchmarks with different configuration (for example, from different packages), benchstat will print separate tables for each configuration.

The table then compares the two input files for each benchmark. It shows the median and 95% confidence interval summaries for each benchmark before and after the change, and an A/B comparison under "vs base". ... The p-value measures how likely it is that any differences were due to random chance (i.e., noise). The "~" means benchstat did not detect a statistically significant difference between the two inputs. ...

Note that "statistically significant" is not the same as "large": with enough low-noise data, even very small changes can be distinguished from noise and considered statistically significant. It is, of course, generally easier to distinguish large changes from noise.

Finally, the last row of the table shows the geometric mean of each column, giving an overall picture of how the benchmarks changed. Proportional changes in the geomean reflect proportional changes in the benchmarks. For example, given n benchmarks, if sec/op for one of them increases by a factor of 2, then the sec/op geomean will increase by a factor of ⁿ√2.

I need more help

First off, do not worry if the benchmarks are failing. They are not tests. The intention is for them to be a tool for you to use during development.

If you would like a hand interpreting the results come chat with us in #serverless-agent in the internal DataDog slack or in #serverless in the public DataDog slack. We're happy to help!

Benchmark stats

@nhulston
nhulston removed the request for review from a team July 29, 2025 20:49

@apiarian-datadog apiarian-datadog 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.

ok. if we're not going to fix the demultiplexer hack now, let's do it in a quick followup. at least to move the "is this cloudrun" boolean logic out of the demultiplexer file and up into the serverless-init main and/or cloudservice.

@nhulston

Copy link
Copy Markdown
Contributor Author

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Jul 30, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-07-30 18:35:08 UTC ℹ️ Start processing command /merge


2025-07-30 18:35:20 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-07-30 19:23:15 UTC ℹ️ MergeQueue: merge request added to the queue

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


2025-07-30 20:01:21 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue
dd-mergequeue Bot merged commit 1a205d7 into main Jul 30, 2025
264 of 265 checks passed
@dd-mergequeue
dd-mergequeue Bot deleted the nicholas.hulston/cloud-run-jobs-enhanced-metrics branch July 30, 2025 20:01
@github-actions github-actions Bot added this to the 7.70.0 milestone Jul 30, 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.

4 participants