|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Common Development Commands |
| 6 | + |
| 7 | +### Building |
| 8 | +```bash |
| 9 | +# Build the Go binary |
| 10 | +make build |
| 11 | + |
| 12 | +# Build UI and binary |
| 13 | +make all |
| 14 | + |
| 15 | +# Build UI only |
| 16 | +make ui |
| 17 | + |
| 18 | +# Build Docker image |
| 19 | +make docker-build |
| 20 | +``` |
| 21 | + |
| 22 | +### Testing |
| 23 | +```bash |
| 24 | +# Run all tests with coverage |
| 25 | +make test |
| 26 | + |
| 27 | +# Run specific test |
| 28 | +go test -v ./path/to/package -run TestName |
| 29 | +``` |
| 30 | + |
| 31 | +### Linting and Formatting |
| 32 | +```bash |
| 33 | +# Run linters (fmt + vet) |
| 34 | +make lint |
| 35 | + |
| 36 | +# Format code |
| 37 | +make fmt |
| 38 | + |
| 39 | +# Run go vet |
| 40 | +make vet |
| 41 | + |
| 42 | +# Run golangci-lint |
| 43 | +golangci-lint run ./... |
| 44 | +``` |
| 45 | + |
| 46 | +### UI Development |
| 47 | +```bash |
| 48 | +# Install UI dependencies |
| 49 | +make install |
| 50 | + |
| 51 | +# Build UI |
| 52 | +cd ui && npm run build |
| 53 | + |
| 54 | +# Run UI in development mode |
| 55 | +cd ui && npm start |
| 56 | +``` |
| 57 | + |
| 58 | +### Kubernetes/OpenShift Examples |
| 59 | +```bash |
| 60 | +# Generate Kubernetes manifests |
| 61 | +make examples/kubernetes/manifests |
| 62 | + |
| 63 | +# Generate webhook-enabled manifests |
| 64 | +make examples/kubernetes/manifests-webhook |
| 65 | + |
| 66 | +# Generate OpenShift manifests |
| 67 | +make examples/openshift/manifests |
| 68 | +``` |
| 69 | + |
| 70 | +## High-Level Architecture |
| 71 | + |
| 72 | +### Core Components |
| 73 | + |
| 74 | +1. **API Server** (`pyrra api`) - Serves the web UI and provides REST/gRPC APIs for SLO management |
| 75 | + - Runs on port 9099 by default |
| 76 | + - Connects to Prometheus for metrics queries |
| 77 | + - Uses connect-go for protobuf-based APIs |
| 78 | + |
| 79 | +2. **Operators/Backends** - Watch for SLO configurations and generate Prometheus recording rules |
| 80 | + - **Kubernetes Operator** (`pyrra kubernetes`) - Watches ServiceLevelObjective CRDs and creates PrometheusRule resources |
| 81 | + - **Filesystem Operator** (`pyrra filesystem`) - Reads SLO configs from files and writes Prometheus rules to disk |
| 82 | + |
| 83 | +3. **Web UI** - React/TypeScript application for visualizing SLOs, error budgets, and burn rates |
| 84 | + - Located in `ui/` directory |
| 85 | + - Uses connect-web for API communication |
| 86 | + - Built with uPlot for charts |
| 87 | + |
| 88 | +### Key Concepts |
| 89 | + |
| 90 | +- **ServiceLevelObjective (SLO)** - Core CRD/config defining target availability, time window, and indicator metrics |
| 91 | +- **Multi-Window Multi-Burn-Rate Alerts** - Generates alerts at different severities based on error budget burn rates |
| 92 | +- **Recording Rules** - Prometheus rules generated for efficient SLO calculations (burnrates, increase windows) |
| 93 | + |
| 94 | +### Code Organization |
| 95 | + |
| 96 | +- `main.go` - CLI entry point with subcommands (api, kubernetes, filesystem, generate) |
| 97 | +- `kubernetes/` - Kubernetes operator implementation and CRD types |
| 98 | +- `slo/` - Core SLO logic, PromQL generation, and rule creation |
| 99 | +- `proto/` - Protocol buffer definitions for APIs |
| 100 | +- `ui/` - React frontend application |
| 101 | +- `examples/` - Deployment examples for various environments |
| 102 | +- `jsonnet/` - Jsonnet libraries for Kubernetes manifest generation |
| 103 | + |
| 104 | +### Protobuf/gRPC APIs |
| 105 | + |
| 106 | +The project uses connect-go/connect-web for type-safe API communication: |
| 107 | +- API definitions in `proto/` |
| 108 | +- Generated Go code in `proto/*/v1alpha1/` |
| 109 | +- Generated TypeScript code in `ui/src/proto/` |
| 110 | + |
| 111 | +### Testing Approach |
| 112 | + |
| 113 | +- Unit tests alongside source files (*_test.go) |
| 114 | +- Table-driven tests for complex logic (e.g., `slo/rules_test.go`) |
| 115 | +- No integration test framework - tests are standard Go tests |
| 116 | + |
| 117 | +When modifying protobuf definitions, regenerate code with appropriate buf commands. |
0 commit comments