- Notifications
You must be signed in to change notification settings - Fork1.1k
chore: record user agent in interception metadata#20695
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
pawbana wants to merge1 commit intomainChoose a base branch from10-30-pb-aibridge-intc-user-agent-metadata
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+348 −212
Open
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletionsenterprise/aibridged/aibridged_integration_test.go
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
3 changes: 2 additions & 1 deletionenterprise/aibridged/http.go
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
5 changes: 4 additions & 1 deletionenterprise/aibridged/pool.go
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
3 changes: 2 additions & 1 deletionenterprise/aibridged/pool_test.go
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
426 changes: 218 additions & 208 deletionsenterprise/aibridged/proto/aibridged.pb.go
Large diffs are not rendered by default.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
1 change: 1 addition & 0 deletionsenterprise/aibridged/proto/aibridged.proto
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
3 changes: 2 additions & 1 deletionenterprise/aibridged/request.go
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
1 change: 1 addition & 0 deletionsenterprise/aibridged/translator.go
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
91 changes: 91 additions & 0 deletionsenterprise/aibridged/translator_test.go
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,91 @@ | ||
| package aibridged //nolint:testpackage | ||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
| "github.com/google/uuid" | ||
| "github.com/stretchr/testify/require" | ||
| "google.golang.org/protobuf/proto" | ||
| "google.golang.org/protobuf/types/known/anypb" | ||
| "google.golang.org/protobuf/types/known/structpb" | ||
| "google.golang.org/protobuf/types/known/timestamppb" | ||
| "github.com/coder/aibridge" | ||
| abpb "github.com/coder/coder/v2/enterprise/aibridged/proto" | ||
| "github.com/coder/coder/v2/testutil" | ||
| ) | ||
| const ( | ||
| MetaKeyUserAgent = "user-agent" | ||
| ) | ||
| type mockClient struct { | ||
| abpb.DRPCRecorderClient | ||
| got *abpb.RecordInterceptionRequest | ||
| } | ||
| func (mc *mockClient) RecordInterception(ctx context.Context, in *abpb.RecordInterceptionRequest) (*abpb.RecordInterceptionResponse, error) { | ||
| mc.got = in | ||
| return &abpb.RecordInterceptionResponse{}, nil | ||
| } | ||
| func mustAnypbNew(t *testing.T, src proto.Message) *anypb.Any { | ||
| ret, err := anypb.New(src) | ||
| require.NoError(t, err) | ||
| return ret | ||
| } | ||
| func TestRecordInterception(t *testing.T) { | ||
| t.Parallel() | ||
| tests := []struct { | ||
| name string | ||
| apiKeyID string | ||
| userAgent string | ||
| in aibridge.InterceptionRecord | ||
| expect *abpb.RecordInterceptionRequest | ||
| }{ | ||
| { | ||
| name: "ok", | ||
| apiKeyID: "key", | ||
| in: aibridge.InterceptionRecord{ | ||
| ID: uuid.UUID{1}.String(), | ||
| InitiatorID: uuid.UUID{2}.String(), | ||
| Provider: "prov", | ||
| Model: "model", | ||
| UserAgent: "user-agent", | ||
Check failure on line 58 in enterprise/aibridged/translator_test.go
| ||
| Metadata: map[string]any{"some": "data"}, | ||
| StartedAt: time.UnixMicro(123), | ||
| }, | ||
| expect: &abpb.RecordInterceptionRequest{ | ||
| Id: uuid.UUID{1}.String(), | ||
| ApiKeyId: "key", | ||
| InitiatorId: uuid.UUID{2}.String(), | ||
| Provider: "prov", | ||
| Model: "model", | ||
| UserAgent: "user-agent", | ||
| Metadata: map[string]*anypb.Any{ | ||
| "some": mustAnypbNew(t, structpb.NewStringValue("data")), | ||
| }, | ||
| StartedAt: timestamppb.New(time.UnixMicro(123)), | ||
| }, | ||
| }, | ||
| } | ||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
| ctx := testutil.Context(t, testutil.WaitShort) | ||
| mc := &mockClient{} | ||
| rt := &recorderTranslation{ | ||
| apiKeyID: tc.apiKeyID, | ||
| client: mc, | ||
| } | ||
| rt.RecordInterception(ctx, &tc.in) | ||
| require.Equal(t, tc.expect, mc.got) | ||
| }) | ||
| } | ||
| } | ||
16 changes: 16 additions & 0 deletionsenterprise/aibridgedserver/aibridgedserver.go
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.
Uh oh!
There was an error while loading.Please reload this page.
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.