Add per-listener connection limits
Configurable maximum concurrent connections per listener. When the limit is reached, new connections are closed immediately after accept. 0 means unlimited (default, preserving existing behavior). Config: Listener gains max_connections field, validated non-negative. DB: Migration 3 adds listeners.max_connections column. UpdateListenerMaxConns method for runtime changes via gRPC. CreateListener updated to persist max_connections on seed. Server: ListenerState/ListenerData gain MaxConnections. Limit checked in serve() after Accept but before handleConn — if ActiveConnections >= MaxConnections, connection is closed and the accept loop continues. SetMaxConnections method for runtime updates. Proto: SetListenerMaxConnections RPC added. ListenerStatus gains max_connections field. Generated code regenerated. gRPC server: SetListenerMaxConnections implements write-through (DB first, then in-memory update). GetStatus includes max_connections. Client: SetListenerMaxConnections method, MaxConnections in ListenerStatus. Tests: DB CRUD and UpdateListenerMaxConns, server connection limit enforcement (accept 2, reject 3rd, close one, accept again), gRPC SetListenerMaxConnections round-trip with DB persistence, not-found error handling. Also updates PROJECT_PLAN.md with phases 6-8 and PROGRESS.md with tracking for the new features. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -329,3 +329,48 @@ Test that htmx-based web UIs work through the L7 proxy:
|
||||
- Verify ARCHITECTURE.md matches final implementation.
|
||||
- Update CLAUDE.md if any package structure or rules changed.
|
||||
- Update Makefile if new build targets are needed.
|
||||
|
||||
---
|
||||
|
||||
## Phase 6: Per-Listener Connection Limits
|
||||
|
||||
Add configurable maximum concurrent connection limits per listener.
|
||||
|
||||
### 6.1 Config: `MaxConnections int64` on `Listener` (0 = unlimited)
|
||||
### 6.2 DB: migration 3 adds `listeners.max_connections`, CRUD updates
|
||||
### 6.3 Server: enforce limit in `serve()` after Accept, before handleConn
|
||||
### 6.4 Proto/gRPC: `SetListenerMaxConnections` RPC, `max_connections` in `ListenerStatus`
|
||||
### 6.5 Client/CLI: `SetListenerMaxConnections` method, status display
|
||||
### 6.6 Tests: DB CRUD, server limit enforcement, gRPC round-trip
|
||||
|
||||
---
|
||||
|
||||
## Phase 7: L7 Policies
|
||||
|
||||
Per-route HTTP blocking rules for L7 routes: user-agent blocking
|
||||
(substring match) and required header enforcement.
|
||||
|
||||
### 7.1 Config: `L7Policy` struct (`type` + `value`), `L7Policies` on Route
|
||||
### 7.2 DB: migration 4 creates `l7_policies` table, new `l7policies.go` CRUD
|
||||
### 7.3 L7 middleware: `PolicyMiddleware` in `internal/l7/policy.go`
|
||||
### 7.4 Server/L7 integration: thread policies from RouteInfo to RouteConfig
|
||||
### 7.5 Proto/gRPC: `L7Policy` message, `ListL7Policies`/`AddL7Policy`/`RemoveL7Policy` RPCs
|
||||
### 7.6 Client/CLI: policy methods, `mcproxyctl policies` subcommand
|
||||
### 7.7 Startup: load L7 policies per route in `loadListenersFromDB`
|
||||
### 7.8 Tests: middleware unit tests, DB CRUD + cascade, gRPC round-trip, e2e
|
||||
|
||||
---
|
||||
|
||||
## Phase 8: Prometheus Metrics
|
||||
|
||||
Instrument the proxy with Prometheus-compatible metrics exposed via a
|
||||
separate HTTP endpoint.
|
||||
|
||||
### 8.1 Dependency: add `prometheus/client_golang`
|
||||
### 8.2 Config: `Metrics` section (`addr`, `path`)
|
||||
### 8.3 Package: `internal/metrics/` with metric definitions and HTTP server
|
||||
### 8.4 Instrumentation: connections, firewall blocks, dial latency, bytes, HTTP status codes, policy blocks
|
||||
### 8.5 Firewall: add `BlockedWithReason()` method
|
||||
### 8.6 L7: status recording wrapper on ResponseWriter
|
||||
### 8.7 Startup: conditionally start metrics server
|
||||
### 8.8 Tests: metric sanity, server endpoint, `BlockedWithReason`
|
||||
|
||||
Reference in New Issue
Block a user