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

[NETPATH-100] TCP Traceroute Implementation POC #25714

Merged
merged 24 commits into from
May 31, 2024
Merged

Conversation

ken-schneider
Copy link
Contributor

@ken-schneider ken-schneider commented May 17, 2024

https://datadoghq.atlassian.net/browse/NETPATH-100

What does this PR do?

This adds a TCPv4 implementation of traceroute to the agent. This allows for onboarding targets to Network Path that do not respond to UDP traceroutes.

Motivation

Allow better path tracing for TCP servers and services and more accurately trace paths that live traffic from the host might take for TCP connections.

Additional Notes

Possible Drawbacks / Trade-offs

Describe how to test/QA your changes

  1. Ensure you're running the agent inside of a Linux environment.
  2. Configure the agent in conf.d/network_path.d/config.yaml to target a web server and set protocol to TCP:
instances:
- hostname: app.datadoghq.eu
  protocol: tcp
  port: 80
  1. Enable traceroute system-probe module and set debug level logs:
    system-probe.yaml
traceroute:
  enabled: true

log_level: debug
  1. Enable debug logs in datadog.yaml:
log_level: debug
  1. See that logs related to TCP traceroute show up in /var/log/datadog/system-probe.log and are succeeding.
  2. If you have the agent configured to send to the datadog back end, check to see that the paths are showing up inside datadog
    If you have it set to send traces to the back end, validate that the

@ken-schneider ken-schneider changed the title start tcp implementation [NETPATH-100] TCP Traceroute Implementation POC May 17, 2024
Copy link

cit-pr-commenter bot commented May 17, 2024

Go Package Import Differences

Baseline: d407c3d
Comparison: 6ee6cd3

binaryosarchchange
agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
agentlinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
agentwindowsamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
agentdarwinamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
agentdarwinarm64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
iot-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
iot-agentlinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
heroku-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
cluster-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
cluster-agentlinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
process-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
process-agentlinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
process-agentwindowsamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
process-agentdarwinamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
process-agentdarwinarm64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
heroku-process-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
system-probelinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
system-probelinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp
system-probewindowsamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/tcp

@pr-commenter
Copy link

pr-commenter bot commented May 20, 2024

Regression Detector

Regression Detector Results

Run ID: 52a59538-b2f9-4cb7-bac3-5327206624d0
Baseline: d407c3d
Comparison: 6ee6cd3

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

No significant changes in experiment optimization goals

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

There were no significant changes in experiment optimization goals at this confidence level and effect size tolerance.

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI
tcp_syslog_to_blackhole ingress throughput +2.93 [-18.54, +24.39]
uds_dogstatsd_to_api_cpu % cpu utilization +1.17 [-1.82, +4.17]
basic_py_check % cpu utilization +0.10 [-2.85, +3.05]
trace_agent_msgpack ingress throughput +0.00 [-0.00, +0.00]
trace_agent_json ingress throughput -0.00 [-0.01, +0.01]
uds_dogstatsd_to_api ingress throughput -0.01 [-0.21, +0.19]
tcp_dd_logs_filter_exclude ingress throughput -0.03 [-0.07, +0.02]
otel_to_otel_logs ingress throughput -0.10 [-0.48, +0.28]
idle memory utilization -0.42 [-0.47, -0.38]
file_tree memory utilization -1.84 [-1.98, -1.71]
pycheck_1000_100byte_tags % cpu utilization -2.08 [-6.81, +2.66]

Explanation

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".

Copy link
Contributor

@leeavital leeavital left a comment

Choose a reason for hiding this comment

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

adding some light comments, but structure looks good!

One thing we may want to consider extracting the icmp/tcp calls to something mockable to get better test coverage.

pkg/collector/corechecks/networkpath/config.go Outdated Show resolved Hide resolved
var pathResult payload.NetworkPath
switch protocol {
case TCP:
log.Debugf("Running TCP traceroute for: %+v", cfg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Per the profiling data, we should be careful about logging here. It consumes a lot of CPU at scale.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is that something that continues to consume high CPU even if log level is set to info i.e. when this becomes a noop? Or is this just a concern for when debug logging is active

Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC it consumes much more when enabled, but the CPU is non-zero even if logging is disabled.

Also, we periodically tell customers to enable debug logging during support cases.

return checksum(append(pseudoHeader, tcpHeader...))
}

func listenAnyPacket(icmpConn *ipv4.RawConn, tcpConn *ipv4.RawConn, timeout time.Duration, localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16) (net.IP, uint16, layers.ICMPv4TypeCode, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

two nits:

  1. documentation on this is appreciated! It's hard to tell what's happening just from the type signature
  2. I recommend reordering this file in function call order so this method appears before the helpers used by it https://github.com/uber-go/guide/blob/master/style.md#function-grouping-and-ordering

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment to the re-named listenPacket to explain what's going on and re-ordered the functions accordingly

src := util.AddressFromNetIP(res.Source)
dst := util.AddressFromNetIP(res.Target)

traceroutePath.Source.Via = r.gatewayLookup.LookupWithIPs(src, dst, r.nsIno)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this is fine to start, but NPM should already be doing a gateway lookup per IP -- have you thought about ways to share the lookup ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, when I modified the Gateway lookup to work with traceroute, I tried to see if there was a way to share it and tried for a while to make it work but had some difficulties. I discussed with @hmahmood at the time and we agreed for now it was best to keep them separate.

I agree though, it would definitely be better if we could create some sort of singleton to share the caches or something along those lines.

pkg/networkpath/traceroute/runner.go Show resolved Hide resolved
TimeoutMs: 0, // TODO: make it configurable, setting 0 to use default value for now
MaxTTL: 0, // TODO: make it configurable, setting 0 to use default value for now
TimeoutMs: 0, // TODO: make it configurable, setting 0 to use default value for now
Protocol: traceroute.TCP, // TODO: would we ever want UDP here?
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 use the protocol from the NPM conns, some changes are needed to pass protocol from npCollectorImpl.ScheduleConns() to PathtestContext and then to traceroute.Config here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a separate PR to merge into this one that handles this: #26110

@ken-schneider ken-schneider marked this pull request as ready for review May 24, 2024 19:52
@ken-schneider ken-schneider requested review from a team as code owners May 24, 2024 19:52
@pr-commenter
Copy link

pr-commenter bot commented May 24, 2024

Test changes on VM

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

inv create-vm --pipeline-id=35592411 --os-family=ubuntu

Copy link

codecov bot commented May 24, 2024

Codecov Report

Attention: Patch coverage is 26.87140% with 381 lines in your changes are missing coverage. Please review.

Project coverage is 43.89%. Comparing base (d407c3d) to head (6ee6cd3).
Report is 12 commits behind head on main.

Files Patch % Lines
pkg/networkpath/traceroute/tcp/utils.go 42.48% 150 Missing and 3 partials ⚠️
pkg/networkpath/traceroute/runner.go 11.19% 119 Missing ⚠️
pkg/networkpath/traceroute/tcp/tcpv4.go 0.00% 99 Missing ⚠️
pkg/networkpath/traceroute/utils.go 50.00% 2 Missing and 1 partial ⚠️
pkg/networkpath/traceroute/traceroute_linux.go 0.00% 2 Missing ⚠️
pkg/process/net/common.go 0.00% 2 Missing ⚠️
cmd/system-probe/modules/traceroute.go 66.66% 1 Missing ⚠️
...kg/collector/corechecks/networkpath/networkpath.go 0.00% 1 Missing ⚠️
pkg/networkpath/traceroute/traceroute_windows.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #25714       +/-   ##
===========================================
- Coverage   45.17%   43.89%    -1.29%     
===========================================
  Files        2349      319     -2030     
  Lines      270700    26699   -244001     
===========================================
- Hits       122296    11720   -110576     
+ Misses     138747    14446   -124301     
+ Partials     9657      533     -9124     
Flag Coverage Δ
amzn_aarch64 45.67% <26.92%> (-0.34%) ⬇️
centos_x86_64 45.67% <26.92%> (-0.24%) ⬇️
ubuntu_aarch64 45.67% <26.92%> (-0.34%) ⬇️
ubuntu_x86_64 45.67% <26.92%> (-0.34%) ⬇️
windows_amd64 37.92% <27.07%> (-13.48%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pkg/networkpath/traceroute/runner.go Show resolved Hide resolved
pkg/networkpath/traceroute/runner.go Show resolved Hide resolved
pkg/networkpath/traceroute/runner.go Show resolved Hide resolved
if err != nil {
return nil, err
}
defer conn.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this free up the local port?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does, we don't really care about binding to the port, I'm just using this to get a random ephemeral port number to use from the OS to send on. Since we have a raw connection we can set whatever source information we want.

if err != nil {
return net.IP{}, 0, 0, fmt.Errorf("failed to read: %w", err)
}
header, packet, _, err := conn.ReadFrom(buf)
Copy link
Contributor

Choose a reason for hiding this comment

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

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 did, I found it a bit after I originally implemented this. I'm going to have to do it in 2 steps for ICMP since we sometimes have to extend the inner TCP header when the ICMP response doesn't contain the whole thing. There's a future iteration of this where it might make more sense to just do the unmarshal manually

default:
}
now := time.Now()
err := conn.SetReadDeadline(now.Add(time.Millisecond * 100))
Copy link
Contributor

@hmahmood hmahmood May 28, 2024

Choose a reason for hiding this comment

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

Is this set for every iteration of the loop?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore the comment about epoll; The Readfrom + timeout should be the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is, I don't think there's a clean way to set the read deadline only once using a time.Duration

Copy link
Member

@robertjli robertjli left a comment

Choose a reason for hiding this comment

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

It seems like there's no impact to @DataDog/processes, approving


// Create TCP packet with the specified flags
// and sequence number
tcpPacket := make([]byte, 20)
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 use something like this https://pkg.go.dev/github.com/google/[email protected]/layers#TCP for constructing a tcp packet?

Copy link
Contributor

@leeavital leeavital left a comment

Choose a reason for hiding this comment

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

Approving as this is behind a config flag, and the structure looks generally fine. I'll do a second review for follow ups next week! Specifically I think we want to get better testcoverage on tcpv4.go

@ken-schneider
Copy link
Contributor Author

Approving as this is behind a config flag, and the structure looks generally fine. I'll do a second review for follow ups next week! Specifically I think we want to get better testcoverage on tcpv4.go

Agreed, planning to get testing of both the tcpv4 and utils up

@ken-schneider
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented May 31, 2024

🚂 MergeQueue

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.

Use /merge -c to cancel this operation!

@dd-devflow
Copy link

dd-devflow bot commented May 31, 2024

🚂 MergeQueue

Pull request added to the queue.

There are 14 builds ahead! (estimated merge in less than 7h)

Use /merge -c to cancel this operation!

@dd-mergequeue dd-mergequeue bot merged commit 27a5ca3 into main May 31, 2024
214 checks passed
@dd-mergequeue dd-mergequeue bot deleted the ken/traceroute-tcp branch May 31, 2024 18:34
@github-actions github-actions bot added this to the 7.55.0 milestone May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants