Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5e2ca7

Browse files
authored
chore: rename recorderTranslation to DRPCRecorder (#29133)
The old name, `recorderTranslation`, did not clarify from what calls were being translated, nor to what they were being translated. The new name, `DRPCRecorder`, immediately explains that calls are being recorded over DRPC. This was a readability hurdle while trying to investigate touch points for AIGOV-358. This is the first step towards implementing either a /dev/null-esque recorder or a logging recorder as per the requirements in AIGOV-358.
1 parent 6bc033e commit d5e2ca7

3 files changed

Lines changed: 23 additions & 19 deletions

File tree

aibridge/recorder/recorder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var (
1818
_ Recorder = &AsyncRecorder{}
1919
)
2020

21-
// WrappedRecorder is a convenience struct which implements RecorderClient and resolves a client before calling each method.
21+
// WrappedRecorder is a convenience struct which implements Recorder and resolves a client before calling each method.
2222
// It also sets the start/creation time of each record.
2323
type WrappedRecorder struct {
2424
logger slog.Logger
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import (
1414
"github.com/coder/coder/v2/coderd/aibridged/proto"
1515
)
1616

17-
var _ aibridge.Recorder = &recorderTranslation{}
17+
var _ aibridge.Recorder = &DRPCRecorder{}
1818

19-
// recorderTranslation satisfies the aibridge.Recorder interface and translates calls into dRPC calls to aibridgedserver.
20-
type recorderTranslation struct {
19+
// DRPCRecorder satisfies the aibridge.Recorder interface and translates calls into dRPC calls to aibridgedserver.
20+
type DRPCRecorder struct {
2121
apiKeyID string
2222
client proto.DRPCRecorderClient
2323
}
2424

25-
func (t *recorderTranslation) RecordInterception(ctx context.Context, req *aibridge.InterceptionRecord) error {
25+
func (t *DRPCRecorder) RecordInterception(ctx context.Context, req *aibridge.InterceptionRecord) error {
2626
_, err := t.client.RecordInterception(ctx, &proto.RecordInterceptionRequest{
2727
Id: req.ID,
2828
ApiKeyId: t.apiKeyID,
@@ -44,7 +44,7 @@ func (t *recorderTranslation) RecordInterception(ctx context.Context, req *aibri
4444
return err
4545
}
4646

47-
func (t *recorderTranslation) RecordInterceptionEnded(ctx context.Context, req *aibridge.InterceptionRecordEnded) error {
47+
func (t *DRPCRecorder) RecordInterceptionEnded(ctx context.Context, req *aibridge.InterceptionRecordEnded) error {
4848
endedReq := &proto.RecordInterceptionEndedRequest{
4949
Id: req.ID,
5050
EndedAt: timestamppb.New(req.EndedAt),
@@ -61,7 +61,7 @@ func (t *recorderTranslation) RecordInterceptionEnded(ctx context.Context, req *
6161
return err
6262
}
6363

64-
func (t *recorderTranslation) RecordPromptUsage(ctx context.Context, req *aibridge.PromptUsageRecord) error {
64+
func (t *DRPCRecorder) RecordPromptUsage(ctx context.Context, req *aibridge.PromptUsageRecord) error {
6565
_, err := t.client.RecordPromptUsage(ctx, &proto.RecordPromptUsageRequest{
6666
InterceptionId: req.InterceptionID,
6767
MsgId: req.MsgID,
@@ -72,7 +72,7 @@ func (t *recorderTranslation) RecordPromptUsage(ctx context.Context, req *aibrid
7272
return err
7373
}
7474

75-
func (t *recorderTranslation) RecordTokenUsage(ctx context.Context, req *aibridge.TokenUsageRecord) error {
75+
func (t *DRPCRecorder) RecordTokenUsage(ctx context.Context, req *aibridge.TokenUsageRecord) error {
7676
merged := req.Metadata
7777
if merged == nil {
7878
merged = aibridge.Metadata{}
@@ -96,7 +96,7 @@ func (t *recorderTranslation) RecordTokenUsage(ctx context.Context, req *aibridg
9696
return err
9797
}
9898

99-
func (t *recorderTranslation) RecordToolUsage(ctx context.Context, req *aibridge.ToolUsageRecord) error {
99+
func (t *DRPCRecorder) RecordToolUsage(ctx context.Context, req *aibridge.ToolUsageRecord) error {
100100
serialized, err := json.Marshal(req.Args)
101101
if err != nil {
102102
return xerrors.Errorf("serialize tool %q args: %w", req.Tool, err)
@@ -123,7 +123,7 @@ func (t *recorderTranslation) RecordToolUsage(ctx context.Context, req *aibridge
123123
return err
124124
}
125125

126-
func (t *recorderTranslation) RecordModelThought(ctx context.Context, req *aibridge.ModelThoughtRecord) error {
126+
func (t *DRPCRecorder) RecordModelThought(ctx context.Context, req *aibridge.ModelThoughtRecord) error {
127127
_, err := t.client.RecordModelThought(ctx, &proto.RecordModelThoughtRequest{
128128
InterceptionId: req.InterceptionID,
129129
Content: req.Content,

coderd/aibridged/pool.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,20 @@ func (p *CachedBridgePool) Acquire(ctx context.Context, req Request, clientFn Cl
228228

229229
span.AddEvent("cache_miss")
230230
providerVersion := p.providerVersion.Load()
231-
recorder := aibridge.NewRecorder(p.logger.Named("recorder"), p.tracer, func(clientCtx context.Context) (aibridge.Recorder, error) {
232-
// The recorder outlives this Acquire call, so the client is acquired
233-
// against the context of the record call being served.
234-
client, err := clientFn(clientCtx)
235-
if err != nil {
236-
return nil, xerrors.Errorf("acquire client: %w", err)
237-
}
231+
recorder := aibridge.NewRecorder(
232+
p.logger.Named("recorder"),
233+
p.tracer,
234+
func(clientCtx context.Context) (aibridge.Recorder, error) {
235+
// The recorder outlives this Acquire call, so the client is acquired
236+
// against the context of the record call being served.
237+
client, err := clientFn(clientCtx)
238+
if err != nil {
239+
return nil, xerrors.Errorf("acquire client: %w", err)
240+
}
238241

239-
return &recorderTranslation{apiKeyID: req.APIKeyID, client: client}, nil
240-
})
242+
return &DRPCRecorder{apiKeyID: req.APIKeyID, client: client}, nil
243+
},
244+
)
241245

242246
// Slow path.
243247
// Creating an *aibridge.RequestBridge may take some time, so gate all subsequent callers behind the initial request and return the resulting value.

0 commit comments

Comments
 (0)