-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: hot-reload aibridged and aibridgeproxyd providers on DB changes #25673
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
+1,677
−226
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ce98a0f
feat: hot-reload aibridged providers on DB changes
dannykopping ef5a9dc
feat: hot-reload aibridgeproxyd routing on AI provider DB changes
dannykopping 31daa51
test(aibridge): cover provider hot reload behavior
dannykopping 40d0184
test(enterprise/coderd): cover end-to-end AI provider hot reload via …
dannykopping de92df8
fix(aibridge): address PR review feedback for provider hot reload
dannykopping 190a851
test(aibridgeproxyd): add black-box integration test for provider hot…
dannykopping 958c96b
fix(aibridgeproxyd): address remaining PR review feedback
dannykopping dee706c
fix: address PR review feedback for hot-reload branch
dannykopping 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
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,62 @@ | ||
| package coderd_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "sync/atomic" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/coder/coder/v2/coderd/coderdtest" | ||
| coderpubsub "github.com/coder/coder/v2/coderd/pubsub" | ||
| "github.com/coder/coder/v2/codersdk" | ||
| "github.com/coder/coder/v2/testutil" | ||
| ) | ||
|
|
||
| // TestAIProvidersChangedPubsub asserts that the CRUD handlers publish | ||
| // on AIProvidersChangedChannel for the operations that affect the | ||
| // runtime provider set. Subscribers (aibridged, aibridgeproxyd) depend | ||
| // on these notifications to trigger their pool reload. | ||
| // | ||
| // The handlers publish best-effort and the payload is empty, so we | ||
| // assert "at least one event per mutation" via a counter. | ||
| func TestAIProvidersChangedPubsub(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| client, _, api := coderdtest.NewWithAPI(t, nil) | ||
| _ = coderdtest.CreateFirstUser(t, client) | ||
| ctx := testutil.Context(t, testutil.WaitLong) | ||
|
|
||
| var count atomic.Int64 | ||
| unsubscribe, err := api.Pubsub.Subscribe(coderpubsub.AIProvidersChangedChannel, func(_ context.Context, _ []byte) { | ||
| count.Add(1) | ||
| }) | ||
| require.NoError(t, err) | ||
| t.Cleanup(unsubscribe) | ||
|
|
||
| // Create. | ||
| req := codersdk.CreateAIProviderRequest{ | ||
| Type: codersdk.AIProviderTypeOpenAI, | ||
| Name: "pubsub-openai", | ||
| Enabled: true, | ||
| BaseURL: "https://api.openai.com/v1/", | ||
| APIKeys: []string{"k1"}, | ||
| } | ||
| //nolint:gocritic // Owner role is the audience for this endpoint. | ||
| created, err := client.CreateAIProvider(ctx, req) | ||
| require.NoError(t, err) | ||
| testutil.Eventually(ctx, t, func(_ context.Context) bool { return count.Load() >= 1 }, testutil.IntervalFast) | ||
|
|
||
| // Update. | ||
| newKey := "k2" | ||
| _, err = client.UpdateAIProvider(ctx, created.ID.String(), codersdk.UpdateAIProviderRequest{ | ||
| APIKeys: &[]codersdk.AIProviderKeyMutation{{APIKey: &newKey}}, | ||
| }) | ||
| require.NoError(t, err) | ||
| testutil.Eventually(ctx, t, func(_ context.Context) bool { return count.Load() >= 2 }, testutil.IntervalFast) | ||
|
|
||
| // Delete. | ||
| err = client.DeleteAIProvider(ctx, created.ID.String()) | ||
| require.NoError(t, err) | ||
| testutil.Eventually(ctx, t, func(_ context.Context) bool { return count.Load() >= 3 }, testutil.IntervalFast) | ||
| } |
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.