Skip to content

Commit 22c6730

Browse files
Copilotmatmerr
andcommitted
Add comprehensive GitHub Copilot instructions for Retina development
Co-authored-by: matmerr <[email protected]>
1 parent 040c137 commit 22c6730

File tree

24 files changed

+158
-54
lines changed

24 files changed

+158
-54
lines changed

.github/copilot-instructions.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Retina - eBPF Network Observability Platform
2+
3+
Retina is a cloud-agnostic, open-source Kubernetes network observability platform that provides centralized monitoring for application health, network health, and security. Built with Go, eBPF, and container technologies for Linux and Windows environments.
4+
5+
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
6+
7+
## Working Effectively
8+
9+
### Environment Setup
10+
- Install required dependencies:
11+
- `sudo apt update && sudo apt install -y clang llvm-strip-18 jq`
12+
- `sudo ln -sf /usr/bin/llvm-strip-18 /usr/bin/llvm-strip` (if needed)
13+
- Go 1.24.6+ required (check with `go version`)
14+
- Docker and Helm required for container operations
15+
- `clang` and `llvm-strip` are CRITICAL for eBPF compilation
16+
17+
### Core Build Commands
18+
- `make retina` -- builds retina binary -- takes ~1 minute (includes eBPF generation). NEVER CANCEL. Set timeout to 10+ minutes.
19+
- `make retina-capture-workload` -- builds capture workload binary -- takes ~2 seconds
20+
- CLI: `cd cli && go build -o ../output/linux_amd64/retina/kubectl-retina .` -- takes ~6 seconds
21+
- `make clean` -- clean build artifacts -- takes < 1 second
22+
23+
### Testing and Validation
24+
- `make test` -- runs full test suite -- takes 10+ minutes. NEVER CANCEL. Set timeout to 20+ minutes.
25+
- Basic package tests: `go test -timeout 10m -tags=unit ./pkg/...` -- takes ~6 minutes with some expected failures in cross-platform code
26+
- `make fmt` -- format code -- takes ~1 second
27+
- `make lint` -- runs linting -- takes ~2-3 minutes. May show some issues in generated mock files that can be ignored.
28+
29+
### BPF Generation and Plugins
30+
- BPF generation for current architecture works: generates `.o` and `.go` files for eBPF programs
31+
- Cross-compilation (ARM64) may fail in development environment - this is expected
32+
- Plugin test example: `cd test/plugin && make test-packetforward` -- builds and runs plugin tests with sudo
33+
- Individual plugins can be tested but require network traffic to show meaningful data
34+
35+
## Validation Scenarios
36+
37+
### Basic Functionality Validation
38+
Always test these core workflows after making changes:
39+
40+
1. **Build and run agent**:
41+
```bash
42+
make retina
43+
./output/linux_amd64/retina/retina --help
44+
```
45+
46+
2. **Build and test CLI**:
47+
```bash
48+
cd cli && go build -o ../output/linux_amd64/retina/kubectl-retina .
49+
./output/linux_amd64/retina/kubectl-retina --help
50+
./output/linux_amd64/retina/kubectl-retina version
51+
```
52+
53+
3. **Test plugin functionality**:
54+
```bash
55+
cd test/plugin && make test-packetforward
56+
# This will run until Ctrl+C - expect to see "Start collecting packet forward metrics"
57+
```
58+
59+
## Critical Build Timing and Warnings
60+
61+
### NEVER CANCEL - Build Time Expectations
62+
- **Main binary build (`make retina`)**: Takes 1-2 minutes including eBPF generation. NEVER CANCEL. Use timeout 10+ minutes.
63+
- **Full test suite (`make test`)**: Takes 10-15 minutes. NEVER CANCEL. Use timeout 20+ minutes.
64+
- **Linting (`make lint`)**: Takes 2-3 minutes. NEVER CANCEL. Use timeout 5+ minutes.
65+
- **Plugin tests**: Can run indefinitely waiting for network traffic - this is expected behavior.
66+
67+
### Expected Build Issues
68+
- Cross-compilation for ARM64 may fail with "exec format error" - this is expected in development environment
69+
- Some unit tests fail due to missing kubebuilder/etcd dependencies - this is expected
70+
- Lint warnings about generated mock files are expected and can be ignored
71+
- BPF compilation warnings about operator precedence are expected and harmless
72+
73+
## Project Structure
74+
75+
### Key Directories
76+
- `/pkg/plugin/` - eBPF plugins for network observability (conntrack, dropreason, packetforward, etc.)
77+
- `/controller/` - Main retina agent controller code
78+
- `/cli/` - kubectl-retina CLI implementation
79+
- `/captureworkload/` - Network capture workload implementation
80+
- `/operator/` - Kubernetes operator code
81+
- `/test/plugin/` - Individual plugin test utilities
82+
- `/docs/08-Contributing/02-development.md` - Detailed development guide
83+
84+
### Important Files
85+
- `Makefile` - Primary build system with comprehensive targets
86+
- `go.mod` - Go 1.24.6, extensive Kubernetes and eBPF dependencies
87+
- `.devcontainer/` - GitHub Codespaces configuration with required tools
88+
- `.github/workflows/` - CI/CD pipelines for testing and building
89+
90+
## Common Development Tasks
91+
92+
### Before Committing Changes
93+
Always run these commands before pushing:
94+
1. `make fmt` - Format code (required for CI)
95+
2. `make lint` - Check code quality (may show expected warnings)
96+
3. `make retina` - Ensure main binary builds correctly
97+
4. Test CLI: `cd cli && go build .` - Ensure CLI builds
98+
99+
### Working with eBPF Code
100+
- eBPF source files are in `pkg/plugin/*/\_cprog/` directories
101+
- Generated files: `*_bpfel_x86.o` and `*_bpfel_x86.go`
102+
- BPF generation happens automatically during build
103+
- Some compiler warnings about operator precedence are expected and harmless
104+
105+
### Container and Helm Operations
106+
- `make retina-image` - Build container image (requires registry access)
107+
- Images are published to GHCR (GitHub Container Registry)
108+
- Helm charts are available in the repository for deployment
109+
- Full deployment requires Kubernetes cluster with appropriate permissions
110+
111+
## Debugging and Troubleshooting
112+
113+
### Common Issues
114+
- **"exec format error"**: Usually cross-compilation issue, rebuild for current arch
115+
- **Missing kubebuilder**: Some tests require Kubernetes test environment
116+
- **Plugin tests hanging**: Normal behavior - plugins wait for network traffic
117+
- **Lint failures**: Check if they're in generated mock files (can be ignored)
118+
- **BPF compilation warnings**: Expected and generally harmless
119+
120+
### Log Analysis
121+
- Agent logs provide detailed eBPF and networking information
122+
- CLI operations are verbose and show capture job creation details
123+
- Plugin tests show real-time network metrics when traffic is available
124+
125+
This is a complex, enterprise-grade networking platform. Take time to understand the eBPF integration and Kubernetes-native architecture before making changes.

cli/cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ type Config struct {
2424
}
2525

2626
var Retina = &cobra.Command{
27-
Use: "kubectl-retina",
27+
Use: "kubectl-retina",
2828
Short: "A kubectl plugin for Retina",
29-
Long: "A kubectl plugin for Retina\nRetina is an eBPF distributed networking observability tool for Kubernetes.",
29+
Long: "A kubectl plugin for Retina\nRetina is an eBPF distributed networking observability tool for Kubernetes.",
3030
PersistentPreRun: func(*cobra.Command, []string) {
3131
var config Config
3232
file, _ := os.ReadFile(ClientConfigPath)

deploy/testutils/grafana/dashboards/simplify-grafana-overwrite_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
func TestOverwriteDashboards(t *testing.T) {
1212
// get all json's in various generation deploly folders
1313
files, err := filepath.Glob("../../../grafana-dashboards/*.json")
14-
1514
if err != nil {
1615
t.Fatal(err)
1716
}

deploy/testutils/grafana/dashboards/simplify-grafana_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
func TestDashboardsAreSimplified(t *testing.T) {
1313
// get all json's in this folder
1414
files, err := filepath.Glob("../../../grafana-dashboards/*.json")
15-
1615
if err != nil {
1716
t.Fatal(err)
1817
}

init/retina/retina

33.9 MB
Binary file not shown.

operator/cilium-crds/k8s/fakeresource.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
"github.com/cilium/cilium/pkg/k8s/resource"
99
)
1010

11-
type fakeresource[T k8sRuntime.Object] struct {
12-
}
11+
type fakeresource[T k8sRuntime.Object] struct{}
1312

1413
func (f *fakeresource[T]) Events(ctx context.Context, opts ...resource.EventsOpt) <-chan resource.Event[T] {
1514
return make(<-chan resource.Event[T])

pkg/k8s/watcher_linux.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ func init() {
2323
}
2424
}
2525

26-
var (
27-
logger = logging.DefaultLogger.WithField(logfields.LogSubsys, "k8s-watcher")
28-
)
26+
var logger = logging.DefaultLogger.WithField(logfields.LogSubsys, "k8s-watcher")
2927

3028
func Start(ctx context.Context, k *watchers.K8sWatcher) {
3129
logger.Info("Starting Kubernetes watcher")

pkg/plugin/ciliumeventobserver/parser_linux.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import (
1616
"go.uber.org/zap"
1717
)
1818

19-
var (
20-
ErrEmptyData = errors.New("empty data")
21-
)
19+
var ErrEmptyData = errors.New("empty data")
2220

2321
func (p *parser) Init() error {
2422
parser, err := hp.New(slog.Default().With("cilium", "parser"),

pkg/plugin/hnsstats/vfp_counters_windows.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ func getVfpPortCountersRaw(portGUID string) (string, error) {
152152

153153
cmd := exec.Command("cmd", "/c", vfpCmd)
154154
out, err := cmd.Output()
155-
156155
if err != nil {
157156
return "", errors.Wrap(err, "errored while running vfpctrl /get-port-counter")
158157
}

pkg/plugin/linuxutil/types_linux.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import (
99
"github.com/safchain/ethtool"
1010
)
1111

12-
const name = "linuxutil"
13-
const defaultLimit = 2000
12+
const (
13+
name = "linuxutil"
14+
defaultLimit = 2000
15+
)
1416

1517
//go:generate go run go.uber.org/mock/[email protected] -source=types_linux.go -destination=linuxutil_mock_generated_linux.go -package=linuxutil
1618
type linuxUtil struct {

0 commit comments

Comments
 (0)