-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(edge): release the WebSocket admission permit, add a budget key #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3eb3d51
fix(edge): release the WebSocket admission permit at relay teardown
cuioss-oliver 96d7a21
feat(config): add the edge_hardening admission budget with a WebSocke…
cuioss-oliver d1fd806
test(it): prove the WebSocket relay returns its admission permits
cuioss-oliver 65f9451
feat(benchmarks): re-enable the websocketEcho goal now the permit lea…
cuioss-oliver c52351d
docs: document the edge_hardening admission budget across all three l…
cuioss-oliver ad2bc76
style(edge): apply the pre-commit formatter to the admission-budget s…
cuioss-oliver eaa00c7
fix(test): use an unnamed catch pattern in GatewayEdgeRouteTest
cuioss-oliver 83ee419
fix(edge): derive the omitted websocket_relay_cap from the effective …
cuioss-oliver 18121d4
chore(architecture): record benchmark expected-list independence insight
cuioss-oliver ad6e74b
docs(adr): add ADR-0018 for the WebSocket admission budget
cuioss-oliver 27866fa
docs(adr): renumber the WebSocket admission-budget ADR to 0020
cuioss-oliver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
104 changes: 104 additions & 0 deletions
104
api-sheriff/src/main/java/de/cuioss/sheriff/gateway/config/model/EdgeHardeningConfig.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * Copyright © 2026 CUI-OpenSource-Software (info@cuioss.de) | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package de.cuioss.sheriff.gateway.config.model; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| /** | ||
| * The operator-facing {@code edge_hardening} block: the gateway's admission budget. | ||
| * <p> | ||
| * <strong>Two caps, not one.</strong> {@code admission_cap} bounds how many requests may be in flight | ||
| * across the whole edge at once. {@code websocket_relay_cap} is a <em>sub-budget acquired in addition | ||
| * to</em> that general permit, never instead of it, and exists because a WebSocket relay holds its | ||
| * admission permit for the connection's entire lifetime rather than for one request/response | ||
| * round-trip. Without the sub-budget a modest number of long-lived relays would consume the general | ||
| * pool and starve ordinary HTTP traffic; with it, WebSocket pressure is bounded independently and | ||
| * HTTP keeps the remaining headroom. A {@code websocket_relay_cap} larger than {@code admission_cap} | ||
| * is meaningless — the sub-budget can never bind — and is refused at boot by the config validator. | ||
| * <p> | ||
| * Both members are optional and are independently omissible. An omitted block resolves to the | ||
| * {@link #defaults() documented defaults}, so an operator who never writes the block keeps today's | ||
| * behaviour. An omitted {@code websocket_relay_cap} resolves to a quarter of the <em>effective</em> | ||
| * {@code admission_cap} rather than to a fixed constant, so lowering {@code admission_cap} alone | ||
| * keeps the pair consistent — the relay sub-budget follows the pool it draws from instead of | ||
| * overshooting it and self-rejecting at boot. Values are validated at boot (both {@code >= 1}); | ||
| * this record only carries them. | ||
| * | ||
| * @param admissionCap the maximum number of concurrently in-flight requests the edge admits, | ||
| * empty when the operator did not declare one | ||
| * @param websocketRelayCap the maximum number of concurrently established WebSocket relays, empty | ||
| * when the operator did not declare one | ||
| * @author API Sheriff Team | ||
| * @since 1.0 | ||
| */ | ||
| @Builder | ||
| public record EdgeHardeningConfig(Optional<Integer> admissionCap, Optional<Integer> websocketRelayCap) { | ||
|
|
||
| /** The admission cap applied when the operator declares none — the gateway's historical bound. */ | ||
| public static final int DEFAULT_ADMISSION_CAP = 2048; | ||
|
|
||
| /** | ||
| * The WebSocket-relay sub-budget carried by {@link #defaults()}: a quarter of | ||
| * {@link #DEFAULT_ADMISSION_CAP}. A relay holds its permit for the connection's lifetime, so the | ||
| * default deliberately leaves three quarters of the general pool for ordinary request/response | ||
| * traffic while still admitting far more concurrent relays than a typical deployment sustains. | ||
| * When only {@code admission_cap} is declared, {@link #effectiveWebsocketRelayCap()} derives the | ||
| * same quarter proportion from <em>that</em> cap rather than reading this constant, so the ratio | ||
| * — not the literal value — is what the default preserves. | ||
| */ | ||
| public static final int DEFAULT_WEBSOCKET_RELAY_CAP = 512; | ||
|
|
||
| /** Canonical constructor normalizing absent optionals to {@link Optional#empty()}. */ | ||
| public EdgeHardeningConfig { | ||
| admissionCap = Objects.requireNonNullElse(admissionCap, Optional.empty()); | ||
| websocketRelayCap = Objects.requireNonNullElse(websocketRelayCap, Optional.empty()); | ||
| } | ||
|
|
||
| /** | ||
| * @return the block an omitted {@code edge_hardening} resolves to — both caps at their documented | ||
| * defaults, preserving the behaviour of a gateway that never declares the block | ||
| */ | ||
| public static EdgeHardeningConfig defaults() { | ||
| return new EdgeHardeningConfig(Optional.of(DEFAULT_ADMISSION_CAP), | ||
| Optional.of(DEFAULT_WEBSOCKET_RELAY_CAP)); | ||
| } | ||
|
|
||
| /** | ||
| * @return the declared admission cap, or {@link #DEFAULT_ADMISSION_CAP} when the member is absent | ||
| */ | ||
| public int effectiveAdmissionCap() { | ||
| return admissionCap.orElse(DEFAULT_ADMISSION_CAP); | ||
| } | ||
|
|
||
| /** | ||
| * The implicit relay sub-budget is derived from the pool it draws from rather than fixed, so a | ||
| * partially declared block can never resolve to a relay cap above its own admission cap: with | ||
| * {@code admission_cap: 64} and no {@code websocket_relay_cap}, this yields {@code 16} instead of | ||
| * a self-rejecting {@code 512}. At the shipped {@link #DEFAULT_ADMISSION_CAP} the quarter is | ||
| * exactly {@link #DEFAULT_WEBSOCKET_RELAY_CAP}. An explicitly declared cap is returned untouched | ||
| * — an explicit relay cap above the admission cap remains a boot-time error. | ||
| * | ||
| * @return the declared WebSocket-relay sub-budget, or — when the member is absent — a quarter of | ||
| * the {@linkplain #effectiveAdmissionCap() effective admission cap}, never below | ||
| * {@code 1} | ||
| */ | ||
| public int effectiveWebsocketRelayCap() { | ||
| return websocketRelayCap.orElseGet(() -> Math.max(1, effectiveAdmissionCap() / 4)); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.