|
| 1 | +# CLAUDE.md - Project Guide for skywalking-infra-e2e |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +Apache SkyWalking Infra E2E is a CLI tool for end-to-end testing. It orchestrates test environments |
| 6 | +(Kubernetes/Kind or Docker Compose), generates traffic, verifies results, and cleans up. |
| 7 | + |
| 8 | +## Build & Test Commands |
| 9 | + |
| 10 | +```bash |
| 11 | +make all # clean + lint + test + build |
| 12 | +make test # run unit tests with coverage |
| 13 | +make lint # run golangci-lint (auto-installs if missing) |
| 14 | +make build # build for windows/linux/darwin |
| 15 | +make darwin # build for macOS only (use your current OS target) |
| 16 | +make e2e-test # run e2e test with Docker Compose (test/e2e/e2e.yaml) |
| 17 | +make e2e-test-kind # run e2e test with Kind (test/e2e/kind/e2e.yaml) |
| 18 | +``` |
| 19 | + |
| 20 | +- Go module: `github.com/apache/skywalking-infra-e2e` |
| 21 | +- Entry point: `cmd/e2e/main.go` |
| 22 | +- Binary output: `bin/<os>/e2e` |
| 23 | +- Version injected via ldflags at build time |
| 24 | + |
| 25 | +## Architecture |
| 26 | + |
| 27 | +### CLI Commands (Cobra) |
| 28 | + |
| 29 | +| Command | File | Purpose | |
| 30 | +|---------------|-------------------------------|--------------------------------| |
| 31 | +| `e2e run` | `commands/run/run.go` | Full lifecycle orchestration | |
| 32 | +| `e2e setup` | `commands/setup/setup.go` | Setup env only (debug mode) | |
| 33 | +| `e2e trigger` | `commands/trigger/trigger.go` | Run trigger only | |
| 34 | +| `e2e verify` | `commands/verify/verify.go` | Run verification only | |
| 35 | +| `e2e cleanup` | `commands/cleanup/cleanup.go` | Run cleanup only | |
| 36 | + |
| 37 | +Global flags defined in `commands/root.go`: |
| 38 | +- `-c, --config` (default: `e2e.yaml`) |
| 39 | +- `-v, --verbosity` (debug/info/warn/error) |
| 40 | +- `-w, --work-dir` (default: `~/.skywalking-infra-e2e`) |
| 41 | +- `-l, --log-dir` (default: `~/.skywalking-infra-e2e/logs`) |
| 42 | + |
| 43 | +### Lifecycle (`e2e run`) |
| 44 | + |
| 45 | +``` |
| 46 | +setup → trigger → verify → cleanup (deferred) |
| 47 | +``` |
| 48 | + |
| 49 | +Cleanup runs via Go `defer` and is controlled by `cleanup.on`: |
| 50 | +- `always` / `success` / `failure` / `never` |
| 51 | +- Default: `success` locally, `always` in CI (`CI=true` env var) |
| 52 | +- Constants in `internal/constant/cleanup.go` |
| 53 | + |
| 54 | +### Environment Modes |
| 55 | + |
| 56 | +Determined by `setup.env` in e2e.yaml (`"kind"` or `"compose"`). |
| 57 | + |
| 58 | +Constants: `constant.Kind` and `constant.Compose` in `internal/constant/`. |
| 59 | + |
| 60 | +**Kind mode** (`internal/components/setup/kind.go`): |
| 61 | +- Creates Kind cluster, loads Docker images, applies K8s manifests |
| 62 | +- Pod log streaming via K8s client-go |
| 63 | +- Port forwarding via SPDY |
| 64 | +- Cleanup: `kind delete cluster` with retry (up to 5x) |
| 65 | + |
| 66 | +**Compose mode** (`internal/components/setup/compose.go`): |
| 67 | +- Uses testcontainers-go for Docker Compose |
| 68 | +- Container log streaming |
| 69 | +- Cleanup: `docker-compose down` |
| 70 | + |
| 71 | +### Configuration |
| 72 | + |
| 73 | +Config struct: `internal/config/e2eConfig.go` → `E2EConfig` |
| 74 | + |
| 75 | +```yaml |
| 76 | +setup: |
| 77 | + env: kind|compose |
| 78 | + file: path/to/kind-config.yaml # or docker-compose.yml |
| 79 | + kubeconfig: path # alternative to file (use existing cluster) |
| 80 | + timeout: 20m |
| 81 | + steps: |
| 82 | + - name: step-name |
| 83 | + path: manifest.yaml # or command: "shell cmd" |
| 84 | + wait: |
| 85 | + - namespace: default |
| 86 | + resource: pod |
| 87 | + label-selector: app=foo |
| 88 | + for: condition=Ready |
| 89 | + kind: |
| 90 | + import-images: [image:tag] |
| 91 | + expose-ports: |
| 92 | + - namespace: default |
| 93 | + resource: pod/name |
| 94 | + port: "8080" |
| 95 | + |
| 96 | +cleanup: |
| 97 | + on: always|success|failure|never |
| 98 | + |
| 99 | +trigger: |
| 100 | + action: http |
| 101 | + interval: 3s |
| 102 | + times: 5 |
| 103 | + url: http://... |
| 104 | + method: GET |
| 105 | + |
| 106 | +verify: |
| 107 | + retry: { count: 10, interval: 10s } |
| 108 | + fail-fast: true |
| 109 | + concurrency: false |
| 110 | + cases: |
| 111 | + - name: case-name |
| 112 | + query: "shell command" # or actual: path/to/file |
| 113 | + expected: path/to/expected.yaml |
| 114 | +``` |
| 115 | +
|
| 116 | +### Key Packages |
| 117 | +
|
| 118 | +| Package | Role | |
| 119 | +|--------------------------------------|-------------------------------------------| |
| 120 | +| `internal/config/` | YAML config parsing, global config state | |
| 121 | +| `internal/components/setup/` | Kind & Compose setup implementations | |
| 122 | +| `internal/components/trigger/` | HTTP trigger action | |
| 123 | +| `internal/components/verifier/` | Test case verification with retry | |
| 124 | +| `internal/components/cleanup/` | Kind & Compose cleanup implementations | |
| 125 | +| `internal/util/` | K8s client, Docker helpers, env/log utils | |
| 126 | +| `internal/constant/` | Constants for both modes and cleanup | |
| 127 | +| `internal/logger/` | Logrus-based logging | |
| 128 | +| `pkg/output/` | Test result formatting (YAML/summary) | |
| 129 | +| `third-party/go/template/` | Extended Go template functions for verify | |
| 130 | + |
| 131 | +### Test Structure |
| 132 | + |
| 133 | +**Unit tests** (6 files): |
| 134 | +- `internal/config/e2eConfig_test.go` |
| 135 | +- `internal/util/config_test.go`, `utils_test.go` |
| 136 | +- `commands/verify/verify_test.go` |
| 137 | +- `internal/components/verifier/verifier_test.go` |
| 138 | +- `third-party/go/template/funcs_test.go` |
| 139 | + |
| 140 | +**E2E tests** (`test/e2e/`): |
| 141 | +- `e2e.yaml` — Compose-based e2e test |
| 142 | +- `kind/e2e.yaml` — Kind-based e2e test |
| 143 | +- Verify scenarios under `concurrency/` and `non-concurrency/` dirs |
| 144 | + |
| 145 | +### Log Collection |
| 146 | + |
| 147 | +- Logs streamed during setup to `LogDir/namespace/podName.log` (Kind) or `LogDir/serviceName/std.log` (Compose) |
| 148 | +- `internal/util/env_log.go` — `ResourceLogFollower` manages log writers |
| 149 | +- GitHub Actions: log dir defaults to `${runner.temp}/skywalking-infra-e2e/logs` |
| 150 | +- **No existing mechanism to copy arbitrary files from containers on failure** |
| 151 | + |
| 152 | +### GitHub Actions Integration |
| 153 | + |
| 154 | +- `action.yaml` at project root defines the composite action |
| 155 | +- Inputs: e2e-file, log-dir, plus matrix vars for log isolation |
0 commit comments