-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MM-57698] Implement client ICE candidate pairs metric (#803)
* Implement client ICE candidate pairs metric * Update calls-common
- Loading branch information
1 parent
a7dabb0
commit afed918
Showing
14 changed files
with
520 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
server/mocks/github.com/mattermost/mattermost-plugin-calls/server/interfaces/mock_Metrics.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package public | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type MetricName string | ||
|
||
const ( | ||
MetricLiveCaptionsWindowDropped MetricName = "live_captions_window_dropped" | ||
MetricLiveCaptionsTranscriberBufFull MetricName = "live_captions_transcriber_buf_full" | ||
MetricLiveCaptionsPktPayloadChBufFull MetricName = "live_captions_pktPayloadCh_buf_full" | ||
|
||
MetricClientICECandidatePair MetricName = "client_ice_candidate_pair" | ||
) | ||
|
||
type MetricMsg struct { | ||
SessionID string `json:"session_id"` | ||
MetricName MetricName `json:"metric_name"` | ||
} | ||
|
||
type ICECandidateInfo struct { | ||
Type string `json:"type"` | ||
Protocol string `json:"protocol"` | ||
} | ||
|
||
func (i ICECandidateInfo) IsValid() error { | ||
switch i.Type { | ||
case "host", "srflx", "prflx", "relay": | ||
default: | ||
return fmt.Errorf("invalid type %q", i.Type) | ||
} | ||
|
||
switch i.Protocol { | ||
case "udp", "tcp": | ||
default: | ||
return fmt.Errorf("invalid protocol %q", i.Protocol) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
type ClientICECandidatePairMetricPayload struct { | ||
State string `json:"state"` | ||
Local ICECandidateInfo `json:"local"` | ||
Remote ICECandidateInfo `json:"remote"` | ||
} | ||
|
||
func (c ClientICECandidatePairMetricPayload) IsValid() error { | ||
switch c.State { | ||
case "succeeded", "waiting", "in-progress", "froze", "failed": | ||
default: | ||
return fmt.Errorf("invalid state %q", c.State) | ||
} | ||
|
||
if err := c.Local.IsValid(); err != nil { | ||
return fmt.Errorf("invalid local candidate info: %w", err) | ||
} | ||
|
||
if err := c.Remote.IsValid(); err != nil { | ||
return fmt.Errorf("invalid remote candidate info: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package public | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestICECandidateInfoIsValid(t *testing.T) { | ||
tcs := []struct { | ||
name string | ||
info ICECandidateInfo | ||
err string | ||
}{ | ||
{ | ||
name: "missing type", | ||
info: ICECandidateInfo{ | ||
Protocol: "udp", | ||
}, | ||
err: `invalid type ""`, | ||
}, | ||
{ | ||
name: "missing protocol", | ||
info: ICECandidateInfo{ | ||
Type: "host", | ||
}, | ||
err: `invalid protocol ""`, | ||
}, | ||
{ | ||
name: "invalid type", | ||
info: ICECandidateInfo{ | ||
Type: "invalid", | ||
Protocol: "udp", | ||
}, | ||
err: `invalid type "invalid"`, | ||
}, | ||
{ | ||
name: "invalid protocol", | ||
info: ICECandidateInfo{ | ||
Type: "host", | ||
Protocol: "invalid", | ||
}, | ||
err: `invalid protocol "invalid"`, | ||
}, | ||
{ | ||
name: "valid, udp", | ||
info: ICECandidateInfo{ | ||
Type: "host", | ||
Protocol: "udp", | ||
}, | ||
}, | ||
{ | ||
name: "valid, tcp", | ||
info: ICECandidateInfo{ | ||
Type: "host", | ||
Protocol: "tcp", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := tc.info.IsValid() | ||
if tc.err == "" { | ||
require.NoError(t, err) | ||
} else { | ||
require.EqualError(t, err, tc.err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestClientICECandidatePairMetricPayloadIsValid(t *testing.T) { | ||
tcs := []struct { | ||
name string | ||
info ClientICECandidatePairMetricPayload | ||
err string | ||
}{ | ||
{ | ||
name: "missing state", | ||
info: ClientICECandidatePairMetricPayload{ | ||
Local: ICECandidateInfo{ | ||
Type: "host", | ||
Protocol: "udp", | ||
}, | ||
Remote: ICECandidateInfo{ | ||
Type: "host", | ||
Protocol: "udp", | ||
}, | ||
}, | ||
err: `invalid state ""`, | ||
}, | ||
{ | ||
name: "invalid state", | ||
info: ClientICECandidatePairMetricPayload{ | ||
State: "invalid", | ||
Local: ICECandidateInfo{ | ||
Type: "host", | ||
Protocol: "udp", | ||
}, | ||
Remote: ICECandidateInfo{ | ||
Type: "host", | ||
Protocol: "udp", | ||
}, | ||
}, | ||
err: `invalid state "invalid"`, | ||
}, | ||
{ | ||
name: "missing local", | ||
info: ClientICECandidatePairMetricPayload{ | ||
State: "succeeded", | ||
Remote: ICECandidateInfo{ | ||
Type: "host", | ||
Protocol: "udp", | ||
}, | ||
}, | ||
err: `invalid local candidate info: invalid type ""`, | ||
}, | ||
{ | ||
name: "missing remote", | ||
info: ClientICECandidatePairMetricPayload{ | ||
State: "succeeded", | ||
Local: ICECandidateInfo{ | ||
Type: "host", | ||
Protocol: "udp", | ||
}, | ||
}, | ||
err: `invalid remote candidate info: invalid type ""`, | ||
}, | ||
{ | ||
name: "valid", | ||
info: ClientICECandidatePairMetricPayload{ | ||
State: "failed", | ||
Local: ICECandidateInfo{ | ||
Type: "host", | ||
Protocol: "udp", | ||
}, | ||
Remote: ICECandidateInfo{ | ||
Type: "host", | ||
Protocol: "udp", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := tc.info.IsValid() | ||
if tc.err == "" { | ||
require.NoError(t, err) | ||
} else { | ||
require.EqualError(t, err, tc.err) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.