-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(coderd): add overload protection with rate limiting and concurrency control #21161
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
15 commits
Select commit
Hold shift + click to select a range
4b78220
feat(aibridged): add overload protection with rate limiting and concu…
kacpersaw 3fdd2a7
refactor: use per-user rate limiting by auth token instead of IP
kacpersaw 77c10fa
refactor: address review feedback from @pawbana
kacpersaw 608dda7
refactor: address remaining review comments
kacpersaw aedd7de
refactor: change rate limit window from per-minute to per-second
kacpersaw 7a84f9a
refactor: address @dannykopping's review comments
kacpersaw 59af0af
docs: document how RateLimitByAuthToken differs from RateLimit
kacpersaw 88e50eb
refactor: remove ExtractAuthToken alias, use httpmw.ExtractAPIKeyFrom…
kacpersaw ac9e7ee
fix lint
kacpersaw 5ad4c6e
Use testutil.Context
kacpersaw 5c92af5
refactor: move ExtractAuthToken to coderd/aibridge package
kacpersaw de43972
test: add integration tests for AI Bridge rate and concurrency limiting
kacpersaw 1317128
fix: avoid require in goroutine to prevent data races
kacpersaw 522b336
refactor: update import alias for aibridge package
kacpersaw 9b2e3c9
Merge branch 'main' into kacpersaw/aibridge-overload-protection
kacpersaw 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
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,24 @@ | ||
| // Package aibridge provides utilities for the AI Bridge feature. | ||
| package aibridge | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "strings" | ||
| ) | ||
|
|
||
| // ExtractAuthToken extracts an authorization token from HTTP headers. | ||
| // It checks the Authorization header (Bearer token) and X-Api-Key header, | ||
| // which represent the different ways clients authenticate against AI providers. | ||
| // If neither are present, an empty string is returned. | ||
| func ExtractAuthToken(header http.Header) string { | ||
| if auth := strings.TrimSpace(header.Get("Authorization")); auth != "" { | ||
| fields := strings.Fields(auth) | ||
| if len(fields) == 2 && strings.EqualFold(fields[0], "Bearer") { | ||
| return fields[1] | ||
| } | ||
| } | ||
| if apiKey := strings.TrimSpace(header.Get("X-Api-Key")); apiKey != "" { | ||
| return apiKey | ||
| } | ||
| return "" | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.