Skip to content

feat(cli): add tcping subcommand#2249

Open
Kelvinoppong wants to merge 1 commit intomicrosoft:mainfrom
Kelvinoppong:feat/tcping
Open

feat(cli): add tcping subcommand#2249
Kelvinoppong wants to merge 1 commit intomicrosoft:mainfrom
Kelvinoppong:feat/tcping

Conversation

@Kelvinoppong
Copy link
Copy Markdown
Contributor

@Kelvinoppong Kelvinoppong commented Apr 24, 2026

Summary

Adds a new kubectl retina tcping HOST PORT subcommand that probes a TCP port by performing a full connect/close handshake, reports per-attempt RTT, and prints min/avg/max/loss statistics at the end (or on Ctrl+C).

This resolves #2022, which asked for a simple tool to generate continuous TCP traffic for debugging without needing curl in a while loop or heavier tools like nmap.

Behavior

  • Runs continuously until interrupted (SIGINT/SIGTERM) or until --count probes are sent.
  • Supports IPv4, IPv6, and hostnames (uses net.JoinHostPort + net.DialTimeout).
  • Prints a summary on exit including partial stats when interrupted mid-run.

Flags

Flag Default Description
-c, --count 0 (unlimited) Number of probes to send
-i, --interval 1s Interval between probes
-t, --timeout 2s TCP connect timeout per probe

Example

$ kubectl retina tcping 1.1.1.1 443 --count 3
TCPing 1.1.1.1:443: tcp connect ...
seq=1 1.1.1.1:443 rtt=9.893ms
seq=2 1.1.1.1:443 rtt=8.576ms
seq=3 1.1.1.1:443 rtt=11.077ms

--- 1.1.1.1:443 tcping statistics ---
3 probes sent, 3 successful, 0.0% loss
rtt min/avg/max = 8.576ms/9.849ms/11.077ms

Test plan

  • Unit tests covering success, connection failure, stats aggregation (min/max/avg/loss), help output, and arg validation (cli/cmd/tcping_test.go).
  • All existing CLI tests still pass (go test ./cli/...).
  • go vet ./cli/... clean.
  • Manual smoke tests:
    • IPv4 happy path (1.1.1.1:443)
    • Hostname/DNS resolution (google.com:443)
    • IPv6 ([::1]:22)
    • DNS failure (nonexistent.invalid.domain:80)
    • Connection refused (127.0.0.1:1)
    • SIGI summary with exit 0

Fixes #2022

Add a lightweight `kubectl retina tcping HOST PORT` subcommand that probes
a TCP port by performing a full connect()/close() handshake and reports
per-attempt RTT plus final min/avg/max/loss statistics.

This removes the need for ad-hoc `curl` loops (or heavier tools like nmap)
when users want to generate simple, continuous TCP traffic against a
service while debugging with Retina. Behavior mirrors `ping`: it runs
until interrupted (SIGINT/SIGTERM) or until `--count` probes have been
sent, then prints a summary.

Flags:
  -c, --count     number of probes (0 = unlimited, default)
  -i, --interval  interval between probes (default 1s)
  -t, --timeout   TCP connect timeout per probe (default 2s)

Fixes microsoft#2022
@Kelvinoppong Kelvinoppong requested a review from a team as a code owner April 24, 2026 17:01
@Kelvinoppong
Copy link
Copy Markdown
Contributor Author

@nddq I have tackled another issue and this PR is ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tcping to retina

1 participant