Skip to content

Commit

Permalink
Better messages for objectStore errors (#3183)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjh1 authored Sep 27, 2024
1 parent 7ae8e2c commit 2cd552f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
8 changes: 8 additions & 0 deletions core/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,14 @@ func CapabilityToName(capability Capability) (string, error) {
return capName, nil
}

func (c Capability) String() string {
name, err := CapabilityToName(c)
if err != nil {
return fmt.Sprintf("%d", int(c))
}
return name
}

func HasCapability(caps []Capability, capability Capability) bool {
for _, c := range caps {
if capability == c {
Expand Down
25 changes: 25 additions & 0 deletions core/capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,28 @@ func TestLiveeerVersionCompatibleWith(t *testing.T) {
})
}
}

func TestCapability_String(t *testing.T) {
var unknownCap Capability = -100
tests := []struct {
name string
c Capability
want string
}{
{
name: "Capability_TextToImage",
c: Capability_TextToImage,
want: "Text to image",
},
{
name: "Unknown",
c: unknownCap,
want: "-100",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.c.String())
})
}
}
2 changes: 1 addition & 1 deletion server/ai_mediaserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (ls *LivepeerServer) TextToImage() http.Handler {
return
}

clog.V(common.VERBOSE).Infof(r.Context(), "Received TextToImage request prompt=%v model_id=%v", req.Prompt, *req.ModelId)
clog.V(common.VERBOSE).Infof(ctx, "Received TextToImage request prompt=%v model_id=%v", req.Prompt, *req.ModelId)

params := aiRequestParams{
node: ls.LivepeerNode,
Expand Down
15 changes: 8 additions & 7 deletions server/ai_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func processTextToImage(ctx context.Context, params aiRequestParams, req worker.
name := string(core.RandomManifestID()) + ".png"
newUrl, err := params.os.SaveData(ctx, name, bytes.NewReader(data.Bytes()), nil, 0)
if err != nil {
return nil, err
return nil, fmt.Errorf("error saving image to objectStore: %w", err)
}

newMedia[i] = worker.Media{Nsfw: media.Nsfw, Seed: media.Seed, Url: newUrl}
Expand Down Expand Up @@ -241,7 +241,7 @@ func processImageToImage(ctx context.Context, params aiRequestParams, req worker
name := string(core.RandomManifestID()) + ".png"
newUrl, err := params.os.SaveData(ctx, name, bytes.NewReader(data.Bytes()), nil, 0)
if err != nil {
return nil, err
return nil, fmt.Errorf("error saving image to objectStore: %w", err)
}

newMedia[i] = worker.Media{Nsfw: media.Nsfw, Seed: media.Seed, Url: newUrl}
Expand Down Expand Up @@ -377,7 +377,7 @@ func processImageToVideo(ctx context.Context, params aiRequestParams, req worker
name := filepath.Base(media.Url)
newUrl, err := params.os.SaveData(ctx, name, bytes.NewReader(data), nil, 0)
if err != nil {
return nil, err
return nil, fmt.Errorf("error saving video to objectStore: %w", err)
}

videos[i] = worker.Media{
Expand Down Expand Up @@ -518,7 +518,7 @@ func processUpscale(ctx context.Context, params aiRequestParams, req worker.GenU
name := string(core.RandomManifestID()) + ".png"
newUrl, err := params.os.SaveData(ctx, name, bytes.NewReader(data.Bytes()), nil, 0)
if err != nil {
return nil, err
return nil, fmt.Errorf("error saving image to objectStore: %w", err)
}

newMedia[i] = worker.Media{Nsfw: media.Nsfw, Seed: media.Seed, Url: newUrl}
Expand Down Expand Up @@ -875,7 +875,8 @@ func processAIRequest(ctx context.Context, params aiRequestParams, req interface
default:
return nil, fmt.Errorf("unsupported request type %T", req)
}
capName, _ := core.CapabilityToName(cap)
capName := cap.String()
ctx = clog.AddVal(ctx, "capability", capName)

var resp interface{}

Expand All @@ -897,7 +898,7 @@ func processAIRequest(ctx context.Context, params aiRequestParams, req interface
tries++
sess, err := params.sessManager.Select(ctx, cap, modelID)
if err != nil {
clog.Infof(ctx, "Error selecting session cap=%v modelID=%v err=%v", cap, modelID, err)
clog.Infof(ctx, "Error selecting session modelID=%v err=%v", modelID, err)
continue
}

Expand All @@ -911,7 +912,7 @@ func processAIRequest(ctx context.Context, params aiRequestParams, req interface
break
}

clog.Infof(ctx, "Error submitting request cap=%v modelID=%v try=%v orch=%v err=%v", cap, modelID, tries, sess.Transcoder(), err)
clog.Infof(ctx, "Error submitting request modelID=%v try=%v orch=%v err=%v", modelID, tries, sess.Transcoder(), err)
params.sessManager.Remove(ctx, sess)

if errors.Is(err, common.ErrAudioDurationCalculation) {
Expand Down

0 comments on commit 2cd552f

Please sign in to comment.