-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
669 lines (579 loc) · 26.9 KB
/
Makefile
File metadata and controls
669 lines (579 loc) · 26.9 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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
.PHONY: help setup up down restart logs clean test test-event build run dev start start-local
# Colors for output
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m # No Color
# Default target
.DEFAULT_GOAL := help
help: ## Show this help message
@echo "$(BLUE)IngestKit - Development Commands$(NC)"
@echo ""
@echo "$(GREEN)Available commands:$(NC)"
@awk 'BEGIN {FS = ":.*##"; printf ""} /^[a-zA-Z_-]+:.*?##/ { printf " $(YELLOW)%-20s$(NC) %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
@echo ""
# =============================================================================
# Quick Start Commands
# =============================================================================
start: docker-build docker-up ## ⚡ ONE COMMAND START - Build and run everything with Docker
@echo ""
@echo "$(GREEN)═══════════════════════════════════════════════════$(NC)"
@echo "$(GREEN) ✓ IngestKit is running!$(NC)"
@echo "$(GREEN)═══════════════════════════════════════════════════$(NC)"
@echo ""
@echo "$(BLUE)Next steps:$(NC)"
@echo " 1. Edit your schema: $(YELLOW)vim schema/events.yaml$(NC)"
@echo " 2. Apply changes: $(YELLOW)make docker-reload$(NC)"
@echo " 3. Send test event: $(YELLOW)make test-event$(NC)"
@echo ""
@echo "$(BLUE)Useful commands:$(NC)"
@echo " • $(YELLOW)make docker-logs$(NC) - View logs"
@echo " • $(YELLOW)make metrics$(NC) - View consumer metrics"
@echo " • $(YELLOW)make down$(NC) - Stop everything"
@echo ""
start-local: quickstart init-go generate build db-migrate-up ## ⚡ Start everything locally (not Docker)
@echo ""
@echo "$(GREEN)═══════════════════════════════════════════════════$(NC)"
@echo "$(GREEN) ✓ Infrastructure ready!$(NC)"
@echo "$(GREEN)═══════════════════════════════════════════════════$(NC)"
@echo ""
@echo "$(BLUE)Start services in separate terminals:$(NC)"
@echo " Terminal 1: $(YELLOW)make run-api$(NC)"
@echo " Terminal 2: $(YELLOW)make run-consumer$(NC)"
@echo ""
@echo "$(BLUE)After services start:$(NC)"
@echo " • Edit schema: $(YELLOW)vim schema/events.yaml$(NC)"
@echo " • Regenerate: $(YELLOW)make generate && make build$(NC)"
@echo " • Restart services (Ctrl+C and re-run make run-api/run-consumer)"
@echo ""
# =============================================================================
# Environment Setup
# =============================================================================
setup: ## Initial setup - create .env file and initialize project
@echo "$(BLUE)Setting up IngestKit development environment...$(NC)"
@if [ ! -f .env ]; then \
cp .env.example .env; \
echo "$(GREEN)Created .env file from .env.example$(NC)"; \
else \
echo "$(YELLOW).env file already exists$(NC)"; \
fi
@mkdir -p init-db generated/sql generated/models generated/sdks
@echo "$(GREEN)Setup complete!$(NC)"
check-env: ## Check if .env file exists
@if [ ! -f .env ]; then \
echo "$(RED)Error: .env file not found. Run 'make setup' first.$(NC)"; \
exit 1; \
fi
# =============================================================================
# Docker Compose - Infrastructure
# =============================================================================
up: check-env ## Start all services (postgres + redpanda)
@echo "$(BLUE)Starting IngestKit services...$(NC)"
docker compose up -d postgres redpanda redpanda-console
@echo "$(GREEN)Services started!$(NC)"
@echo "$(YELLOW)PostgreSQL:$(NC) localhost:5432"
@echo "$(YELLOW)Redpanda (Kafka):$(NC) localhost:19092"
@echo "$(YELLOW)Redpanda Console:$(NC) http://localhost:8090"
up-full: check-env ## Start all services including Redis and pgAdmin
@echo "$(BLUE)Starting all IngestKit services (full stack)...$(NC)"
docker compose --profile full up -d
@echo "$(GREEN)All services started!$(NC)"
@echo "$(YELLOW)PostgreSQL:$(NC) localhost:5432"
@echo "$(YELLOW)Redpanda (Kafka):$(NC) localhost:19092"
@echo "$(YELLOW)Redpanda Console:$(NC) http://localhost:8090"
@echo "$(YELLOW)Redis:$(NC) localhost:6379"
@echo "$(YELLOW)pgAdmin:$(NC) http://localhost:5050"
down: ## Stop all services
@echo "$(BLUE)Stopping all services...$(NC)"
docker compose --profile full down
@echo "$(GREEN)Services stopped!$(NC)"
restart: down up ## Restart all services
logs: ## Tail logs from all services
docker compose logs -f
logs-postgres: ## Tail PostgreSQL logs
docker compose logs -f postgres
logs-redpanda: ## Tail Redpanda logs
docker compose logs -f redpanda
# =============================================================================
# Database Operations
# =============================================================================
db-connect: ## Connect to PostgreSQL with psql
@echo "$(BLUE)Connecting to PostgreSQL...$(NC)"
docker compose exec postgres psql -U ingestkit -d ingestkit
db-create: ## Create database schema
@echo "$(BLUE)Creating database schema...$(NC)"
@if [ -f generated/sql/schema.sql ]; then \
docker compose exec -T postgres psql -U ingestkit -d ingestkit < generated/sql/schema.sql; \
echo "$(GREEN)Schema created!$(NC)"; \
else \
echo "$(RED)No schema.sql found. Run 'make generate' first.$(NC)"; \
fi
db-drop: ## Drop all tables (DANGEROUS)
@echo "$(RED)WARNING: This will drop all tables!$(NC)"
@read -p "Are you sure? [y/N] " -n 1 -r; \
echo; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
docker compose exec postgres psql -U ingestkit -d ingestkit -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"; \
echo "$(GREEN)Database reset!$(NC)"; \
fi
db-reset: db-drop db-create ## Drop and recreate database
db-migrate-up: ## Run database migrations
@echo "$(BLUE)Running migrations...$(NC)"
@. .env 2>/dev/null || true; \
migrate -path migrations -database "postgres://$$POSTGRES_USER:$$POSTGRES_PASSWORD@localhost:$$POSTGRES_PORT/$$POSTGRES_DB?sslmode=disable" up
@echo "$(GREEN)Migrations applied!$(NC)"
db-migrate-down: ## Rollback one migration
@echo "$(BLUE)Rolling back migration...$(NC)"
@. .env 2>/dev/null || true; \
migrate -path migrations -database "postgres://$$POSTGRES_USER:$$POSTGRES_PASSWORD@localhost:$$POSTGRES_PORT/$$POSTGRES_DB?sslmode=disable" down 1
@echo "$(GREEN)Migration rolled back!$(NC)"
db-migrate-create: ## Create a new migration (usage: make db-migrate-create NAME=add_user_field)
@if [ -z "$(NAME)" ]; then \
echo "$(RED)Error: NAME is required$(NC)"; \
echo "Usage: make db-migrate-create NAME=add_user_field"; \
exit 1; \
fi
@echo "$(BLUE)Creating migration: $(NAME)$(NC)"
@migrate create -ext sql -dir migrations -seq $(NAME)
@echo "$(GREEN)Migration files created!$(NC)"
@echo "$(YELLOW)Edit the migration files in migrations/ directory$(NC)"
db-migrate-force: ## Force migration version without running (usage: make db-migrate-force VERSION=1)
@if [ -z "$(VERSION)" ]; then \
echo "$(RED)Error: VERSION is required$(NC)"; \
echo "Usage: make db-migrate-force VERSION=1"; \
exit 1; \
fi
@echo "$(BLUE)Forcing migration version $(VERSION)...$(NC)"
@. .env 2>/dev/null || true; \
migrate -path migrations -database "postgres://$$POSTGRES_USER:$$POSTGRES_PASSWORD@localhost:$$POSTGRES_PORT/$$POSTGRES_DB?sslmode=disable" force $(VERSION)
@echo "$(GREEN)Migration version set to $(VERSION)!$(NC)"
db-migrate-version: ## Show current migration version
@echo "$(BLUE)Current migration version:$(NC)"
@. .env 2>/dev/null || true; \
migrate -path migrations -database "postgres://$$POSTGRES_USER:$$POSTGRES_PASSWORD@localhost:$$POSTGRES_PORT/$$POSTGRES_DB?sslmode=disable" version
migrate-auto: ## Auto-generate migration from schema changes (usage: make migrate-auto NAME=add_field)
@if [ -z "$(NAME)" ]; then \
echo "$(RED)Error: NAME is required$(NC)"; \
echo "Usage: make migrate-auto NAME=add_user_field"; \
exit 1; \
fi
@echo "$(BLUE)Auto-generating migration: $(NAME)$(NC)"
@echo ""
@echo "$(YELLOW)Step 1/3: Regenerating code from schema...$(NC)"
@$(MAKE) generate > /dev/null
@echo "$(GREEN)✓ Code generated$(NC)"
@echo ""
@echo "$(YELLOW)Step 2/3: Computing schema diff...$(NC)"
@atlas migrate diff $(NAME) \
--env local \
--dev-url "docker://postgres/18/dev" \
|| (echo "$(RED)Atlas migration failed. Check schema syntax.$(NC)" && exit 1)
@echo "$(GREEN)✓ Migration generated$(NC)"
@echo ""
@echo "$(YELLOW)Step 3/3: Review migration files:$(NC)"
@ls -lh migrations/*$(NAME)* | awk '{print " " $$9 " (" $$5 ")"}'
@echo ""
@echo "$(GREEN)✓ Migration ready!$(NC)"
@echo ""
@echo "$(YELLOW)Next steps:$(NC)"
@echo " 1. Review migration files in migrations/ directory"
@echo " 2. Test: $(BLUE)make db-migrate-up$(NC)"
@echo " 3. Verify: Send test events"
@echo " 4. Rollback if needed: $(BLUE)make db-migrate-down$(NC)"
@echo " 5. Deploy: $(BLUE)make docker-reload$(NC)"
@echo ""
db-migrate: db-migrate-up ## Alias for db-migrate-up
# =============================================================================
# Redpanda Operations
# =============================================================================
redpanda-topics: ## List Redpanda topics
docker compose exec redpanda rpk topic list
redpanda-create-topic: ## Create ingestkit.events topic
@echo "$(BLUE)Creating topic: ingestkit.events$(NC)"
docker compose exec redpanda rpk topic create ingestkit.events -p 3 -r 1
@echo "$(GREEN)Topic created!$(NC)"
redpanda-consume: ## Consume messages from ingestkit.events topic
docker compose exec redpanda rpk topic consume ingestkit.events --format '%v\n'
redpanda-info: ## Show Redpanda cluster info
docker compose exec redpanda rpk cluster info
# =============================================================================
# Application Development
# =============================================================================
build: ## Build Go applications
@echo "$(BLUE)Building IngestKit...$(NC)"
@if [ -f go.mod ]; then \
go build -o bin/ingestkit ./cmd/cli; \
go build -o bin/api ./cmd/api; \
go build -o bin/consumer ./cmd/consumer; \
echo "$(GREEN)Build complete!$(NC)"; \
else \
echo "$(RED)No go.mod found. Initialize Go project first.$(NC)"; \
fi
run-api: ## Run API server locally
@echo "$(BLUE)Starting API server...$(NC)"
@if [ -f bin/api ]; then \
set -a && [ -f .env ] && . ./.env && set +a && ./bin/api; \
else \
echo "$(RED)Binary not found. Run 'make build' first.$(NC)"; \
fi
run-consumer: ## Run consumer worker locally
@echo "$(BLUE)Starting consumer worker...$(NC)"
@if [ -f bin/consumer ]; then \
set -a && [ -f .env ] && . ./.env && set +a && ./bin/consumer; \
else \
echo "$(RED)Binary not found. Run 'make build' first.$(NC)"; \
fi
dev: up ## Start infrastructure and run in dev mode
@echo "$(GREEN)Infrastructure is running. Ready for development!$(NC)"
# =============================================================================
# Code Generation
# =============================================================================
generate: ## Generate code from schema
@echo "$(BLUE)Generating code from schema...$(NC)"
@if [ -f bin/ingestkit ]; then \
./bin/ingestkit schema compile; \
else \
echo "$(YELLOW)Building CLI tool...$(NC)"; \
go build -o bin/ingestkit ./cmd/cli; \
./bin/ingestkit schema compile; \
fi
schema-apply: ## Apply schema changes (generate + build + migrations)
@echo "$(BLUE)Applying schema changes...$(NC)"
@echo ""
@echo "$(YELLOW)Step 1/3: Generating code from schema...$(NC)"
@$(MAKE) generate
@echo ""
@echo "$(YELLOW)Step 2/3: Building binaries...$(NC)"
@$(MAKE) build
@echo ""
@echo "$(YELLOW)Step 3/3: Applying database migrations...$(NC)"
@$(MAKE) db-migrate-up
@echo ""
@echo "$(GREEN)✓ Schema changes applied successfully!$(NC)"
@echo ""
@echo "$(YELLOW)⚠️ Next steps:$(NC)"
@echo " 1. If you added/removed fields, create a migration:"
@echo " $(BLUE)make db-migrate-create NAME=add_field_name$(NC)"
@echo " 2. Edit the migration files in migrations/ directory"
@echo " 3. Apply migrations: $(BLUE)make db-migrate-up$(NC)"
@echo " 4. For Docker deployment: $(BLUE)make docker-reload$(NC)"
@echo ""
# =============================================================================
# Testing
# =============================================================================
test: ## Run unit tests
@echo "$(BLUE)Running tests...$(NC)"
@if [ -f go.mod ]; then \
go test ./... -v; \
else \
echo "$(YELLOW)No Go project initialized yet$(NC)"; \
fi
test-event: ## Send a test user_signup event (quick verification)
@echo "$(BLUE)Sending test event...$(NC)"
@curl -X POST http://localhost:8080/v1/events/user_signup \
-H "Authorization: Bearer dev_key_1234567890" \
-H "Content-Type: application/json" \
-d '{"user_id":"test_'$$(date +%s)'","email":"test@example.com","signup_source":"web"}' \
&& echo "" \
&& echo "$(GREEN)✓ Event sent successfully!$(NC)" \
&& echo "$(YELLOW)Check: make metrics$(NC)" \
|| echo "$(RED)✗ Failed. Is API running?$(NC)"
test-integration: up ## Run integration tests
@echo "$(BLUE)Running integration tests...$(NC)"
@echo "$(YELLOW)Integration tests not implemented yet$(NC)"
# =============================================================================
# Load Testing (k6)
# =============================================================================
loadtest: loadtest-baseline ## Run default load test (baseline scenario)
loadtest-quick: ## Quick validation test - 100 RPS for 10s
@echo "$(BLUE)Running quick load test with k6...$(NC)"
@if ! command -v k6 > /dev/null; then \
echo "$(RED)k6 not installed. Install with: brew install k6$(NC)"; \
exit 1; \
fi
k6 run loadtest/quick.js
loadtest-baseline: ## Baseline test - 500 RPS for 30s
@echo "$(BLUE)Running baseline load test with k6...$(NC)"
@if ! command -v k6 > /dev/null; then \
echo "$(RED)k6 not installed. Install with: brew install k6$(NC)"; \
exit 1; \
fi
k6 run loadtest/baseline.js
loadtest-production: ## Production simulation - 1000 RPS for 1 min
@echo "$(BLUE)Running production load test with k6...$(NC)"
@if ! command -v k6 > /dev/null; then \
echo "$(RED)k6 not installed. Install with: brew install k6$(NC)"; \
exit 1; \
fi
k6 run loadtest/production.js
loadtest-batch: ## Batch test - 100 RPS with 10 events/batch
@echo "$(BLUE)Running batch load test with k6...$(NC)"
@if ! command -v k6 > /dev/null; then \
echo "$(RED)k6 not installed. Install with: brew install k6$(NC)"; \
exit 1; \
fi
k6 run loadtest/batch.js
loadtest-high: ## High throughput - 5000 RPS for 30s (requires RATE_LIMIT_RPS=10000)
@echo "$(BLUE)Running high throughput load test with k6...$(NC)"
@echo "$(YELLOW)Note: Ensure RATE_LIMIT_RPS is set to 10000 or higher$(NC)"
@if ! command -v k6 > /dev/null; then \
echo "$(RED)k6 not installed. Install with: brew install k6$(NC)"; \
exit 1; \
fi
k6 run loadtest/high-throughput.js
loadtest-custom: ## Custom load test - set API_URL, API_KEY env vars
@echo "$(BLUE)Running custom load test with k6...$(NC)"
@SCRIPT=$${SCRIPT:-loadtest/baseline.js}; \
echo "Using script: $$SCRIPT"; \
k6 run $$SCRIPT
# =============================================================================
# Load Testing - Optimized Stack
# =============================================================================
tune-system: ## Run system tuning script for load testing
@echo "$(BLUE)Running system tuning...$(NC)"
@if [ -f scripts/tune-system.sh ]; then \
./scripts/tune-system.sh; \
else \
echo "$(RED)scripts/tune-system.sh not found$(NC)"; \
exit 1; \
fi
loadtest-start: ## Start optimized stack for load testing
@echo "$(BLUE)Starting optimized IngestKit stack for load testing...$(NC)"
@echo ""
@if [ ! -f .env.loadtest ]; then \
echo "$(RED)Error: .env.loadtest not found$(NC)"; \
echo "Run: cp .env.loadtest.example .env.loadtest"; \
exit 1; \
fi
@echo "$(YELLOW)Step 1/3: Copying load test configuration...$(NC)"
@cp .env.loadtest .env
@echo "$(GREEN)✓ Using .env.loadtest configuration$(NC)"
@echo ""
@echo "$(YELLOW)Step 2/3: Building optimized Docker images...$(NC)"
@docker compose -f docker-compose.yml -f docker-compose.loadtest.yml build api consumer
@echo "$(GREEN)✓ Images built$(NC)"
@echo ""
@echo "$(YELLOW)Step 3/3: Starting full stack...$(NC)"
@docker compose -f docker-compose.yml -f docker-compose.loadtest.yml up -d
@echo "$(GREEN)✓ Stack started$(NC)"
@echo ""
@echo "$(BLUE)═══════════════════════════════════════════════════$(NC)"
@echo "$(GREEN) Load Testing Stack Ready!$(NC)"
@echo "$(BLUE)═══════════════════════════════════════════════════$(NC)"
@echo ""
@echo "$(YELLOW)⏳ Wait 60 seconds for services to warm up...$(NC)"
@echo ""
@echo "$(YELLOW)Service URLs:$(NC)"
@echo " API (2 replicas): http://localhost:8080/health"
@echo " Consumer (2 replicas): http://localhost:8081/metrics"
@echo " PostgreSQL: localhost:5433"
@echo " Redpanda Console: http://localhost:8090"
@echo ""
@echo "$(YELLOW)Next steps:$(NC)"
@echo " 1. Wait 60s: $(BLUE)sleep 60$(NC)"
@echo " 2. Run test: $(BLUE)make loadtest-high$(NC) (10,000 RPS)"
@echo " 3. Monitor: $(BLUE)make metrics-watch$(NC)"
@echo " 4. Stop: $(BLUE)make loadtest-stop$(NC)"
@echo ""
loadtest-stop: ## Stop optimized load testing stack
@echo "$(BLUE)Stopping load testing stack...$(NC)"
@docker compose -f docker-compose.yml -f docker-compose.loadtest.yml down
@echo "$(GREEN)Stack stopped!$(NC)"
@echo ""
@echo "$(YELLOW)Restore normal .env:$(NC)"
@echo " git checkout .env"
@echo ""
loadtest-restart: loadtest-stop loadtest-start ## Restart load testing stack
loadtest-logs: ## View logs from load testing stack
@docker compose -f docker-compose.yml -f docker-compose.loadtest.yml logs -f api consumer
loadtest-stats: ## Show load testing statistics
@echo "$(BLUE)Load Testing Statistics$(NC)"
@echo ""
@echo "$(YELLOW)Container Resource Usage:$(NC)"
@docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}" | grep ingestkit
@echo ""
@echo "$(YELLOW)Service Status:$(NC)"
@docker compose -f docker-compose.yml -f docker-compose.loadtest.yml ps
@echo ""
@echo "$(YELLOW)Consumer Metrics:$(NC)"
@curl -s http://localhost:8081/metrics | grep -E "^ingestkit_" | head -20 || echo "Metrics not available"
@echo ""
loadtest-monitor: ## Real-time monitoring during load test (requires tmux)
@if ! command -v tmux > /dev/null; then \
echo "$(RED)tmux not installed. Install with: brew install tmux$(NC)"; \
exit 1; \
fi
@tmux new-session -d -s ingestkit-loadtest
@tmux split-window -h
@tmux split-window -v
@tmux select-pane -t 0
@tmux send-keys 'watch -n 2 "docker stats --no-stream | grep ingestkit"' C-m
@tmux select-pane -t 1
@tmux send-keys 'watch -n 2 "curl -s http://localhost:8081/metrics | grep -E \"^ingestkit_\""' C-m
@tmux select-pane -t 2
@tmux send-keys 'docker compose -f docker-compose.yml -f docker-compose.loadtest.yml logs -f api consumer' C-m
@tmux attach-session -t ingestkit-loadtest
# =============================================================================
# Utilities
# =============================================================================
metrics: ## Check consumer metrics endpoint
@echo "$(BLUE)Consumer Metrics:$(NC)"
@curl -s http://localhost:8081/metrics | grep -E "^(ingestkit_|# )" || echo "$(RED)Metrics endpoint not available$(NC)"
metrics-health: ## Check consumer health endpoint
@echo "$(BLUE)Consumer Health:$(NC)"
@curl -s http://localhost:8081/health | jq . || echo "$(RED)Health endpoint not available$(NC)"
metrics-watch: ## Watch consumer metrics in real-time (requires watch command)
@echo "$(BLUE)Watching consumer metrics (Ctrl+C to stop)...$(NC)"
@watch -n 2 'curl -s http://localhost:8081/metrics | grep -E "^ingestkit_" | grep -v "# "'
db-stats: ## Show database statistics (table sizes, row counts)
@echo "$(BLUE)Database Statistics:$(NC)"
@docker compose exec -T postgres psql -U ingestkit -d ingestkit -c "\
SELECT \
schemaname, \
tablename, \
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS size, \
n_live_tup AS rows \
FROM pg_stat_user_tables \
WHERE schemaname NOT IN ('pg_catalog', 'information_schema') \
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;"
db-event-counts: ## Show event counts by type
@echo "$(BLUE)Event Counts:$(NC)"
@docker compose exec -T postgres psql -U ingestkit -d ingestkit -c "\
SELECT 'user_signup' as event_type, COUNT(*) as count FROM events_user_signup \
UNION ALL \
SELECT 'purchase', COUNT(*) FROM events_purchase \
UNION ALL \
SELECT 'page_view', COUNT(*) FROM events_page_view \
ORDER BY count DESC;"
db-dlq-check: ## Check dead letter queue
@echo "$(BLUE)Dead Letter Queue:$(NC)"
@docker compose exec -T postgres psql -U ingestkit -d ingestkit -c "\
SELECT \
event_type, \
COUNT(*) as count, \
MAX(created_at) as latest_failure \
FROM ingestkit_meta.dead_letter_queue \
GROUP BY event_type;"
clean: down ## Clean up containers, volumes, and build artifacts
@echo "$(BLUE)Cleaning up...$(NC)"
docker compose --profile full down -v
rm -rf bin/ generated/
@echo "$(GREEN)Cleanup complete!$(NC)"
status: ## Show status of all services
@echo "$(BLUE)Service Status:$(NC)"
@docker compose ps
health: ## Check health of all services
@echo "$(BLUE)Health Check:$(NC)"
@echo -n "$(YELLOW)PostgreSQL:$(NC) "
@docker compose exec -T postgres pg_isready -U ingestkit && echo "$(GREEN)✓$(NC)" || echo "$(RED)✗$(NC)"
@echo -n "$(YELLOW)Redpanda:$(NC) "
@docker compose exec -T redpanda rpk cluster health > /dev/null 2>&1 && echo "$(GREEN)✓$(NC)" || echo "$(RED)✗$(NC)"
fmt: ## Format Go code
@if [ -f go.mod ]; then \
go fmt ./...; \
echo "$(GREEN)Code formatted!$(NC)"; \
fi
lint: ## Lint Go code
@if [ -f go.mod ]; then \
if command -v golangci-lint > /dev/null; then \
golangci-lint run ./...; \
else \
echo "$(YELLOW)golangci-lint not installed. Run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest$(NC)"; \
fi; \
fi
# =============================================================================
# Project Initialization
# =============================================================================
init-go: setup ## Initialize Go project
@echo "$(BLUE)Initializing Go project...$(NC)"
@if [ ! -f go.mod ]; then \
go mod init github.com/feat7/ingestkit; \
go get github.com/gofiber/fiber/v2; \
go get github.com/twmb/franz-go/pkg/kgo; \
go get github.com/lib/pq; \
go get gopkg.in/yaml.v3; \
mkdir -p cmd/api cmd/consumer cmd/cli internal pkg; \
echo "$(GREEN)Go project initialized!$(NC)"; \
else \
echo "$(YELLOW)go.mod already exists$(NC)"; \
fi
# =============================================================================
# Quick Start
# =============================================================================
quickstart: setup up redpanda-create-topic ## Complete setup and start infrastructure
@echo ""
@echo "$(GREEN)═══════════════════════════════════════════════════$(NC)"
@echo "$(GREEN) IngestKit is ready for development!$(NC)"
@echo "$(GREEN)═══════════════════════════════════════════════════$(NC)"
@echo ""
@echo "$(YELLOW)Services running:$(NC)"
@echo " • PostgreSQL: localhost:5432"
@echo " • Redpanda: localhost:19092"
@echo " • Redpanda Console: http://localhost:8090"
@echo ""
@echo "$(YELLOW)Next steps:$(NC)"
@echo " 1. Run 'make init-go' to initialize Go project"
@echo " 2. Define schemas in schema/events.yaml"
@echo " 3. Run 'make generate' to generate code"
@echo " 4. Run 'make build' to build applications"
@echo " 5. Run 'make run-api' to start the API server"
@echo ""
@echo "$(YELLOW)Useful commands:$(NC)"
@echo " • make logs - View all logs"
@echo " • make db-connect - Connect to PostgreSQL"
@echo " • make health - Check service health"
@echo " • make help - Show all commands"
@echo ""
# =============================================================================
# Docker - Application Deployment
# =============================================================================
docker-build: ## Build Docker images for API and consumer
@echo "$(BLUE)Building Docker images...$(NC)"
docker compose build api consumer
@echo "$(GREEN)Docker images built!$(NC)"
docker-up: ## Start full stack including API and consumer
@echo "$(BLUE)Starting full IngestKit stack (infrastructure + services)...$(NC)"
@docker compose up -d || (echo "$(RED)Failed to start services. Check logs with: docker compose logs$(NC)" && exit 1)
@echo "$(GREEN)Full stack started!$(NC)"
@echo "$(YELLOW)API:$(NC) http://localhost:8080"
@echo "$(YELLOW)Consumer Metrics:$(NC) http://localhost:8081/metrics"
@echo "$(YELLOW)PostgreSQL:$(NC) localhost:5433"
@echo "$(YELLOW)Redpanda:$(NC) localhost:19092"
@echo "$(YELLOW)Redpanda Console:$(NC) http://localhost:8090"
docker-reload: schema-apply docker-build ## Zero-downtime reload after schema changes
@echo "$(BLUE)Performing zero-downtime rolling update...$(NC)"
@echo ""
@echo "$(YELLOW)Step 1/2: Reloading API server...$(NC)"
@docker compose up -d --no-deps --build api
@echo "$(GREEN)✓ API server reloaded$(NC)"
@echo ""
@echo "$(YELLOW)Step 2/2: Reloading consumer...$(NC)"
@docker compose up -d --no-deps --build consumer
@echo "$(GREEN)✓ Consumer reloaded$(NC)"
@echo ""
@echo "$(GREEN)✓ Zero-downtime reload complete!$(NC)"
@echo "$(YELLOW)Services are running with new schema$(NC)"
docker-logs: ## Tail logs from API and consumer
@docker compose logs -f api consumer
docker-logs-api: ## Tail API logs
@docker compose logs -f api
docker-logs-consumer: ## Tail consumer logs
@docker compose logs -f consumer
docker-down: ## Stop all Docker services
@echo "$(BLUE)Stopping all Docker services...$(NC)"
docker compose down
@echo "$(GREEN)All services stopped!$(NC)"
docker-restart: docker-down docker-up ## Restart all Docker services
docker-clean: ## Remove all containers, images, and volumes
@echo "$(RED)WARNING: This will remove all containers, images, and volumes!$(NC)"
@read -p "Are you sure? [y/N] " -n 1 -r; \
echo; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
docker compose down -v --rmi all; \
echo "$(GREEN)Cleanup complete!$(NC)"; \
fi
docker-clean-volumes: ## Remove database volumes (fixes migration errors)
@echo "$(BLUE)Removing database volumes...$(NC)"
docker compose down -v
@echo "$(GREEN)Volumes removed. Database will be recreated on next start.$(NC)"