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.
This commit is contained in:
1 parent
6bc033eebd
commit
d5e2ca74cd
3 files changed
+23
-19
No files matched your search
@@ -18,7 +18,7 @@ var (
|
||||
_ Recorder = &AsyncRecorder{}
|
||||
)
|
||||
|
||||
// WrappedRecorder is a convenience struct which implements RecorderClient and resolves a client before calling each method.
|
||||
// WrappedRecorder is a convenience struct which implements Recorder and resolves a client before calling each method.
|
||||
// It also sets the start/creation time of each record.
|
||||
type WrappedRecorder struct {
|
||||
logger slog.Logger
|
||||
|
||||
@@ -14,15 +14,15 @@ import (
|
||||
"github.com/coder/coder/v2/coderd/aibridged/proto"
|
||||
)
|
||||
|
||||
var _ aibridge.Recorder = &recorderTranslation{}
|
||||
var _ aibridge.Recorder = &DRPCRecorder{}
|
||||
|
||||
// recorderTranslation satisfies the aibridge.Recorder interface and translates calls into dRPC calls to aibridgedserver.
|
||||
type recorderTranslation struct {
|
||||
// DRPCRecorder satisfies the aibridge.Recorder interface and translates calls into dRPC calls to aibridgedserver.
|
||||
type DRPCRecorder struct {
|
||||
apiKeyID string
|
||||
client proto.DRPCRecorderClient
|
||||
}
|
||||
|
||||
func (t *recorderTranslation) RecordInterception(ctx context.Context, req *aibridge.InterceptionRecord) error {
|
||||
func (t *DRPCRecorder) RecordInterception(ctx context.Context, req *aibridge.InterceptionRecord) error {
|
||||
_, err := t.client.RecordInterception(ctx, &proto.RecordInterceptionRequest{
|
||||
Id: req.ID,
|
||||
ApiKeyId: t.apiKeyID,
|
||||
@@ -44,7 +44,7 @@ func (t *recorderTranslation) RecordInterception(ctx context.Context, req *aibri
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *recorderTranslation) RecordInterceptionEnded(ctx context.Context, req *aibridge.InterceptionRecordEnded) error {
|
||||
func (t *DRPCRecorder) RecordInterceptionEnded(ctx context.Context, req *aibridge.InterceptionRecordEnded) error {
|
||||
endedReq := &proto.RecordInterceptionEndedRequest{
|
||||
Id: req.ID,
|
||||
EndedAt: timestamppb.New(req.EndedAt),
|
||||
@@ -61,7 +61,7 @@ func (t *recorderTranslation) RecordInterceptionEnded(ctx context.Context, req *
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *recorderTranslation) RecordPromptUsage(ctx context.Context, req *aibridge.PromptUsageRecord) error {
|
||||
func (t *DRPCRecorder) RecordPromptUsage(ctx context.Context, req *aibridge.PromptUsageRecord) error {
|
||||
_, err := t.client.RecordPromptUsage(ctx, &proto.RecordPromptUsageRequest{
|
||||
InterceptionId: req.InterceptionID,
|
||||
MsgId: req.MsgID,
|
||||
@@ -72,7 +72,7 @@ func (t *recorderTranslation) RecordPromptUsage(ctx context.Context, req *aibrid
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *recorderTranslation) RecordTokenUsage(ctx context.Context, req *aibridge.TokenUsageRecord) error {
|
||||
func (t *DRPCRecorder) RecordTokenUsage(ctx context.Context, req *aibridge.TokenUsageRecord) error {
|
||||
merged := req.Metadata
|
||||
if merged == nil {
|
||||
merged = aibridge.Metadata{}
|
||||
@@ -96,7 +96,7 @@ func (t *recorderTranslation) RecordTokenUsage(ctx context.Context, req *aibridg
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *recorderTranslation) RecordToolUsage(ctx context.Context, req *aibridge.ToolUsageRecord) error {
|
||||
func (t *DRPCRecorder) RecordToolUsage(ctx context.Context, req *aibridge.ToolUsageRecord) error {
|
||||
serialized, err := json.Marshal(req.Args)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("serialize tool %q args: %w", req.Tool, err)
|
||||
@@ -123,7 +123,7 @@ func (t *recorderTranslation) RecordToolUsage(ctx context.Context, req *aibridge
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *recorderTranslation) RecordModelThought(ctx context.Context, req *aibridge.ModelThoughtRecord) error {
|
||||
func (t *DRPCRecorder) RecordModelThought(ctx context.Context, req *aibridge.ModelThoughtRecord) error {
|
||||
_, err := t.client.RecordModelThought(ctx, &proto.RecordModelThoughtRequest{
|
||||
InterceptionId: req.InterceptionID,
|
||||
Content: req.Content,
|
||||
@@ -228,16 +228,20 @@ func (p *CachedBridgePool) Acquire(ctx context.Context, req Request, clientFn Cl
|
||||
|
||||
span.AddEvent("cache_miss")
|
||||
providerVersion := p.providerVersion.Load()
|
||||
recorder := aibridge.NewRecorder(p.logger.Named("recorder"), p.tracer, func(clientCtx context.Context) (aibridge.Recorder, error) {
|
||||
// The recorder outlives this Acquire call, so the client is acquired
|
||||
// against the context of the record call being served.
|
||||
client, err := clientFn(clientCtx)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("acquire client: %w", err)
|
||||
}
|
||||
recorder := aibridge.NewRecorder(
|
||||
p.logger.Named("recorder"),
|
||||
p.tracer,
|
||||
func(clientCtx context.Context) (aibridge.Recorder, error) {
|
||||
// The recorder outlives this Acquire call, so the client is acquired
|
||||
// against the context of the record call being served.
|
||||
client, err := clientFn(clientCtx)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("acquire client: %w", err)
|
||||
}
|
||||
|
||||
return &recorderTranslation{apiKeyID: req.APIKeyID, client: client}, nil
|
||||
})
|
||||
return &DRPCRecorder{apiKeyID: req.APIKeyID, client: client}, nil
|
||||
},
|
||||
)
|
||||
|
||||
// Slow path.
|
||||
// Creating an *aibridge.RequestBridge may take some time, so gate all subsequent callers behind the initial request and return the resulting value.
|
||||
|
||||
Reference in new issue
Block a user