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

[CONTP-549] throttle the number of parallel client initial syncs in the tagger server #31741

Merged

Conversation

adel121
Copy link
Contributor

@adel121 adel121 commented Dec 4, 2024

What does this PR do?

This PR adds throttling behaviour to the tagger server so that the number of clients (remote tagger) undergoing tagger initial sync in parallel is bound by a specific value.

Motivation

Flatten the memory and cpu usage curves on cluster agent startup to avoid OOMKills and container restarts on large clusters.

Such issues are visible on large clusters where:

  • the content of the cluster tagger is huge
  • we have multiple CLC runner replicas
  • CLC runners are using the remote tagger (i.e. connecting to the cluster agent to stream tags)

Tested on large clusters, and saw big improvement by flattening Memory and CPU usage curves on startup of the DCA:

image

image

Describe how you validated your changes

The default behaviour should be preserved. E2E already test CLC runners and cluster checks on CLC runners.

We can validate throttling works by scaling up the number of replicas of the CLC runners, and setting the DCA log level to DEBUG, and verify in the DCA logs that we never have more than 4 CLC runner instances receiving the initial tagger burst at the same time.

It is difficult to test this locally because on local machine the workload is very small, so it is not easy to exhaust the throttler.

What we can do is check we can perform sync with a large number of CLC runners without issues.

Example:

datadog:
  apiKeyExistingSecret: datadog-secret
  appKeyExistingSecret: datadog-secret
  logLevel: DEBUG
  clusterChecks:
    enabled: true
  kubelet:
    tlsVerify: false

  logs:
    enabled: true
    containerCollectAll: true

  clusterTagger:
    # datadog.clusterTagger.collectKubernetesTags -- Enables Kubernetes resources tags collection.
    collectKubernetesTags: true



clusterChecksRunner:
  enabled: true
  replicas: 90 # this is only for local testing, don't try this on large clusters 👯 
  env:
    - name: DD_CLC_RUNNER_REMOTE_TAGGER_ENABLED
      value: true

clusterAgent:
  enabled: true
  replicas: 1

By deploying this, you should be able to see in the DCA logs how the throttler token is requested, when the sync process has started/finished for each CLC runner. The logs should never show more than 4 CLC runners started syncing in parallel.

Example from the logs showing multiple CLC runners requesting tokens and waiting until they get their turn:

2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "0899691f-6f71-449e-b947-95c6e7449afb"
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "4e559f19-38f3-4999-9855-be2360bac49d"
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "3c33fb42-7e23-40ad-af28-8db8c6af7e40"
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "fb7ba70e-e3a6-44aa-b126-8dcc2729ed0b"
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "fbcf536f-b98e-47f6-aa1e-2d2ae8fc3f06"
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "6e9f184a-5d20-4e6d-b268-ba07eb516263"
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "2d4097e9-0da4-4a06-bc55-0008b1575ca7"
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "972d6bef-4808-4ff2-85af-0539066bb45b"
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "f53b0ae7-33a2-4d46-9c0c-34f90108f09a"
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "71b022dc-f0ad-406b-a5ec-8b46938f0f77"
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "c9cbdb8a-a2c4-4219-9c7f-4441d7575a37"
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "44db4a0e-2ee8-4b8d-a6a3-b8ef7c32f5b3"
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:113 in TaggerStreamEntities) | cluster tagger has just initiated subscription for "streaming-client-0899691f-6f71-449e-b947-95c6e7449afb" at time 1735312103
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:113 in TaggerStreamEntities) | cluster tagger has just initiated subscription for "streaming-client-4e559f19-38f3-4999-9855-be2360bac49d" at time 1735312103
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:113 in TaggerStreamEntities) | cluster tagger has just initiated subscription for "streaming-client-3c33fb42-7e23-40ad-af28-8db8c6af7e40" at time 1735312103
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:113 in TaggerStreamEntities) | cluster tagger has just initiated subscription for "streaming-client-972d6bef-4808-4ff2-85af-0539066bb45b" at time 1735312103
2024-12-27 15:08:23 UTC | CLUSTER | INFO | (comp/core/tagger/server/server.go:159 in TaggerStreamEntities) | cluster tagger has just finished initialization for subscription "streaming-client-4e559f19-38f3-4999-9855-be2360bac49d" at time 1735312103
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:113 in TaggerStreamEntities) | cluster tagger has just initiated subscription for "streaming-client-fb7ba70e-e3a6-44aa-b126-8dcc2729ed0b" at time 1735312103
2024-12-27 15:08:23 UTC | CLUSTER | INFO | (comp/core/tagger/server/server.go:159 in TaggerStreamEntities) | cluster tagger has just finished initialization for subscription "streaming-client-fb7ba70e-e3a6-44aa-b126-8dcc2729ed0b" at time 1735312103
2024-12-27 15:08:23 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:113 in TaggerStreamEntities) | cluster tagger has just initiated subscription for "streaming-client-c9cbdb8a-a2c4-4219-9c7f-4441d7575a37" at time 1735312103
2024-12-27 15:08:24 UTC | CLUSTER | DEBUG | (comp/core/tagger/server/server.go:108 in TaggerStreamEntities) | requesting token from server throttler for streaming id: "d8bddeec-a2e8-4196-bedb-e2041ab47db6"

You can see we never have more than 4 progressing sync operations.

At the end, all CLC runners should have their taggers synced with the cluster agent (you can check this with agent tagger-list)

Possible Drawbacks / Trade-offs

Slows down initial sync of tagger in CLC runners, however this is ok because it only happens on very large clusters with many CLC runners, and it allows the DCA to survive the initialisation phase without exceeding too much memory and cpu.

Additional Notes

@github-actions github-actions bot added medium review PR review might take time team/container-platform The Container Platform Team labels Dec 4, 2024
Copy link

cit-pr-commenter bot commented Dec 4, 2024

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: e72003d9-5e20-4436-a684-d61d0f154abb

Baseline: 97e21b6
Comparison: c0967b0
Diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gate_idle memory utilization +0.54 [+0.50, +0.57] 1 Logs bounds checks dashboard
uds_dogstatsd_to_api_cpu % cpu utilization +0.42 [-0.26, +1.11] 1 Logs
file_to_blackhole_100ms_latency egress throughput +0.11 [-0.59, +0.81] 1 Logs
file_to_blackhole_0ms_latency_http2 egress throughput +0.03 [-0.86, +0.91] 1 Logs
quality_gate_idle_all_features memory utilization +0.01 [-0.07, +0.10] 1 Logs bounds checks dashboard
uds_dogstatsd_to_api ingress throughput +0.01 [-0.10, +0.11] 1 Logs
file_to_blackhole_0ms_latency egress throughput +0.00 [-0.89, +0.90] 1 Logs
file_to_blackhole_500ms_latency egress throughput +0.00 [-0.77, +0.77] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput -0.00 [-0.01, +0.01] 1 Logs
file_tree memory utilization -0.03 [-0.16, +0.10] 1 Logs
file_to_blackhole_300ms_latency egress throughput -0.07 [-0.72, +0.58] 1 Logs
file_to_blackhole_1000ms_latency egress throughput -0.14 [-0.93, +0.65] 1 Logs
file_to_blackhole_1000ms_latency_linear_load egress throughput -0.17 [-0.63, +0.29] 1 Logs
file_to_blackhole_0ms_latency_http1 egress throughput -0.18 [-1.07, +0.70] 1 Logs
tcp_syslog_to_blackhole ingress throughput -0.83 [-0.90, -0.76] 1 Logs
quality_gate_logs % cpu utilization -0.90 [-4.11, +2.31] 1 Logs

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed links
file_to_blackhole_0ms_latency lost_bytes 10/10
file_to_blackhole_0ms_latency memory_usage 10/10
file_to_blackhole_0ms_latency_http1 lost_bytes 10/10
file_to_blackhole_0ms_latency_http1 memory_usage 10/10
file_to_blackhole_0ms_latency_http2 lost_bytes 10/10
file_to_blackhole_0ms_latency_http2 memory_usage 10/10
file_to_blackhole_1000ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency_linear_load 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_300ms_latency lost_bytes 10/10
file_to_blackhole_300ms_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 memory_usage 10/10 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 bounds checks dashboard
quality_gate_logs lost_bytes 10/10
quality_gate_logs memory_usage 10/10

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 memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check lost_bytes: 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 memory_usage: 10/10 replicas passed. Gate passed.

@adel121 adel121 force-pushed the adelhajhassan/throttle_remote_tagger_parallel_sync branch from fbcb3b7 to a2e257b Compare December 27, 2024 14:25
@adel121 adel121 added changelog/no-changelog kind/enhancement qa/rc-required Only for a PR that requires validation on the Release Candidate labels Dec 27, 2024
@adel121 adel121 force-pushed the adelhajhassan/throttle_remote_tagger_parallel_sync branch from a2e257b to 63e9838 Compare December 27, 2024 14:30
@adel121 adel121 force-pushed the adelhajhassan/throttle_remote_tagger_parallel_sync branch from 63e9838 to b390f94 Compare December 27, 2024 15:16
@@ -729,6 +729,9 @@ func InitConfig(config pkgconfigmodel.Setup) {
config.BindEnvAndSetDefault("clc_runner_server_readheader_timeout", 10)
config.BindEnvAndSetDefault("clc_runner_remote_tagger_enabled", false)

// Remote tagger
config.BindEnvAndSetDefault("remote_tagger.max_concurrent_sync", 4)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Open questions for discussion:

Do you think 4 is a good default value for this option?

Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, a default value of 4 is quite high. Most of the setups I’ve seen typically use around 3 cluster-check-runner instances.

If we aim to minimize the impact of the initialization stream on the cluster-agent, a default value of 1 would be more appropriate. In most cases, this should suffice because cluster-check-runners are usually rolled out and updated incrementally, one at a time, based on the rollout strategy.

That said, a default value of 1 might be too low for some setups. I’d suggest setting the default to 2 as a balanced choice, though I acknowledge this decision is largely empirical and not based on concrete data.

@adel121 adel121 changed the title throttle the number of parallel client initial syncs in the tagger server [CONTP-549] throttle the number of parallel client initial syncs in the tagger server Dec 27, 2024
@adel121 adel121 marked this pull request as ready for review December 27, 2024 15:21
@adel121 adel121 requested review from a team as code owners December 27, 2024 15:21
@adel121 adel121 requested a review from louis-cqrl December 27, 2024 15:21
@adel121 adel121 added this to the 7.63.0 milestone Dec 27, 2024
@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Dec 27, 2024

Test changes on VM

Use this command from test-infra-definitions to manually test this PR changes on a VM:

inv aws.create-vm --pipeline-id=52097096 --os-family=ubuntu

Note: This applies to commit c0967b0

@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Dec 27, 2024

Uncompressed package size comparison

Comparison with ancestor 97e21b68ef14225946b43f673e3a9ef5ad42e7fa

Diff per package
package diff status size ancestor threshold
datadog-agent-amd64-deb 0.01MB ⚠️ 1198.13MB 1198.11MB 140.00MB
datadog-agent-x86_64-rpm 0.01MB ⚠️ 1207.44MB 1207.43MB 140.00MB
datadog-agent-x86_64-suse 0.01MB ⚠️ 1207.44MB 1207.43MB 140.00MB
datadog-heroku-agent-amd64-deb 0.01MB ⚠️ 506.11MB 506.10MB 70.00MB
datadog-iot-agent-amd64-deb 0.01MB ⚠️ 113.78MB 113.77MB 10.00MB
datadog-iot-agent-x86_64-rpm 0.01MB ⚠️ 113.85MB 113.84MB 10.00MB
datadog-iot-agent-x86_64-suse 0.01MB ⚠️ 113.85MB 113.84MB 10.00MB
datadog-agent-arm64-deb 0.01MB ⚠️ 940.51MB 940.50MB 140.00MB
datadog-agent-aarch64-rpm 0.01MB ⚠️ 949.81MB 949.80MB 140.00MB
datadog-iot-agent-aarch64-rpm 0.01MB ⚠️ 109.29MB 109.29MB 10.00MB
datadog-iot-agent-arm64-deb 0.01MB ⚠️ 109.22MB 109.22MB 10.00MB
datadog-dogstatsd-amd64-deb 0.00MB 79.00MB 79.00MB 10.00MB
datadog-dogstatsd-x86_64-rpm 0.00MB 79.08MB 79.08MB 10.00MB
datadog-dogstatsd-x86_64-suse 0.00MB 79.08MB 79.08MB 10.00MB
datadog-dogstatsd-arm64-deb 0.00MB 56.11MB 56.11MB 10.00MB

Decision

⚠️ Warning

Copy link
Contributor

@clamoriniere clamoriniere left a comment

Choose a reason for hiding this comment

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

looks good,

I'm suggestion small nits to ease futur code investigation


timeoutRefreshError := make(chan error)

go func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wondering if we can create a function to isolate this logic.
Also should it be the client who send the keepAlive and not the server?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline regarding this.

In summary, this part of the code was already there, it is just moved up a bit.
We can work on refactoring this code in a subsequent PR.

subscriptionID := fmt.Sprintf("streaming-client-%s", streamingID)

initBurst := true
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add a comment to explain what is initBurst?

@@ -729,6 +729,9 @@ func InitConfig(config pkgconfigmodel.Setup) {
config.BindEnvAndSetDefault("clc_runner_server_readheader_timeout", 10)
config.BindEnvAndSetDefault("clc_runner_remote_tagger_enabled", false)

// Remote tagger
config.BindEnvAndSetDefault("remote_tagger.max_concurrent_sync", 4)
Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, a default value of 4 is quite high. Most of the setups I’ve seen typically use around 3 cluster-check-runner instances.

If we aim to minimize the impact of the initialization stream on the cluster-agent, a default value of 1 would be more appropriate. In most cases, this should suffice because cluster-check-runners are usually rolled out and updated incrementally, one at a time, based on the rollout strategy.

That said, a default value of 1 might be too low for some setups. I’d suggest setting the default to 2 as a balanced choice, though I acknowledge this decision is largely empirical and not based on concrete data.

comp/core/tagger/server/syncthrottler_test.go Show resolved Hide resolved
@adel121 adel121 requested a review from clamoriniere January 3, 2025 07:53
@adel121
Copy link
Contributor Author

adel121 commented Jan 3, 2025

/merge

@dd-devflow
Copy link

dd-devflow bot commented Jan 3, 2025

Devflow running: /merge

View all feedbacks in Devflow UI.


2025-01-03 09:13:55 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-01-03 13:13:57 UTC ⚠️ MergeQueue: This merge request was unqueued

[email protected] unqueued this merge request: It did not become mergeable within the expected time

@adel121
Copy link
Contributor Author

adel121 commented Jan 3, 2025

/merge

@dd-devflow
Copy link

dd-devflow bot commented Jan 3, 2025

Devflow running: /merge

View all feedbacks in Devflow UI.


2025-01-03 15:26:26 UTC ℹ️ MergeQueue: pull request added to the queue

The median merge time in main is 35m.


2025-01-03 16:01:39 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue dd-mergequeue bot merged commit ce6e680 into main Jan 3, 2025
238 checks passed
@dd-mergequeue dd-mergequeue bot deleted the adelhajhassan/throttle_remote_tagger_parallel_sync branch January 3, 2025 16:01
mwdd146980 pushed a commit that referenced this pull request Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog kind/enhancement medium review PR review might take time qa/rc-required Only for a PR that requires validation on the Release Candidate team/container-platform The Container Platform Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants