Skip to content

Prevent deadlocks in the metrics client#44762

Merged
dd-mergequeue[bot] merged 4 commits intomainfrom
agagniere/fix-prometheus-deadlock
Jan 13, 2026
Merged

Prevent deadlocks in the metrics client#44762
dd-mergequeue[bot] merged 4 commits intomainfrom
agagniere/fix-prometheus-deadlock

Conversation

@agagniere
Copy link
Copy Markdown
Contributor

@agagniere agagniere commented Jan 5, 2026

What does this PR do?

Reduce the scope where the metrics client's mutex is held, to prevent a deadlock from happening when the meter's methods want to acquire another mutex

Motivation

Prevent a deadlock we've seen occurring in prod OTAGENT-753

Describe how you validated your changes

Reading the change

Additional Notes

I'm making the assumption that holding the lock is not required when using the meter, just like it is done in the Histogram and Count functions

@agagniere agagniere requested review from songy23 and truthbk January 5, 2026 16:28
@agagniere agagniere self-assigned this Jan 5, 2026
@agagniere agagniere requested a review from a team as a code owner January 5, 2026 16:28
@github-actions github-actions bot added the short review PR is simple enough to be reviewed quickly label Jan 5, 2026
@agagniere agagniere force-pushed the agagniere/fix-prometheus-deadlock branch from cb8e725 to fe83f31 Compare January 5, 2026 16:35
Copy link
Copy Markdown
Member

@songy23 songy23 left a comment

Choose a reason for hiding this comment

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

Is there a simple way to reproduce it in unit tests (e.g with a mock meter)? The change makes sense to me

Comment thread comp/otelcol/otlp/components/metricsclient/metrics_client.go
@agent-platform-auto-pr
Copy link
Copy Markdown
Contributor

agent-platform-auto-pr bot commented Jan 5, 2026

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor adfcd28
📊 Static Quality Gates Dashboard

Successful checks

Info

Quality gate Change Size (prev → curr → max)
agent_deb_amd64 -81.26 KiB (0.01% reduction) 705.398 → 705.319 → 708.410
agent_deb_amd64_fips -81.26 KiB (0.01% reduction) 700.680 → 700.600 → 704.000
agent_heroku_amd64 -80.78 KiB (0.02% reduction) 326.998 → 326.919 → 329.530
agent_msi -77.01 KiB (0.01% reduction) 571.530 → 571.454 → 982.080
agent_rpm_amd64 -81.26 KiB (0.01% reduction) 705.385 → 705.305 → 708.380
agent_rpm_amd64_fips -81.26 KiB (0.01% reduction) 700.666 → 700.587 → 703.990
agent_rpm_arm64 -81.12 KiB (0.01% reduction) 686.969 → 686.890 → 693.520
agent_rpm_arm64_fips -81.12 KiB (0.01% reduction) 683.051 → 682.972 → 688.480
agent_suse_amd64 -81.26 KiB (0.01% reduction) 705.385 → 705.305 → 708.380
agent_suse_amd64_fips -81.26 KiB (0.01% reduction) 700.666 → 700.587 → 703.990
agent_suse_arm64 -81.12 KiB (0.01% reduction) 686.969 → 686.890 → 693.520
agent_suse_arm64_fips -81.12 KiB (0.01% reduction) 683.051 → 682.972 → 688.480
docker_agent_amd64 -79.47 KiB (0.01% reduction) 767.611 → 767.534 → 770.720
docker_agent_arm64 -79.32 KiB (0.01% reduction) 773.755 → 773.677 → 780.200
docker_agent_jmx_amd64 -79.45 KiB (0.01% reduction) 958.490 → 958.412 → 961.600
docker_agent_jmx_arm64 -79.32 KiB (0.01% reduction) 953.352 → 953.275 → 959.800
15 successful checks with minimal change (< 2 KiB)
Quality gate Current Size
docker_cluster_agent_amd64 180.790 MiB
docker_cluster_agent_arm64 196.620 MiB
docker_cws_instrumentation_amd64 7.135 MiB
docker_cws_instrumentation_arm64 6.689 MiB
docker_dogstatsd_amd64 38.808 MiB
docker_dogstatsd_arm64 37.128 MiB
dogstatsd_deb_amd64 30.031 MiB
dogstatsd_deb_arm64 28.176 MiB
dogstatsd_rpm_amd64 30.031 MiB
dogstatsd_suse_amd64 30.031 MiB
iot_agent_deb_amd64 43.037 MiB
iot_agent_deb_arm64 40.155 MiB
iot_agent_deb_armhf 40.736 MiB
iot_agent_rpm_amd64 43.038 MiB
iot_agent_suse_amd64 43.038 MiB
On-wire sizes (compressed)
Quality gate Change Size (prev → curr → max)
agent_deb_amd64 -28.07 KiB (0.02% reduction) 173.358 → 173.330 → 174.490
agent_deb_amd64_fips -12.34 KiB (0.01% reduction) 172.299 → 172.286 → 173.750
agent_heroku_amd64 -9.79 KiB (0.01% reduction) 87.128 → 87.119 → 88.450
agent_msi -64.0 KiB (0.04% reduction) 142.965 → 142.902 → 143.020
agent_rpm_amd64 -9.57 KiB (0.01% reduction) 176.103 → 176.094 → 177.660
agent_rpm_amd64_fips -36.46 KiB (0.02% reduction) 175.043 → 175.007 → 176.600
agent_rpm_arm64 +65.22 KiB (0.04% increase) 159.393 → 159.457 → 161.260
agent_rpm_arm64_fips -32.72 KiB (0.02% reduction) 158.801 → 158.769 → 160.550
agent_suse_amd64 -9.57 KiB (0.01% reduction) 176.103 → 176.094 → 177.660
agent_suse_amd64_fips -36.46 KiB (0.02% reduction) 175.043 → 175.007 → 176.600
agent_suse_arm64 +65.22 KiB (0.04% increase) 159.393 → 159.457 → 161.260
agent_suse_arm64_fips -32.72 KiB (0.02% reduction) 158.801 → 158.769 → 160.550
docker_agent_amd64 -26.65 KiB (0.01% reduction) 261.102 → 261.076 → 262.450
docker_agent_arm64 -3.27 KiB (0.00% reduction) 250.106 → 250.103 → 252.630
docker_agent_jmx_amd64 -8.01 KiB (0.00% reduction) 329.732 → 329.724 → 331.080
docker_agent_jmx_arm64 -11.78 KiB (0.00% reduction) 314.729 → 314.717 → 317.270
docker_cluster_agent_amd64 -3.47 KiB (0.01% reduction) 63.877 → 63.874 → 64.490
docker_cluster_agent_arm64 +9.08 KiB (0.01% increase) 60.160 → 60.169 → 61.170
docker_cws_instrumentation_amd64 neutral 2.994 MiB
docker_cws_instrumentation_arm64 neutral 2.726 MiB
docker_dogstatsd_amd64 neutral 15.026 MiB
docker_dogstatsd_arm64 neutral 14.351 MiB
dogstatsd_deb_amd64 neutral 7.944 MiB
dogstatsd_deb_arm64 neutral 6.825 MiB
dogstatsd_rpm_amd64 neutral 7.956 MiB
dogstatsd_suse_amd64 neutral 7.956 MiB
iot_agent_deb_amd64 neutral 11.275 MiB
iot_agent_deb_arm64 neutral 9.641 MiB
iot_agent_deb_armhf -2.43 KiB (0.02% reduction) 9.836 → 9.833 → 10.620
iot_agent_rpm_amd64 neutral 11.294 MiB
iot_agent_suse_amd64 neutral 11.294 MiB

@cit-pr-commenter
Copy link
Copy Markdown

cit-pr-commenter bot commented Jan 5, 2026

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: 7f4bdc67-42d2-49c4-99fb-f77d1e97414a

Baseline: adfcd28
Comparison: bbc7914
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 +2.19 [-0.85, +5.23] 1 Logs

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gate_logs % cpu utilization +2.59 [+1.12, +4.06] 1 Logs bounds checks dashboard
docker_containers_cpu % cpu utilization +2.19 [-0.85, +5.23] 1 Logs
quality_gate_metrics_logs memory utilization +1.20 [+0.99, +1.40] 1 Logs bounds checks dashboard
otlp_ingest_metrics memory utilization +0.51 [+0.36, +0.66] 1 Logs
ddot_logs memory utilization +0.24 [+0.18, +0.29] 1 Logs
file_to_blackhole_0ms_latency egress throughput +0.04 [-0.35, +0.44] 1 Logs
file_to_blackhole_500ms_latency egress throughput +0.04 [-0.34, +0.41] 1 Logs
ddot_metrics_sum_cumulativetodelta_exporter memory utilization +0.03 [-0.20, +0.26] 1 Logs
quality_gate_idle memory utilization +0.02 [-0.02, +0.07] 1 Logs bounds checks dashboard
otlp_ingest_logs memory utilization +0.01 [-0.08, +0.10] 1 Logs
uds_dogstatsd_to_api ingress throughput +0.01 [-0.11, +0.13] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput +0.01 [-0.08, +0.09] 1 Logs
docker_containers_memory memory utilization -0.00 [-0.08, +0.07] 1 Logs
uds_dogstatsd_to_api_v3 ingress throughput -0.00 [-0.14, +0.13] 1 Logs
quality_gate_idle_all_features memory utilization -0.03 [-0.07, +0.01] 1 Logs bounds checks dashboard
ddot_metrics_sum_delta memory utilization -0.04 [-0.25, +0.17] 1 Logs
file_to_blackhole_1000ms_latency egress throughput -0.05 [-0.45, +0.35] 1 Logs
file_to_blackhole_100ms_latency egress throughput -0.10 [-0.14, -0.05] 1 Logs
uds_dogstatsd_20mb_12k_contexts_20_senders memory utilization -0.17 [-0.22, -0.11] 1 Logs
file_tree memory utilization -0.18 [-0.24, -0.12] 1 Logs
ddot_metrics_sum_cumulative memory utilization -0.35 [-0.51, -0.18] 1 Logs
ddot_metrics memory utilization -0.42 [-0.64, -0.21] 1 Logs
tcp_syslog_to_blackhole ingress throughput -0.58 [-0.66, -0.50] 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 lost_bytes 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_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 intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, 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_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.
  • 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.

Comment thread comp/otelcol/otlp/components/metricsclient/metrics_client.go
@github-actions github-actions bot added medium review PR review might take time and removed short review PR is simple enough to be reviewed quickly labels Jan 5, 2026
Copy link
Copy Markdown
Member

@songy23 songy23 left a comment

Choose a reason for hiding this comment

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

Please add a changelog

@agagniere agagniere force-pushed the agagniere/fix-prometheus-deadlock branch from fe83f31 to 6a72b2c Compare January 8, 2026 15:48
@agagniere agagniere requested a review from a team as a code owner January 8, 2026 15:48
@agagniere agagniere force-pushed the agagniere/fix-prometheus-deadlock branch from 6a72b2c to 359edb4 Compare January 8, 2026 16:49
Copy link
Copy Markdown
Contributor

@drichards-87 drichards-87 left a comment

Choose a reason for hiding this comment

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

Left some feedback on the release notes from Docs and approved the PR.

@agagniere agagniere force-pushed the agagniere/fix-prometheus-deadlock branch from fcf1505 to 5623f36 Compare January 12, 2026 10:16
@agagniere agagniere requested a review from songy23 January 12, 2026 10:24
@agagniere
Copy link
Copy Markdown
Contributor Author

Note : I verified that the test fails on main, and succeeds with the associated changes.

Pushed with --no-verify to allow review of the test, but it is not compatible with go 1.24, unless we activate the GOEXPERIMENT=synctest

@agagniere agagniere force-pushed the agagniere/fix-prometheus-deadlock branch 2 times, most recently from 2607dc4 to d8cf397 Compare January 12, 2026 13:44
@agagniere agagniere added the qa/done QA done before merge and regressions are covered by tests label Jan 12, 2026
@agagniere agagniere force-pushed the agagniere/fix-prometheus-deadlock branch from d8cf397 to 8235945 Compare January 12, 2026 14:14
agagniere and others added 2 commits January 13, 2026 10:17
Co-authored-by: DeForest Richards <56796055+drichards-87@users.noreply.github.com>
@agagniere agagniere force-pushed the agagniere/fix-prometheus-deadlock branch from 8235945 to bbc7914 Compare January 13, 2026 10:33
@agagniere
Copy link
Copy Markdown
Contributor Author

/merge -m squash

@gh-worker-devflow-routing-ef8351
Copy link
Copy Markdown

gh-worker-devflow-routing-ef8351 bot commented Jan 13, 2026

View all feedbacks in Devflow UI.

2026-01-13 13:11:40 UTC ℹ️ Start processing command /merge -m squash


2026-01-13 13:11:47 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-01-13 13:41:50 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue dd-mergequeue bot merged commit 186de0a into main Jan 13, 2026
328 of 329 checks passed
@dd-mergequeue dd-mergequeue bot deleted the agagniere/fix-prometheus-deadlock branch January 13, 2026 13:41
@github-actions github-actions bot added this to the 7.76.0 milestone Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

medium review PR review might take time qa/done QA done before merge and regressions are covered by tests team/opentelemetry-agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants