Skip to content

[kubernetes/leaderelection] Fix race condition - #38694

Merged
dd-mergequeue[bot] merged 3 commits into
mainfrom
davidor/contp-853-leader-election-race-condition
Jul 14, 2025
Merged

[kubernetes/leaderelection] Fix race condition#38694
dd-mergequeue[bot] merged 3 commits into
mainfrom
davidor/contp-853-leader-election-race-condition

Conversation

@davidor

@davidor davidor commented Jul 11, 2025

Copy link
Copy Markdown
Member

What does this PR do?

This PR fixes 2 issues in the createLeaderTokenIfNotExists function in the leader election package:

  • When leader_election_default_resource was set to leases, the Cluster Agent still created a configmap. This was unnecessary and is now fixed.
  • There was a race condition during the first install when running multiple Cluster Agent replicas. The function checked if a lease or configmap existed, and if not, tried to create it. But another replica could create it in the middle of the two operations, which was not handled correctly.

Describe how you validated your changes

I added unit tests. I also tested it manually by setting leader_election_default_resource to leases and confirmed that the configmap is no longer created.

We'll need to merge DataDog/test-infra-definitions#1492 again. It's the PR that exposed the race condition.

@davidor davidor added this to the 7.70.0 milestone Jul 11, 2025
@davidor
davidor requested review from a team as code owners July 11, 2025 09:53
@davidor davidor added qa/done QA done before merge and regressions are covered by tests team/container-platform The Container Platform Team labels Jul 11, 2025
@github-actions github-actions Bot added the medium review PR review might take time label Jul 11, 2025
@davidor
davidor force-pushed the davidor/contp-853-leader-election-race-condition branch from 11415b5 to f3e6643 Compare July 11, 2025 10:05
@cit-pr-commenter

cit-pr-commenter Bot commented Jul 11, 2025

Copy link
Copy Markdown

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: 4bae1e34-8612-4753-8f22-1e2ce795c032

Baseline: 66a6326
Comparison: 3e36b68
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 +3.04 [-0.16, +6.23] 1 Logs

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
docker_containers_cpu % cpu utilization +3.04 [-0.16, +6.23] 1 Logs
uds_dogstatsd_to_api_cpu % cpu utilization +1.77 [+0.92, +2.62] 1 Logs
quality_gate_idle memory utilization +0.72 [+0.65, +0.79] 1 Logs bounds checks dashboard
file_tree memory utilization +0.69 [+0.65, +0.74] 1 Logs
ddot_logs memory utilization +0.40 [+0.31, +0.49] 1 Logs
file_to_blackhole_500ms_latency egress throughput +0.07 [-0.53, +0.68] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput -0.00 [-0.01, +0.01] 1 Logs
uds_dogstatsd_to_api ingress throughput -0.00 [-0.30, +0.29] 1 Logs
file_to_blackhole_0ms_latency egress throughput -0.02 [-0.62, +0.58] 1 Logs
otlp_ingest_metrics memory utilization -0.03 [-0.17, +0.11] 1 Logs
otlp_ingest_logs memory utilization -0.03 [-0.16, +0.09] 1 Logs
file_to_blackhole_100ms_latency egress throughput -0.05 [-0.69, +0.59] 1 Logs
ddot_metrics memory utilization -0.08 [-0.19, +0.04] 1 Logs
tcp_syslog_to_blackhole ingress throughput -0.08 [-0.14, -0.02] 1 Logs
file_to_blackhole_1000ms_latency egress throughput -0.09 [-0.69, +0.51] 1 Logs
quality_gate_idle_all_features memory utilization -0.43 [-0.55, -0.32] 1 Logs bounds checks dashboard
uds_dogstatsd_20mb_12k_contexts_20_senders memory utilization -0.60 [-0.66, -0.54] 1 Logs
docker_containers_memory memory utilization -0.61 [-0.69, -0.54] 1 Logs
quality_gate_logs % cpu utilization -1.37 [-4.15, +1.40] 1 Logs bounds checks dashboard

Bounds Checks: ❌ Failed

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 9/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

Failed. Some Quality Gates were violated.

  • 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_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 9/10 replicas passed. Failed 1 which is > 0. Gate FAILED.
  • quality_gate_logs, bounds check lost_bytes: 10/10 replicas passed. Gate 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.

@agent-platform-auto-pr

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

Copy link
Copy Markdown
Contributor

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor 3c429f6

Successful checks

Info

Quality gate Delta On disk size (MiB) Delta On wire size (MiB)
agent_deb_amd64 $${0}$$ $${702.49}$$ < $${705.58}$$ $${-0.05}$$ $${177.35}$$ < $${178.78}$$
agent_deb_amd64_fips $${0}$$ $${700.75}$$ < $${704.78}$$ $${-0}$$ $${176.8}$$ < $${178.18}$$
agent_heroku_amd64 $${0}$$ $${354.42}$$ < $${367.87}$$ $${-0}$$ $${94.76}$$ < $${100.05}$$
agent_msi $${+0}$$ $${977.22}$$ < $${979.82}$$ $${-0}$$ $${148.46}$$ < $${149.26}$$
agent_rpm_amd64 $${0}$$ $${702.48}$$ < $${705.56}$$ $${+0.01}$$ $${178.94}$$ < $${180.29}$$
agent_rpm_amd64_fips $${0}$$ $${700.74}$$ < $${704.77}$$ $${-0.03}$$ $${178.51}$$ < $${179.83}$$
agent_rpm_arm64 $${0}$$ $${692.52}$$ < $${695.45}$$ $${+0.03}$$ $${162.69}$$ < $${163.94}$$
agent_rpm_arm64_fips $${+0}$$ $${690.83}$$ < $${694.75}$$ $${+0.02}$$ $${161.71}$$ < $${163.06}$$
agent_suse_amd64 $${0}$$ $${702.48}$$ < $${705.57}$$ $${+0.01}$$ $${178.94}$$ < $${180.29}$$
agent_suse_amd64_fips $${0}$$ $${700.74}$$ < $${704.77}$$ $${-0.03}$$ $${178.51}$$ < $${180.01}$$
agent_suse_arm64 $${0}$$ $${692.52}$$ < $${695.38}$$ $${+0.03}$$ $${162.69}$$ < $${163.95}$$
agent_suse_arm64_fips $${+0}$$ $${690.83}$$ < $${694.73}$$ $${+0.02}$$ $${161.71}$$ < $${163.06}$$
docker_agent_amd64 $${0}$$ $${786.3}$$ < $${789.36}$$ $${+0}$$ $${270.55}$$ < $${272.13}$$
docker_agent_arm64 $${+0}$$ $${799.79}$$ < $${802.63}$$ $${-0.01}$$ $${258.29}$$ < $${259.79}$$
docker_agent_jmx_amd64 $${+0}$$ $${977.49}$$ < $${980.55}$$ $${+0}$$ $${339.52}$$ < $${341.08}$$
docker_agent_jmx_arm64 $${+0}$$ $${979.58}$$ < $${982.42}$$ $${-0}$$ $${323.24}$$ < $${324.75}$$
docker_agent_windows1809 $${+0}$$ $${1189.83}$$ < $${1195.03}$$ $${+0.08}$$ $${419.7}$$ < $${424.31}$$
docker_agent_windows1809_core $${+0}$$ $${5919.79}$$ < $${5930.43}$$ $${0}$$ $${2048.0}$$ < $${2049.0}$$
docker_agent_windows1809_core_jmx $${+22.32}$$ $${6063.69}$$ < $${6068.68}$$ $${0}$$ $${2048.0}$$ < $${2054.45}$$
docker_agent_windows1809_jmx $${-0}$$ $${1311.46}$$ < $${1316.42}$$ $${+0.08}$$ $${461.9}$$ < $${466.29}$$
docker_agent_windows2022 $${-0.26}$$ $${1208.87}$$ < $${1213.94}$$ $${-0.03}$$ $${432.3}$$ < $${436.85}$$
docker_agent_windows2022_core $${+0.28}$$ $${5893.14}$$ < $${5897.98}$$ $${0}$$ $${2048.0}$$ < $${2050.9}$$
docker_agent_windows2022_core_jmx $${+0.29}$$ $${6014.79}$$ < $${6019.2}$$ $${0}$$ $${2048.0}$$ < $${2054.29}$$
docker_agent_windows2022_jmx $${-0.42}$$ $${1330.53}$$ < $${1335.89}$$ $${-0.01}$$ $${474.58}$$ < $${479.09}$$
docker_cluster_agent_amd64 $${+0}$$ $${213.71}$$ < $${214.5}$$ $${-0}$$ $${72.63}$$ < $${73.51}$$
docker_cluster_agent_arm64 $${0}$$ $${229.5}$$ < $${230.33}$$ $${+0}$$ $${68.91}$$ < $${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}$$ $${39.24}$$ < $${39.57}$$ $${+0}$$ $${15.12}$$ < $${15.76}$$
docker_dogstatsd_arm64 $${0}$$ $${37.88}$$ < $${38.2}$$ $${-0}$$ $${14.55}$$ < $${14.83}$$
dogstatsd_deb_amd64 $${0}$$ $${30.45}$$ < $${31.4}$$ $${+0}$$ $${8.01}$$ < $${8.95}$$
dogstatsd_deb_arm64 $${0}$$ $${29.01}$$ < $${29.97}$$ $${+0}$$ $${6.95}$$ < $${7.89}$$
dogstatsd_rpm_amd64 $${0}$$ $${30.45}$$ < $${31.4}$$ $${-0}$$ $${8.01}$$ < $${8.96}$$
dogstatsd_suse_amd64 $${0}$$ $${30.45}$$ < $${31.4}$$ $${-0}$$ $${8.01}$$ < $${8.96}$$
iot_agent_deb_amd64 $${0}$$ $${53.87}$$ < $${54.55}$$ $${+0}$$ $${13.57}$$ < $${14.45}$$
iot_agent_deb_arm64 $${0}$$ $${51.21}$$ < $${51.9}$$ $${+0}$$ $${11.75}$$ < $${12.63}$$
iot_agent_deb_armhf $${0}$$ $${50.72}$$ < $${51.42}$$ $${-0.01}$$ $${11.81}$$ < $${12.74}$$
iot_agent_rpm_amd64 $${0}$$ $${53.87}$$ < $${54.55}$$ $${+0}$$ $${13.59}$$ < $${14.47}$$
iot_agent_rpm_arm64 $${0}$$ $${51.21}$$ < $${51.91}$$ $${+0}$$ $${11.77}$$ < $${12.65}$$
iot_agent_suse_amd64 $${0}$$ $${53.87}$$ < $${54.55}$$ $${+0}$$ $${13.59}$$ < $${14.47}$$

@davidor

davidor commented Jul 14, 2025

Copy link
Copy Markdown
Member Author

/merge

@dd-devflow-routing-codex

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

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-07-14 07:16:44 UTC ℹ️ Start processing command /merge


2025-07-14 07:16:49 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 1h (p90).


2025-07-14 07:49:37 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue
dd-mergequeue Bot merged commit b1f9037 into main Jul 14, 2025
259 checks passed
@dd-mergequeue
dd-mergequeue Bot deleted the davidor/contp-853-leader-election-race-condition branch July 14, 2025 07:49
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/container-platform The Container Platform Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants