Config new limits for higher concurrent users - #40
Merged
Conversation
Greptile SummaryThis PR adds configurable per-tenant realtime connection envelopes and raises the compiled limits for higher service tiers.
|
| Filename | Overview |
|---|---|
| internal/realtime/server.go | Realtime admission now consumes the connection envelope resolved with the API key, while retaining explicit environment-limit precedence. |
| internal/tenant/sql.go | API-key resolution maps the authoritative joined connection-limit columns into the request-scoped tenant context. |
| internal/db/queries/api_keys.sql | The API-key lookup now joins the current per-tenant connection override without introducing a separate process cache. |
| internal/ratelimit/connection_cap.go | Higher tier defaults and a bounded custom-limit ceiling are introduced while preserving burst admission semantics. |
| internal/controlpanel/rate_limits.go | Adds validated, audited persistence and clearing of tenant-specific connection envelopes. |
| db/migrations/0044_connection_limit_overrides.up.sql | Creates the connection-limit override table with referential integrity and sustained, ceiling, ratio, and absolute-limit constraints. |
Sequence Diagram
sequenceDiagram
participant Admin as Platform Admin
participant CP as Control Panel
participant DB as PostgreSQL
participant MW as Tenant Middleware
participant WS as Realtime Admission
participant Cap as Leased Connection Cap
Admin->>CP: Set or clear tenant envelope
CP->>DB: Persist sustained and ceiling
MW->>DB: Resolve API key and current envelope
DB-->>MW: Tenant tier and optional override
MW->>WS: Attach resolved API-key facts
WS->>Cap: Acquire using resolved envelope
Cap-->>WS: Admit or reject
Reviews (3): Last reviewed commit: "Resolve connection override consistency" | Re-trigger Greptile
Comment on lines
+141
to
+150
| } else { | ||
| // Preserve the last known override through a short database failure. If | ||
| // this tenant has never been cached, the zero entry means "use its tier | ||
| // default." The short backoff prevents every handshake from retrying the | ||
| // same failed query while still converging quickly after recovery. | ||
| if !hadEntry { | ||
| entry = cachedConnectionLimit{} | ||
| } | ||
| entry.expiresAt = now.Add(min(c.ttl, time.Second)) | ||
| } |
There was a problem hiding this comment.
Stale elevated cap survives reductions
If a tenant's elevated override is cached on one process, an administrator lowers or clears it on another process, and the next refresh fails, the error path preserves the former elevated limits. tenantCapLimits then continues passing those stale limits to admission, causing WebSocket connections to be admitted above the newly persisted envelope until a refresh succeeds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
increasing higher concurrent user limits for high scale services.