Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Report packet-capture statistics by host #179

Merged
merged 12 commits into from
Nov 11, 2022
Merged

Report packet-capture statistics by host #179

merged 12 commits into from
Nov 11, 2022

Conversation

thatplguy
Copy link
Contributor

This PR adds per-host packet capture statistics for TLS handshakes and HTTP requests, which readily have the host available. Per-host stats are uploaded with telemetry data and summarized as CLI output alongside per-port statistics.

This also adds hard limits on the number of ports, interfaces, and hosts that the CLI tracks for telemetry data. The CLI is a long-running process, and our telemetry data monotonically increases. We should consider capturing telemetry data in rolling windows in the future. For now, I chose a limit of 10,000 each for ports, interfaces, and hosts; if we assume hosts and interfaces are ~10 bytes, then that maxes out at ~2Mb. These are most useful in the first 60 seconds of running the CLI, so 10K should be more than enough.

Depends on postmanlabs/observability-shared-libs#174.

Here's what the CLI packet capture summary looks like with hosts:

[INFO] Created new trace on Akita Cloud: akita://akibox:trace:mud-fisher-74a4bce9
[INFO] Running learn mode on interfaces awdl0, llw0, utun4, en0, utun3, lo0, anpi2, utun5, utun2, utun6, anpi1, anpi0, utun0, utun1
[INFO] --filter flag is not set; capturing all network traffic to and from your services.
[INFO] Send SIGINT (Ctrl-C) to stop...
[INFO] Printing packet capture statistics after 60 seconds of capture.
[INFO] TCP port  8000:  1386 packets (50% of total), 99 HTTP requests, 99 HTTP responses, 0 TLS handshakes, 18 unparsed packets.
[INFO] TCP port   443:  1226 packets (44% of total), no HTTP requests or responses, 18 TLS handshakes indicating encrypted traffic.
[INFO] TCP port 64791:   136 packets (4% of total), no HTTP requests or responses; the data to this service could not be parsed.
[INFO] Host localhost:8000                                                   99 HTTP requests, 0 TLS handshakes.
[INFO] Host 560E52A873D46C9D31B9710C15766566.gr7.us-east-1.eks.amazonaws.com no HTTP requests, 4 TLS handshakes indicating encrypted traffic.
[INFO] Host sqs.us-west-1.amazonaws.com                                      no HTTP requests, 4 TLS handshakes indicating encrypted traffic.

@thatplguy thatplguy requested a review from a team November 11, 2022 06:41
apidump/summary.go Outdated Show resolved Hide resolved
Comment on lines 95 to 96
s.printPortHighlights(top)
s.printHostHighlights(top)
Copy link
Member

Choose a reason for hiding this comment

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

Can we clarify to the user that these highlights do not describe disjoint sets of traffic?

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 added section labels to that effect in dd88251.

Comment on lines 186 to 189
if left.HTTPRequests != right.HTTPRequests {
return left.HTTPRequests > right.HTTPRequests
} else if left.HTTPResponses != right.HTTPResponses {
return left.HTTPResponses > right.HTTPResponses
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 sort by the sum instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Changed in bf4d2b3.

trace/stats.go Outdated
@@ -131,11 +172,39 @@ func (s *PacketCounter) Summary(n int) *PacketCountSummary {
s.mutex.RLock()
defer s.mutex.RUnlock()

topByPort, byPortOverflow := s.byPort.TopN(n, func(c *PacketCounts) int { return c.TCPPackets })
topByInterface, byInterfaceOverflow := s.byInterface.TopN(n, func(c *PacketCounts) int { return c.TCPPackets })
topByHost, byHostOverflow := s.byHost.TopN(n, func(c *PacketCounts) int { return c.TCPPackets })
Copy link
Member

Choose a reason for hiding this comment

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

Aren't the TCP counts in byHost all zero, according to the XXX comment on line 37?

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, good point. Fixed in bf4d2b3.

trace/stats.go Outdated
limit: limit,
m: make(map[T]*PacketCounts),

// Accumulate across all interfaces and ports.
Copy link
Member

Choose a reason for hiding this comment

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

And hosts too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in bf4d2b3.

@@ -27,40 +28,71 @@ func (d *PacketCountDiscard) Update(_ PacketCounts) {
// In the future, this could put counters on a pipe and do the increments
// in a separate goroutine, but we would *still* need a mutex to read the
// totals out.
// TODO: limit maximum size
type PacketCounter struct {
Copy link
Member

Choose a reason for hiding this comment

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

Documentation should be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in bf4d2b3.

trace/stats.go Outdated Show resolved Hide resolved
trace/stats.go Outdated Show resolved Hide resolved
@thatplguy thatplguy merged commit cf4ce98 into main Nov 11, 2022
@thatplguy thatplguy deleted the cns/tls-hosts branch November 11, 2022 22:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants