Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/modern-fans-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/protocol": patch
---

Fix the egress results serialization format
45 changes: 22 additions & 23 deletions observability/egressobs/egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const (
)

type EgressResults struct {
FileResults []*livekit.FileInfo
StreamResults []*livekit.StreamInfo
SegmentResults []*livekit.SegmentsInfo
ImageResults []*livekit.ImagesInfo
FileResults []*livekit.FileInfo `json:"file_results,omitempty"`
StreamResults []*livekit.StreamInfo `json:"stream_results,omitempty"`
SegmentResults []*livekit.SegmentsInfo `json:"segment_results,omitempty"`
ImageResults []*livekit.ImagesInfo `json:"image_results,omitempty"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this currently snake case? what consumes this? does this break backward compatibility?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was currently not working because:

  1. cloud-api-server tries to parse the content of this field as if were in the same format as the analytics corresponding field
  2. egress is serializing this in different formats depending on the type of result without actually indicating what the type is

See https://linear.app/livekit/issue/CS-1673/v3-egress-missing-data-points

I can change the schema to write to a new column if you want to somehow keep compatibility with the data that's currently in the "result" column. Do we need to considering the context above?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backward compatibility with the existing data isn't important but the way api server is parsing this is sketchy...

}

func GetSourceType(info *livekit.EgressInfo) SessionSourceType {
Expand Down Expand Up @@ -154,37 +154,36 @@ func GetRequest(info *livekit.EgressInfo) (string, error) {
}

func GetResult(info *livekit.EgressInfo) (string, error) {
var results *EgressResults

if file := info.GetFile(); file != nil {
b, err := protojson.Marshal(file)
if err != nil {
return "", errors.Wrap(err, "failed serializing File result")
results = &EgressResults{
FileResults: []*livekit.FileInfo{
file,
},
}
return string(b), nil
} else if stream := info.GetStream(); stream != nil {
b, err := protojson.Marshal(stream)
if err != nil {
return "", errors.Wrap(err, "failed serializing Stream result")
}
return string(b), nil
results = &EgressResults{}
results.StreamResults = append(results.StreamResults, stream.Info...)
} else if segments := info.GetSegments(); segments != nil {
b, err := protojson.Marshal(segments)
if err != nil {
return "", errors.Wrap(err, "failed serializing Segments result")
results = &EgressResults{
SegmentResults: []*livekit.SegmentsInfo{
segments,
},
}
return string(b), nil
} else {
results := &EgressResults{
results = &EgressResults{
FileResults: info.FileResults,
StreamResults: info.StreamResults,
SegmentResults: info.SegmentResults,
ImageResults: info.ImageResults,
}
b, err := json.Marshal(results)
if err != nil {
return "", errors.Wrap(err, "failed serializing Multiple result")
}
return string(b), nil
}
b, err := json.Marshal(results)
if err != nil {
return "", errors.Wrap(err, "failed serializing results")
}
return string(b), nil
}

func GetAudioOnly(info *livekit.EgressInfo) bool {
Expand Down
19 changes: 13 additions & 6 deletions observability/egressobs/egress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,32 +219,38 @@ func TestGetRequest(t *testing.T) {

func TestGetResult(t *testing.T) {
tests := []struct {
name string
info *livekit.EgressInfo
name string
info *livekit.EgressInfo
expected string
}{
{
name: "FileResult",
info: &livekit.EgressInfo{
Result: &livekit.EgressInfo_File{
File: &livekit.FileInfo{Filename: "test.mp4"},
File: &livekit.FileInfo{Filename: "test.mp4", Size: 1024},
},
},
expected: `{"file_results":[{"filename":"test.mp4", "size":1024}]}`,
},
{
name: "StreamResult",
info: &livekit.EgressInfo{
Result: &livekit.EgressInfo_Stream{
Stream: &livekit.StreamInfoList{},
Stream: &livekit.StreamInfoList{
Info: []*livekit.StreamInfo{{Url: "rtmp://example.com/live"}},
},
},
},
expected: `{"stream_results":[{"url":"rtmp://example.com/live"}]}`,
},
{
name: "SegmentResult",
info: &livekit.EgressInfo{
Result: &livekit.EgressInfo_Segments{
Segments: &livekit.SegmentsInfo{},
Segments: &livekit.SegmentsInfo{PlaylistName: "playlist.m3u8"},
},
},
expected: `{"segment_results":[{"playlist_name":"playlist.m3u8"}]}`,
},
{
name: "MultipleResults",
Expand All @@ -253,14 +259,15 @@ func TestGetResult(t *testing.T) {
{Filename: "test.mp4"},
},
},
expected: `{"file_results":[{"filename":"test.mp4"}]}`,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := GetResult(tt.info)
require.NoError(t, err)
require.NotEmpty(t, result)
require.JSONEq(t, tt.expected, result)
})
}
}
Expand Down
Loading