Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-53432] Improve recording start time accuracy #44

Merged
merged 14 commits into from
Nov 21, 2023
Merged
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ docker pull mattermost/calls-recorder:latest
### Run the container

```
docker run --network=host --name calls-recorder -e "SITE_URL=http://127.0.0.1:8065/" -e "AUTH_TOKEN=ohqd1phqtt8m3gsfg8j5ymymqy" -e "CALL_ID=9c86b3q57fgfpqr8jq3b9yjweh" -e "THREAD_ID=e4pdmi6rqpn7pp9sity9hiza3r" -e "DEV_MODE=true" -v calls-recorder-volume:/recs mattermost/calls-recorder
docker run --network=host --name calls-recorder -e "SITE_URL=http://127.0.0.1:8065/" -e "AUTH_TOKEN=ohqd1phqtt8m3gsfg8j5ymymqy" -e "CALL_ID=9c86b3q57fgfpqr8jq3b9yjweh" -e "POST_ID=e4pdmi6rqpn7pp9sity9hiza3r" -e "DEV_MODE=true" -v calls-recorder-volume:/data mattermost/calls-recorder
```

> **_Note_**
Expand All @@ -36,7 +36,7 @@ docker run --network=host --name calls-recorder -e "SITE_URL=http://127.0.0.1:80
> - `SITE_URL`: The URL pointing to the Mattermost installation.
> - `AUTH_TOKEN`: The authentication token for the Calls bot.
> - `CALL_ID`: The channel ID in which the call to record has been started.
> - `THREAD_ID`: The thread ID the recording file should be posted to.
> - `POST_ID`: The post ID the recording file should be attached to.

> **_Note_**
>
Expand Down
4 changes: 2 additions & 2 deletions build/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ trap 'kill ${!}; term_handler' SIGTERM
RECORDER_USER=calls

# Give permission to write recording files.
chown -R $RECORDER_USER:$RECORDER_USER /recs
chown -R $RECORDER_USER:$RECORDER_USER /data
# Give permissions to home directory so that Chromium can create any
# necessary files and directories.
chown -R $RECORDER_USER:$RECORDER_USER /home/$RECORDER_USER
Expand All @@ -72,7 +72,7 @@ runuser -l $RECORDER_USER -c \
"SITE_URL=$SITE_URL \
AUTH_TOKEN=$AUTH_TOKEN \
CALL_ID=$CALL_ID \
THREAD_ID=$THREAD_ID \
POST_ID=$POST_ID \
RECORDING_ID=$RECORDING_ID \
WIDTH=${WIDTH:-0} \
HEIGHT=${HEIGHT:-0} \
Expand Down
8 changes: 4 additions & 4 deletions build/pkgs_list
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ca-certificates=20230311
chromium=119.0.6045.123-1
chromium-driver=119.0.6045.123-1
chromium-sandbox=119.0.6045.123-1
ffmpeg=7:6.1-2
chromium=119.0.6045.159-1
chromium-driver=119.0.6045.159-1
chromium-sandbox=119.0.6045.159-1
ffmpeg=7:6.1-3
fonts-recommended=1
pulseaudio=16.1+dfsg1-2+b1
wget=1.21.4-1+b1
Expand Down
26 changes: 17 additions & 9 deletions cmd/recorder/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type RecorderConfig struct {
// input config
SiteURL string
CallID string
ThreadID string
PostID string
RecordingID string
AuthToken string

Expand Down Expand Up @@ -101,10 +101,10 @@ func (cfg RecorderConfig) IsValid() error {
return fmt.Errorf("CallID parsing failed")
}

if cfg.ThreadID == "" {
return fmt.Errorf("ThreadID cannot be empty")
} else if !idRE.MatchString(cfg.ThreadID) {
return fmt.Errorf("ThreadID parsing failed")
if cfg.PostID == "" {
return fmt.Errorf("PostID cannot be empty")
} else if !idRE.MatchString(cfg.PostID) {
return fmt.Errorf("PostID parsing failed")
}

if cfg.RecordingID == "" {
Expand Down Expand Up @@ -175,10 +175,14 @@ func (cfg *RecorderConfig) SetDefaults() {
}

func (cfg RecorderConfig) ToEnv() []string {
if cfg == (RecorderConfig{}) {
return nil
}

return []string{
fmt.Sprintf("SITE_URL=%s", cfg.SiteURL),
fmt.Sprintf("CALL_ID=%s", cfg.CallID),
fmt.Sprintf("THREAD_ID=%s", cfg.ThreadID),
fmt.Sprintf("POST_ID=%s", cfg.PostID),
fmt.Sprintf("RECORDING_ID=%s", cfg.RecordingID),
fmt.Sprintf("AUTH_TOKEN=%s", cfg.AuthToken),
fmt.Sprintf("WIDTH=%d", cfg.Width),
Expand All @@ -192,10 +196,14 @@ func (cfg RecorderConfig) ToEnv() []string {
}

func (cfg RecorderConfig) ToMap() map[string]any {
if cfg == (RecorderConfig{}) {
return nil
}

return map[string]any{
"site_url": cfg.SiteURL,
"call_id": cfg.CallID,
"thread_id": cfg.ThreadID,
"post_id": cfg.PostID,
"recording_id": cfg.RecordingID,
"auth_token": cfg.AuthToken,
"width": cfg.Width,
Expand All @@ -211,7 +219,7 @@ func (cfg RecorderConfig) ToMap() map[string]any {
func (cfg *RecorderConfig) FromMap(m map[string]any) *RecorderConfig {
cfg.SiteURL, _ = m["site_url"].(string)
cfg.CallID, _ = m["call_id"].(string)
cfg.ThreadID, _ = m["thread_id"].(string)
cfg.PostID, _ = m["post_id"].(string)
cfg.RecordingID, _ = m["recording_id"].(string)
cfg.AuthToken, _ = m["auth_token"].(string)
if width, ok := m["width"].(float64); ok {
Expand Down Expand Up @@ -256,7 +264,7 @@ func LoadFromEnv() (RecorderConfig, error) {
var cfg RecorderConfig
cfg.SiteURL = strings.TrimSuffix(os.Getenv("SITE_URL"), "/")
cfg.CallID = os.Getenv("CALL_ID")
cfg.ThreadID = os.Getenv("THREAD_ID")
cfg.PostID = os.Getenv("POST_ID")
cfg.RecordingID = os.Getenv("RECORDING_ID")
cfg.AuthToken = os.Getenv("AUTH_TOKEN")

Expand Down
36 changes: 18 additions & 18 deletions cmd/recorder/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ func TestConfigIsValid(t *testing.T) {
expectedError: "CallID cannot be empty",
},
{
name: "missing ThreadID",
name: "missing PostID",
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
},
expectedError: "ThreadID cannot be empty",
expectedError: "PostID cannot be empty",
},
{
name: "missing RecordingID",
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
PostID: "udzdsg7dwidbzcidx5khrf8nee",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
},
expectedError: "RecordingID cannot be empty",
Expand All @@ -56,7 +56,7 @@ func TestConfigIsValid(t *testing.T) {
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
PostID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
},
expectedError: "AuthToken cannot be empty",
Expand All @@ -66,7 +66,7 @@ func TestConfigIsValid(t *testing.T) {
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
PostID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
},
Expand All @@ -77,7 +77,7 @@ func TestConfigIsValid(t *testing.T) {
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
PostID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Expand All @@ -89,7 +89,7 @@ func TestConfigIsValid(t *testing.T) {
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
PostID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Expand All @@ -102,7 +102,7 @@ func TestConfigIsValid(t *testing.T) {
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
PostID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Expand All @@ -116,7 +116,7 @@ func TestConfigIsValid(t *testing.T) {
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
PostID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Expand All @@ -131,7 +131,7 @@ func TestConfigIsValid(t *testing.T) {
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
PostID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Expand All @@ -148,7 +148,7 @@ func TestConfigIsValid(t *testing.T) {
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
PostID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Expand All @@ -164,7 +164,7 @@ func TestConfigIsValid(t *testing.T) {
cfg: RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
PostID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1280,
Expand Down Expand Up @@ -267,8 +267,8 @@ func TestLoadFromEnv(t *testing.T) {
defer os.Unsetenv("SITE_URL")
os.Setenv("CALL_ID", "8w8jorhr7j83uqr6y1st894hqe")
defer os.Unsetenv("CALL_ID")
os.Setenv("THREAD_ID", "udzdsg7dwidbzcidx5khrf8nee")
defer os.Unsetenv("THREAD_ID")
os.Setenv("POST_ID", "udzdsg7dwidbzcidx5khrf8nee")
defer os.Unsetenv("POST_ID")
os.Setenv("RECORDING_ID", "67t5u6cmtfbb7jug739d43xa9e")
defer os.Unsetenv("RECORDING_ID")
os.Setenv("AUTH_TOKEN", "qj75unbsef83ik9p7ueypb6iyw")
Expand All @@ -291,7 +291,7 @@ func TestLoadFromEnv(t *testing.T) {
require.Equal(t, RecorderConfig{
SiteURL: "http://localhost:8065",
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
PostID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
Width: 1920,
Expand All @@ -308,14 +308,14 @@ func TestRecorderConfigToEnv(t *testing.T) {
var cfg RecorderConfig
cfg.SiteURL = "http://localhost:8065"
cfg.CallID = "8w8jorhr7j83uqr6y1st894hqe"
cfg.ThreadID = "udzdsg7dwidbzcidx5khrf8nee"
cfg.PostID = "udzdsg7dwidbzcidx5khrf8nee"
cfg.RecordingID = "67t5u6cmtfbb7jug739d43xa9e"
cfg.AuthToken = "qj75unbsef83ik9p7ueypb6iyw"
cfg.SetDefaults()
require.Equal(t, []string{
"SITE_URL=http://localhost:8065",
"CALL_ID=8w8jorhr7j83uqr6y1st894hqe",
"THREAD_ID=udzdsg7dwidbzcidx5khrf8nee",
"POST_ID=udzdsg7dwidbzcidx5khrf8nee",
"RECORDING_ID=67t5u6cmtfbb7jug739d43xa9e",
"AUTH_TOKEN=qj75unbsef83ik9p7ueypb6iyw",
"WIDTH=1920",
Expand All @@ -332,7 +332,7 @@ func TestRecorderConfigMap(t *testing.T) {
var cfg RecorderConfig
cfg.SiteURL = "http://localhost:8065"
cfg.CallID = "8w8jorhr7j83uqr6y1st894hqe"
cfg.ThreadID = "udzdsg7dwidbzcidx5khrf8nee"
cfg.PostID = "udzdsg7dwidbzcidx5khrf8nee"
cfg.RecordingID = "67t5u6cmtfbb7jug739d43xa9e"
cfg.AuthToken = "qj75unbsef83ik9p7ueypb6iyw"
cfg.SetDefaults()
Expand Down
2 changes: 1 addition & 1 deletion cmd/recorder/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestReportJobFailure(t *testing.T) {
cfg := config.RecorderConfig{
SiteURL: ts.URL,
CallID: "8w8jorhr7j83uqr6y1st894hqe",
ThreadID: "udzdsg7dwidbzcidx5khrf8nee",
PostID: "udzdsg7dwidbzcidx5khrf8nee",
RecordingID: "67t5u6cmtfbb7jug739d43xa9e",
AuthToken: "qj75unbsef83ik9p7ueypb6iyw",
}
Expand Down
Loading