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

[NPM-4243] Cache low-value network path contexts and discard them #34597

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pimlu
Copy link
Contributor

@pimlu pimlu commented Feb 28, 2025

What does this PR do?

This PR adds a cache storing known low-value pathtests to avoid repeating them (by default, for two hours currently).

Motivation

We want to reduce the total number of pathtraces done by dynamic paths in order to reduce server load, and reduce the number of independent connections in NAT tables.

Describe how you validated your changes

New discard scanner tests:

go test -timeout 30s -tags linux,linux_bpf,npm,process,test github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard

Existing NP collector tests:

go test -timeout 30s -tags linux,linux_bpf,npm,process,test github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl

Possible Drawbacks / Trade-offs

Additional Notes

@github-actions github-actions bot added team/networks medium review PR review might take time labels Feb 28, 2025
Copy link

cit-pr-commenter bot commented Feb 28, 2025

Go Package Import Differences

Baseline: c99883d
Comparison: 1f46d69

binaryosarchchange
agentlinuxamd64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
agentlinuxarm64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
agentwindowsamd64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
agentdarwinamd64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
agentdarwinarm64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
iot-agentlinuxamd64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
iot-agentlinuxarm64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
heroku-agentlinuxamd64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
process-agentlinuxamd64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
process-agentlinuxarm64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
process-agentwindowsamd64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
process-agentdarwinamd64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
process-agentdarwinarm64
+3, -0
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight
heroku-process-agentlinuxamd64
+4, -0
+container/heap
+github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/discard
+github.com/jellydator/ttlcache/v3
+golang.org/x/sync/singleflight

@pimlu pimlu added changelog/no-changelog qa/done QA done before merge and regressions are covered by tests labels Feb 28, 2025
@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Feb 28, 2025

Uncompressed package size comparison

Comparison with ancestor c99883d062e9593674298c57d3d9205c93935130

Diff per package
package diff status size ancestor threshold
datadog-agent-amd64-deb 0.29MB ⚠️ 815.68MB 815.40MB 0.50MB
datadog-agent-x86_64-rpm 0.29MB ⚠️ 825.48MB 825.19MB 0.50MB
datadog-agent-x86_64-suse 0.29MB ⚠️ 825.48MB 825.19MB 0.50MB
datadog-agent-aarch64-rpm 0.28MB ⚠️ 816.42MB 816.14MB 0.50MB
datadog-agent-arm64-deb 0.28MB ⚠️ 806.64MB 806.36MB 0.50MB
datadog-heroku-agent-amd64-deb 0.19MB ⚠️ 440.88MB 440.69MB 0.50MB
datadog-iot-agent-aarch64-rpm 0.10MB ⚠️ 59.51MB 59.42MB 0.50MB
datadog-iot-agent-arm64-deb 0.10MB ⚠️ 59.44MB 59.35MB 0.50MB
datadog-iot-agent-x86_64-rpm 0.09MB ⚠️ 62.28MB 62.18MB 0.50MB
datadog-iot-agent-x86_64-suse 0.09MB ⚠️ 62.28MB 62.18MB 0.50MB
datadog-iot-agent-amd64-deb 0.09MB ⚠️ 62.21MB 62.11MB 0.50MB
datadog-dogstatsd-amd64-deb 0.00MB 39.43MB 39.43MB 0.50MB
datadog-dogstatsd-x86_64-rpm 0.00MB 39.51MB 39.51MB 0.50MB
datadog-dogstatsd-x86_64-suse 0.00MB 39.51MB 39.51MB 0.50MB
datadog-dogstatsd-arm64-deb 0.00MB 37.97MB 37.97MB 0.50MB

Decision

⚠️ Warning

@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Feb 28, 2025

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=57539394 --os-family=ubuntu

Note: This applies to commit 1f46d69

@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Feb 28, 2025

Static quality checks ✅

Please find below the results from static quality gates

Successful checks

Info

Result Quality gate On disk size On disk size limit On wire size On wire size limit
static_quality_gate_agent_deb_amd64 789.31MiB 801.8MiB 192.28MiB 202.62MiB
static_quality_gate_agent_deb_arm64 780.63MiB 793.14MiB 174.59MiB 184.51MiB
static_quality_gate_agent_rpm_amd64 789.4MiB 801.79MiB 194.43MiB 205.03MiB
static_quality_gate_agent_rpm_arm64 780.58MiB 793.09MiB 175.83MiB 186.44MiB
static_quality_gate_agent_suse_amd64 789.37MiB 801.81MiB 194.43MiB 205.03MiB
static_quality_gate_agent_suse_arm64 780.7MiB 793.14MiB 175.83MiB 186.44MiB
static_quality_gate_dogstatsd_deb_amd64 37.68MiB 47.67MiB 9.78MiB 19.78MiB
static_quality_gate_dogstatsd_deb_arm64 36.29MiB 46.27MiB 8.49MiB 18.49MiB
static_quality_gate_dogstatsd_rpm_amd64 37.68MiB 47.67MiB 9.79MiB 19.79MiB
static_quality_gate_dogstatsd_suse_amd64 37.68MiB 47.67MiB 9.79MiB 19.79MiB
static_quality_gate_iot_agent_deb_amd64 59.4MiB 69.0MiB 14.92MiB 24.8MiB
static_quality_gate_iot_agent_deb_arm64 56.77MiB 66.4MiB 12.89MiB 22.8MiB
static_quality_gate_iot_agent_rpm_amd64 59.4MiB 69.0MiB 14.95MiB 24.8MiB
static_quality_gate_iot_agent_rpm_arm64 56.77MiB 66.4MiB 12.88MiB 22.8MiB
static_quality_gate_iot_agent_suse_amd64 59.4MiB 69.0MiB 14.95MiB 24.8MiB
static_quality_gate_docker_agent_amd64 874.05MiB 886.12MiB 294.01MiB 304.21MiB
static_quality_gate_docker_agent_arm64 888.68MiB 900.79MiB 280.26MiB 290.47MiB
static_quality_gate_docker_agent_jmx_amd64 1.05GiB 1.06GiB 369.12MiB 379.33MiB
static_quality_gate_docker_agent_jmx_arm64 1.05GiB 1.06GiB 351.36MiB 361.55MiB
static_quality_gate_docker_dogstatsd_amd64 45.83MiB 55.78MiB 17.29MiB 27.28MiB
static_quality_gate_docker_dogstatsd_arm64 44.47MiB 54.45MiB 16.17MiB 26.16MiB
static_quality_gate_docker_cluster_agent_amd64 265.01MiB 274.78MiB 106.37MiB 116.28MiB
static_quality_gate_docker_cluster_agent_arm64 280.97MiB 290.82MiB 101.21MiB 111.12MiB

Copy link

cit-pr-commenter bot commented Feb 28, 2025

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: bf0049ee-c341-4ef7-9250-dde7771606cc

Baseline: c99883d
Comparison: 1f46d69
Diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
tcp_syslog_to_blackhole ingress throughput +1.18 [+1.11, +1.24] 1 Logs
quality_gate_idle memory utilization +0.78 [+0.74, +0.82] 1 Logs bounds checks dashboard
file_to_blackhole_500ms_latency egress throughput +0.20 [-0.58, +0.97] 1 Logs
file_to_blackhole_1000ms_latency_linear_load egress throughput +0.12 [-0.34, +0.58] 1 Logs
file_to_blackhole_0ms_latency_http1 egress throughput +0.03 [-0.75, +0.81] 1 Logs
quality_gate_idle_all_features memory utilization +0.02 [-0.03, +0.06] 1 Logs bounds checks dashboard
file_to_blackhole_100ms_latency egress throughput +0.01 [-0.65, +0.67] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput -0.00 [-0.03, +0.02] 1 Logs
file_to_blackhole_300ms_latency egress throughput -0.01 [-0.63, +0.61] 1 Logs
file_to_blackhole_0ms_latency egress throughput -0.01 [-0.78, +0.76] 1 Logs
file_to_blackhole_0ms_latency_http2 egress throughput -0.02 [-0.80, +0.77] 1 Logs
uds_dogstatsd_to_api ingress throughput -0.02 [-0.31, +0.27] 1 Logs
file_tree memory utilization -0.08 [-0.14, -0.01] 1 Logs
file_to_blackhole_1000ms_latency egress throughput -0.26 [-1.04, +0.53] 1 Logs
quality_gate_logs % cpu utilization -1.04 [-3.94, +1.86] 1 Logs
uds_dogstatsd_to_api_cpu % cpu utilization -2.33 [-3.22, -1.43] 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 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
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_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.

@pimlu pimlu marked this pull request as ready for review February 28, 2025 21:28
@pimlu pimlu requested review from a team as code owners February 28, 2025 21:28
@pimlu pimlu requested review from dustmop and mbakht February 28, 2025 21:28
Copy link
Contributor

@dustmop dustmop left a comment

Choose a reason for hiding this comment

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

LGTM for files owned by agent-configuration

@@ -0,0 +1,148 @@
// Unless explicitly stated otherwise all files in this repository are licensed
Copy link
Member

Choose a reason for hiding this comment

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

I think we should avoid re-implementing cache ourselves if possible.

Is there are well known cache library we can use instead of a custom impl?

It seems that https://github.com/jellydator/ttlcache could work for this case?
This seems to be already used un multiple places in datadog-agent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would work. I was originally looking at pkg/util/cache.go which also implements a TTL cache, but it requires string keys which is not useful for us. I missed ttlcache, it seems like it is suitable.

Comment on lines 49 to 52
// we only blacklist short traceroutes
if len(path.Hops) > s.config.MaxTTL {
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we start with:

Suggested change
// we only blacklist short traceroutes
if len(path.Hops) > s.config.MaxTTL {
return false
}
// we only blacklist short traceroutes
if len(path.Hops) > 2 {
return false
}

to only target hops with 1 and 2 hops? I think it will be safer that way and we also cover >80%

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, will remove this config

return false
}
// none of the intermediate hops should be reachable otherwise it is a "useful" path
for i := range len(path.Hops) - 1 {
Copy link
Member

@AlexandreYang AlexandreYang Mar 3, 2025

Choose a reason for hiding this comment

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

What about this simpler version? :)

Suggested change
for i := range len(path.Hops) - 1 {
for i := path.Hops {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intent of this was to loop through all but the last hop - since we are removing config.MaxTTL it won't be necessary anymore. Will update

Comment on lines 487 to 492
config.BindEnvAndSetDefault("network_path.collector.blacklist_cache.capacity", 20000)
config.BindEnvAndSetDefault("network_path.collector.blacklist_cache.duration", "2h")
config.BindEnvAndSetDefault("network_path.collector.blacklist_cache.clean_interval", "10m")
config.BindEnvAndSetDefault("network_path.collector.blacklist_scanner.enabled", true)
config.BindEnvAndSetDefault("network_path.collector.blacklist_scanner.max_ttl", 2)
config.BindEnvAndSetDefault("network_path.collector.blacklist_scanner.only_private_subnets", true)
Copy link
Member

@AlexandreYang AlexandreYang Mar 3, 2025

Choose a reason for hiding this comment

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

I think we should avoid exposing configs if possible.

We probably only need to expose:

  • Enable/Disable this blacklist/filter/exclusion feature
  • Expiration TTL

The other ones seems not needed / can be kept hard coded (user can't change them).

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, I will remove these configs. What do you think about retaining a cache capacity config to limit memory consumption?

@@ -337,6 +342,16 @@ func (s *npCollectorImpl) runTracerouteForPath(ptest *pathteststore.PathtestCont
path.Namespace = s.networkDevicesNamespace
path.Origin = payload.PathOriginNetworkTraffic

if s.blacklistScanner.ShouldBlacklist(&path) {
Copy link
Member

Choose a reason for hiding this comment

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

I think "runTracerouteForPath" should not be responsible for this new logic.

I would suggestion replace s.runTracerouteForPath with s.processPathtest(), then in processPathtest() have:

  • a/ s.runTracerouteForPath() that only runs the traceroute and returns the result pathtrace without sending the data to event platform
  • b/ evaluate if the result pathtrace should be discarded
  • c/ s.forwardToEventPlatform(): send payload to event platform

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I will separate these out

Comment on lines 348 to 351
hash := ptest.Pathtest.GetHash()
s.blacklistCache.Add(hash)
s.pathtestStore.RemoveHash(hash)
// no need to do further processing since it's blacklisted
Copy link
Member

Choose a reason for hiding this comment

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

I think we should avoid removing completely an entry from pathtestStore while it's being processed.
It can possibly lead to subtle bugs.

Maybe we can just set PathtestContext.runUntil to 0, that way, it will be discarded automatically at next flush.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RemoveHash and Flush both hold onto the contexts mutex so it should be safe no?

Comment on lines 58 to 60
// Blacklist of low-value pathtests
blacklistCache *blacklist.Cache
blacklistScanner *blacklist.Scanner
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be best, if we only expose a one API instead of two Cache+Scanner.

I think the caller doesn't need to be aware of the low level cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I will refactor this

@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 Mar 3, 2025
@pimlu pimlu changed the title [NPM-4243] Cache low-value network path contexts in a blacklist [NPM-4243] Cache low-value network path contexts and discard them Mar 3, 2025
Copy link
Member

@AlexandreYang AlexandreYang left a comment

Choose a reason for hiding this comment

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

I think the approach looks fine overall, but let's sync before merging this :)

I think we might want to make this feature generic enough so that we can easily handle various cases in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog long review PR is complex, plan time to review it qa/done QA done before merge and regressions are covered by tests team/networks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants