-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
381 lines (339 loc) · 12.3 KB
/
Makefile
File metadata and controls
381 lines (339 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
.PHONY: help build build-ui build-mcp build-docs run test test-go test-ui test-e2e test-e2e-root-cause test-e2e-ui test-e2e-all clean clean-test-clusters docker-build docker-run deploy watch lint fmt vet favicons helm-lint helm-test helm-test-local helm-unittest helm-unittest-install proto dev-iterate dev-stop dev-logs graph-up graph-down startup-import-benchmark test-graph test-graph-integration test-integration test-graph-integration-coverage test-graph-integration-single golden-generator test-golden docs-dev docs-preview
# Default target
help:
@echo "Kubernetes Event Monitor - Available targets:"
@echo ""
@echo "Build:"
@echo " build - Build the application binary"
@echo " build-ui - Build the React UI"
@echo " build-mcp - Build the MCP server for Claude integration"
@echo " build-docs - Build the documentation site"
@echo " proto - Generate protobuf code"
@echo ""
@echo "Run:"
@echo " run - Run the application locally"
@echo ""
@echo "Test:"
@echo " test - Run all tests (Go + UI)"
@echo " test-go - Run Go tests only"
@echo " test-ui - Run UI tests only"
@echo " golden-generator - Build the golden fixture generator"
@echo " generate-golden-fixtures - Generate golden test fixtures from Kind cluster"
@echo " test-golden - Run golden fixture tests"
@echo " clean-test-clusters - Delete persistent test Kind clusters"
@echo " clean-golden-cluster - Delete golden test Kind cluster"
@echo ""
@echo "Graph Layer:"
@echo " graph-up - Start FalkorDB for development"
@echo " graph-down - Stop FalkorDB"
@echo " startup-import-benchmark - Run startup import benchmark harness"
@echo ""
@echo "Development:"
@echo " dev-iterate - Quick iteration: clean, build, restart all services locally"
@echo " dev-stop - Stop all development services"
@echo " dev-logs - Tail all development logs"
@echo ""
@echo "Code Quality:"
@echo " lint - Run linter (golangci-lint if available)"
@echo " fmt - Format code with gofmt"
@echo " vet - Run go vet"
@echo ""
@echo "Docker & Deployment:"
@echo " docker-build - Build Docker image"
@echo " docker-run - Run application in Docker"
@echo " deploy - Deploy to Kubernetes via Helm"
@echo ""
@echo "Helm:"
@echo " helm-lint - Lint Helm chart"
@echo " helm-unittest - Run Helm unit tests"
@echo " helm-unittest-install - Install helm-unittest plugin"
@echo " helm-test - Run Helm tests (requires active k8s cluster)"
@echo " helm-test-local - Create Kind cluster and run Helm tests locally"
@echo ""
@echo "Documentation:"
@echo " build-docs - Build the documentation site for production"
@echo " docs-dev - Run documentation dev server locally"
@echo " docs-preview - Preview production build locally"
@echo ""
@echo "Other:"
@echo " clean - Clean build artifacts and temporary files"
@echo " watch - Watch and rebuild on file changes (requires entr)"
@echo " favicons - Generate all favicon versions from favicon.svg"
# Variables
BINARY_NAME=spectre
BINARY_PATH=bin/$(BINARY_NAME)
IMAGE_NAME=spectre
IMAGE_TAG=latest
DOCKER_IMAGE=$(IMAGE_NAME):$(IMAGE_TAG)
CHART_PATH=./chart
NAMESPACE=monitoring
DATA_DIR=./data
DATA_LOCAL_DIR=./data-local
# Build the application
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p bin
@go build -o $(BINARY_PATH) ./cmd/spectre
@echo "Build complete: $(BINARY_PATH)"
# Build the React UI
build-ui:
@echo "Building React UI..."
@cd ui && npm ci && npm run build
@echo "UI build complete: ui/dist"
# Run the application locally
run: build build-ui
@echo "Running $(BINARY_NAME) server..."
@mkdir -p $(DATA_DIR)
@export KUBECONFIG=$(KUBECONFIG); \
$(BINARY_PATH) server
# Run Go tests only
test-go:
@echo "Running Go tests..."
script -q -e -c "go test -v -cover -count 1 -timeout 60m ./..." /dev/null
# Run UI tests only (unit tests + component tests)
test-ui:
@echo "Running UI unit tests..."
@cd ui && npm ci --prefer-offline --no-audit --no-fund 2>/dev/null && npm run test
@echo "Running UI component tests..."
@cd ui && npx playwright install chromium --with-deps && npm run test:ct
# Run all tests (Go + UI)
test: test-go test-ui
@echo "All tests completed successfully!"
# Clean up test Kind clusters
clean-test-clusters:
@echo "Cleaning up test Kind clusters..."
@kind delete cluster --name spectre-e2e-shared 2>/dev/null || true
@kind delete cluster --name spectre-ui-e2e-shared 2>/dev/null || true
@echo "✓ Test clusters cleaned up"
# Build golden fixture generator
golden-generator:
@echo "Building golden fixture generator..."
@go build ./tests/integration/golden/cmd/golden-generator/
@echo "✓ Golden fixture generator built (./golden-generator)"
# Generate golden test fixtures
generate-golden-fixtures:
@echo "Generating golden test fixtures..."
@./golden-generator --cluster spectre-golden --output tests/integration/fixtures/golden
@echo "✓ Golden fixtures generated"
# Run golden tests
test-golden:
@echo "Running golden tests..."
@go test -v -tags integration -timeout 30m ./tests/integration/api -run TestGoldenScenarios
@echo "✓ Golden tests completed"
# Clean up golden cluster
clean-golden-cluster:
@echo "Cleaning up golden cluster..."
@kind delete cluster --name spectre-golden 2>/dev/null || true
@echo "✓ Golden cluster cleaned up"
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -rf bin/
@rm -rf dist/
@rm -f coverage.out coverage.html
@rm -f *.test
@go clean
@echo "Clean complete"
# Format code
fmt:
@echo "Formatting code..."
@go fmt ./...
@echo "Format complete"
# Run go vet
vet:
@echo "Running go vet..."
@go vet ./...
@echo "Vet complete"
# Run linter (requires golangci-lint)
lint:
@echo "Running linter..."
@which golangci-lint > /dev/null || (echo "golangci-lint not installed, skipping" && exit 0)
@golangci-lint run ./... || true
@echo "Lint complete"
# Build Docker image
docker-build: build build-ui
@echo "Building Docker image $(DOCKER_IMAGE)..."
@docker build -t $(DOCKER_IMAGE) .
@echo "Docker image built: $(DOCKER_IMAGE)"
# Run in Docker
docker-run: docker-build
@echo "Running in Docker..."
@docker run --rm -p 8080:8080 -v $(shell pwd)/data:/data $(DOCKER_IMAGE)
# Deploy to Kubernetes via Helm
deploy:
@echo "Deploying to Kubernetes cluster..."
@kubectl create namespace $(NAMESPACE) --dry-run=client -o yaml | kubectl apply -f -
@helm upgrade --install spectre $(CHART_PATH) \
--namespace $(NAMESPACE) \
--create-namespace \
--values $(CHART_PATH)/values.yaml
@echo "Deployment complete. Check status:"
@kubectl get pods -n $(NAMESPACE)
# Watch and rebuild on file changes (requires entr)
watch:
@echo "Watching for changes (requires 'entr')..."
@find . -name "*.go" | entr make build
# Download dependencies
deps:
@echo "Downloading dependencies..."
@go mod download
@go mod tidy
@echo "Dependencies updated"
# Verify dependencies
deps-verify:
@echo "Verifying dependencies..."
@go mod verify
@echo "Dependencies verified"
# Generate protobuf code
proto:
@echo "Generating protobuf code..."
@protoc --go_out=. --go_opt=module=github.com/moolen/spectre internal/models/event.proto
@protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
--connect-go_out=. --connect-go_opt=paths=source_relative \
internal/api/proto/timeline.proto
@echo "Protobuf code generated successfully"
# Generate favicons from SVG source
favicons:
@echo "Generating favicons..."
@./hack/generate-favicons.sh
@echo "Favicons generated successfully"
# Install helm-unittest plugin
helm-unittest-install:
@echo "Installing helm-unittest plugin..."
@helm plugin list | grep -q unittest || helm plugin install https://github.com/helm-unittest/helm-unittest.git --version v1.0.2
@echo "helm-unittest plugin installed"
# Run helm unit tests
helm-unittest: helm-unittest-install
@echo "Running Helm unit tests..."
@helm unittest $(CHART_PATH) --color --output-type JUnit --output-file test-results.xml
@echo "Helm unit tests complete!"
# Stop development services
dev-stop:
@echo "==> Stopping all development services..."
@-pkill -f "$(BINARY_PATH) server" || true
@-pkill -f "$(BINARY_PATH) mcp" || true
@docker compose -f docker-compose.graph.yml down || true
@echo "All services stopped"
# ============================================================================
# Graph Layer Targets
# ============================================================================
# Start FalkorDB for development
graph-up:
@echo "Starting FalkorDB..."
@docker compose -f docker-compose.graph.yml up -d falkordb
@echo "Waiting for FalkorDB to be ready..."
@sleep 3
@echo "FalkorDB is running on localhost:6379"
# Stop FalkorDB
graph-down:
@echo "Stopping FalkorDB..."
@docker compose -f docker-compose.graph.yml down falkordb
@echo "FalkorDB stopped"
startup-import-benchmark:
@bash hack/benchmark-startup-import.sh
# ============================================================================
# Tail development logs
dev-logs:
@echo "==> Tailing development logs (Ctrl+C to exit)..."
@tail -f $(DATA_LOCAL_DIR)/logs/*.log
# Quick iteration for MCP/Spectre/FalkorDB development
dev-iterate: build
@echo "==> Stopping all services..."
-pkill -f "$(BINARY_PATH) server" || true
-pkill -f "$(BINARY_PATH) mcp" || true
docker compose -f docker-compose.graph.yml down falkordb || true
sleep 2
@echo ""
@echo "==> Cleaning local state..."
@echo ""
@echo "==> Building spectre binary..."
mkdir -p bin
go build -o $(BINARY_PATH) ./cmd/spectre
@echo ""
@echo "==> Starting FalkorDB..."
docker compose -f docker-compose.graph.yml up -d falkordb
@echo "Waiting for FalkorDB to be ready..."
sleep 3
@echo ""
@echo "==> Starting Spectre server..."
mkdir -p $(DATA_LOCAL_DIR)/logs
KUBECONFIG=$(KUBECONFIG) \
$(BINARY_PATH) server \
--log-level=debug \
--graph-enabled=true \
--graph-host=localhost \
--graph-port=6379 \
--watcher-config=hack/watcher.yaml \
> $(DATA_LOCAL_DIR)/logs/spectre.log 2>&1 &
@echo "Spectre server PID: $$!"
@echo "Waiting for Spectre server to be ready..."
@timeout=60; \
while [ $$timeout -gt 0 ]; do \
if nc -z localhost 8080 2>/dev/null; then \
if curl -sf http://localhost:8080/ready >/dev/null 2>&1; then \
echo "Spectre server is ready!"; \
break; \
fi; \
fi; \
sleep 1; \
timeout=$$((timeout - 1)); \
done; \
if [ $$timeout -eq 0 ]; then \
echo "ERROR: Spectre server did not become ready within 60 seconds"; \
exit 1; \
fi
@echo ""
@echo "==> Starting MCP server..."
$(BINARY_PATH) mcp \
--spectre-url=http://localhost:8080 \
--graph-enabled=true \
--log-level=debug \
--graph-host=localhost \
--graph-port=6379 \
--http-addr=:8082 \
> $(DATA_LOCAL_DIR)/logs/mcp.log 2>&1 &
@echo "MCP server PID: $$!"
@echo ""
@echo "==> All services started!"
@echo ""
@echo "Service URLs:"
@echo " - Spectre UI: http://localhost:8080"
@echo " - Spectre API: http://localhost:8080/api"
@echo " - MCP Server: http://localhost:8082"
@echo " - FalkorDB: localhost:6379"
@echo ""
@echo "Logs:"
@echo " - Spectre: $(DATA_LOCAL_DIR)/logs/spectre.log"
@echo " - MCP: $(DATA_LOCAL_DIR)/logs/mcp.log"
@echo " - FalkorDB: docker compose -f docker-compose.graph.yml logs -f"
@echo ""
@echo "To stop services:"
@echo " pkill -f '$(BINARY_PATH)' && docker compose -f docker-compose.graph.yml down"
@echo ""
@echo "To view logs:"
@echo " tail -f $(DATA_LOCAL_DIR)/logs/spectre.log"
@echo " tail -f $(DATA_LOCAL_DIR)/logs/mcp.log"
.PHONY: dev-clean
dev-clean:
@echo "==> Cleaning local state..."
rm -rf $(DATA_LOCAL_DIR)
mkdir -p $(DATA_LOCAL_DIR)
# ============================================================================
# Documentation Targets
# ============================================================================
# Build documentation site for production
build-docs:
@echo "Building documentation site..."
@cd docs && npm ci && npm run build
@echo "Documentation build complete: docs/dist"
# Run documentation dev server
docs-dev:
@echo "Starting documentation dev server..."
@cd docs && npm ci && npm run dev
# Preview production documentation build
docs-preview: build-docs
@echo "Starting documentation preview server..."
@cd docs && npm run preview
# Default target
.DEFAULT_GOAL := help