Skip to content

Add kubectl retina debug drop command for real-time packet drop monitoring #1673

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 9, 2025

This PR implements a new kubectl retina debug drop command that provides real-time monitoring of packet drop events using eBPF, converting the drop debug script functionality into a Go-based CLI subcommand.

Features

  • Real-time monitoring: Uses the existing dropreason plugin to capture drop events live
  • Console formatting: Dynamic output formatting with word wrapping to fit terminal width
  • File output: Optional file writing capability via --output flag
  • User confirmation: Prompts for confirmation before invasive operations like port-forwarding
  • IP filtering: Filter events by specific IP addresses using --ips flag
  • Error handling: Comprehensive error messages for common eBPF permission issues

Usage

# Basic usage - monitor for 30 seconds
kubectl retina debug drop

# Monitor for specific duration and save to file
kubectl retina debug drop --duration=60s --output=drops.log

# Filter by IP addresses
kubectl retina debug drop --ips=10.0.0.1,10.0.0.2

# Skip confirmation prompts
kubectl retina debug drop --confirm=false

Output Format

TIMESTAMP            SRC_IP          DST_IP          PROTO      DROP_REASON          DETAILS
21:30:15.123         10.0.0.1        10.0.0.2        TCP        DROP(42)             Connection refused
21:30:15.456         10.0.0.3        10.0.0.4        UDP        DROP(13)             No route to host

Implementation Details

  • Command structure: Added debug command group under cli/cmd/debug/
  • Integration: Leverages existing pkg/plugin/dropreason plugin via event channels
  • Architecture: Follows established CLI patterns from capture commands
  • Testing: Comprehensive test coverage for flags, defaults, and functionality
  • Documentation: Complete documentation in new docs/05-Debug/ section

Requirements

  • Linux environment with eBPF support
  • Sufficient privileges for eBPF operations (may require sudo)
  • Modern kernel version (4.9+)

The command provides helpful error messages when eBPF capabilities are not available, guiding users on common resolution steps.

Fixes #1672.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits June 9, 2025 21:31
Co-authored-by: matmerr <6521405+matmerr@users.noreply.github.com>
Co-authored-by: matmerr <6521405+matmerr@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Krew plugin watching for drop events Add kubectl retina debug drop command for real-time packet drop monitoring Jun 9, 2025
@Copilot Copilot AI requested a review from matmerr June 9, 2025 21:39
Copilot finished work on behalf of matmerr June 9, 2025 21:39
// Place holder header file that will be replaced by the actual header file during runtime
// DO NOT DELETE
#define ADVANCED_METRICS 1
#define BYPASS_LOOKUP_IP_OF_INTEREST 0
Copy link
Contributor

Choose a reason for hiding this comment

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

this should not be part of the PR

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 commit 222d88e - reverted the dynamic.h file that was not part of the intended changes.

Long: "Debug network issues using various Retina debugging tools",
}

func init() {
Copy link
Contributor

Choose a reason for hiding this comment

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

There could be some conflicts with the refactor going on at - #1693

dropCmd.Flags().StringVar(&dropOpts.podName, "pod-name", "", "Specific pod name to monitor (optional)")
dropCmd.Flags().StringSliceVar(&dropOpts.ips, "ips", nil, "IP addresses to filter for (optional)")
dropCmd.Flags().BoolVar(&dropOpts.verbose, "verbose", false, "Enable verbose output")
dropCmd.Flags().IntVar(&dropOpts.consoleWidth, "width", 0, "Console width for formatting (auto-detected if 0)")
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a reason to have consoleWidth as a flag. It should always just auto-detect.

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 commit 222d88e - removed the --width flag and made console width auto-detection the only behavior. The consoleWidth is now always automatically detected from the terminal.


The `kubectl retina debug drop` command monitors packet drop events in real-time using eBPF technology. This helps network operators and developers quickly identify and troubleshoot packet loss issues.

**Key Features:**
Copy link
Contributor

Choose a reason for hiding this comment

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

Number of linting errors here. Need to be fixed.

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 commit 222d88e - resolved all markdown linting errors in docs/05-Debug/00-overview.md including missing blank lines around lists, language specification for code blocks, and proper file ending.


The command displays drop events in a tabular format:

```
Copy link
Contributor

Choose a reason for hiding this comment

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

Some linting errors here. Need to be fixed.

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 commit 222d88e - resolved all markdown linting errors in docs/05-Debug/01-cli.md including proper heading formatting, blank lines around code blocks, and language specification.

RunE: runDropCommand,
}

func init() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The script under scripts/watch_drops.sh states Poll drop counters on a specific node every INTERVAL seconds (default 30). The go code in this change does not have a configurable interval

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 commit 222d88e - added --interval flag with 1s default to match the configurable interval functionality in watch_drops.sh script. The interval controls the MetricsInterval configuration for the dropreason plugin.

…g, revert dynamic.h

Co-authored-by: kamilprz <36544756+kamilprz@users.noreply.github.com>
@Copilot Copilot AI requested a review from kamilprz June 20, 2025 08:05
Copilot finished work on behalf of kamilprz June 20, 2025 08:05
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.

Krew plugin watching for drop events
3 participants