Skip to content

Commit

Permalink
media/metrics: Avoid reporting preloadTime as 0 (#406)
Browse files Browse the repository at this point in the history
* media/metrics: Avoid reporting preloadTime as 0

* Revert "media/metrics: Avoid reporting preloadTime as 0"

This reverts commit cf9eeae.

* fix: fix metrics to only send valid values

* chore: changeset

---------

Co-authored-by: Chase Adams <[email protected]>
  • Loading branch information
victorges and 0xcadams authored Nov 14, 2023
1 parent c17686d commit 570342f
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 143 deletions.
9 changes: 9 additions & 0 deletions .changeset/chatty-moons-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@livepeer/core': patch
'@livepeer/core-react': patch
'@livepeer/core-web': patch
'@livepeer/react': patch
'@livepeer/react-native': patch
---

**Fix:** fixed metrics to only send values when they are defined, to avoid filtering on the backend.
220 changes: 110 additions & 110 deletions packages/core-web/src/media/browser/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ describe('addMediaMetrics', () => {
}

expect(metricsSnapshot?.current).toMatchInlineSnapshot(`
{
"autoplay": "standard",
"duration": 0,
"firstPlayback": 0,
"nError": 0,
"nStalled": 0,
"nWaiting": 0,
"offset": 0,
"pageUrl": "http://localhost:3000/",
"playbackScore": null,
"player": "hls-1",
"playerHeight": null,
"playerWidth": null,
"preloadTime": 0,
"sourceType": "unknown",
"sourceUrl": null,
"timeStalled": 0,
"timeUnpaused": 0,
"timeWaiting": 0,
"ttff": 0,
"uid": "",
"userAgent": "UA",
"videoHeight": null,
"videoWidth": null,
}
`);
{
"autoplay": "standard",
"duration": null,
"firstPlayback": null,
"nError": null,
"nStalled": 0,
"nWaiting": 0,
"offset": null,
"pageUrl": "http://localhost:3000/",
"playbackScore": null,
"player": "hls-1",
"playerHeight": null,
"playerWidth": null,
"preloadTime": null,
"sourceType": "unknown",
"sourceUrl": null,
"timeStalled": 0,
"timeUnpaused": 0,
"timeWaiting": 0,
"ttff": null,
"uid": "",
"userAgent": "UA",
"videoHeight": null,
"videoWidth": null,
}
`);
});

it('should update time unpaused and first playback', async () => {
Expand All @@ -72,24 +72,24 @@ describe('addMediaMetrics', () => {
expect(metricsSnapshot?.current).toMatchInlineSnapshot(`
{
"autoplay": "standard",
"duration": 0,
"firstPlayback": 0,
"nError": 0,
"duration": null,
"firstPlayback": null,
"nError": null,
"nStalled": 0,
"nWaiting": 0,
"offset": 0,
"offset": null,
"pageUrl": "http://localhost:3000/",
"playbackScore": null,
"player": "hls-1",
"playerHeight": null,
"playerWidth": null,
"preloadTime": 0,
"preloadTime": null,
"sourceType": "unknown",
"sourceUrl": null,
"timeStalled": 0,
"timeUnpaused": 0,
"timeWaiting": 0,
"ttff": 0,
"ttff": null,
"uid": "",
"userAgent": "UA",
"videoHeight": null,
Expand All @@ -115,32 +115,32 @@ describe('addMediaMetrics', () => {
}

expect(metricsSnapshot?.current).toMatchInlineSnapshot(`
{
"autoplay": "standard",
"duration": 0,
"firstPlayback": 0,
"nError": 0,
"nStalled": 0,
"nWaiting": 1,
"offset": 0,
"pageUrl": "http://localhost:3000/",
"playbackScore": null,
"player": "hls-1",
"playerHeight": null,
"playerWidth": null,
"preloadTime": 0,
"sourceType": "unknown",
"sourceUrl": null,
"timeStalled": 0,
"timeUnpaused": 0,
"timeWaiting": 1000,
"ttff": 0,
"uid": "",
"userAgent": "UA",
"videoHeight": null,
"videoWidth": null,
}
`);
{
"autoplay": "standard",
"duration": null,
"firstPlayback": null,
"nError": null,
"nStalled": 0,
"nWaiting": 1,
"offset": null,
"pageUrl": "http://localhost:3000/",
"playbackScore": null,
"player": "hls-1",
"playerHeight": null,
"playerWidth": null,
"preloadTime": null,
"sourceType": "unknown",
"sourceUrl": null,
"timeStalled": 0,
"timeUnpaused": 0,
"timeWaiting": 1000,
"ttff": null,
"uid": "",
"userAgent": "UA",
"videoHeight": null,
"videoWidth": null,
}
`);
});

it('should update time stalled and stalled count', async () => {
Expand All @@ -162,32 +162,32 @@ describe('addMediaMetrics', () => {
}

expect(metricsSnapshot?.current).toMatchInlineSnapshot(`
{
"autoplay": "standard",
"duration": 0,
"firstPlayback": 0,
"nError": 0,
"nStalled": 1,
"nWaiting": 0,
"offset": 0,
"pageUrl": "http://localhost:3000/",
"playbackScore": null,
"player": "hls-1",
"playerHeight": null,
"playerWidth": null,
"preloadTime": 0,
"sourceType": "unknown",
"sourceUrl": null,
"timeStalled": 1000,
"timeUnpaused": 0,
"timeWaiting": 0,
"ttff": 0,
"uid": "",
"userAgent": "UA",
"videoHeight": null,
"videoWidth": null,
}
`);
{
"autoplay": "standard",
"duration": null,
"firstPlayback": null,
"nError": null,
"nStalled": 1,
"nWaiting": 0,
"offset": null,
"pageUrl": "http://localhost:3000/",
"playbackScore": null,
"player": "hls-1",
"playerHeight": null,
"playerWidth": null,
"preloadTime": null,
"sourceType": "unknown",
"sourceUrl": null,
"timeStalled": 1000,
"timeUnpaused": 0,
"timeWaiting": 0,
"ttff": null,
"uid": "",
"userAgent": "UA",
"videoHeight": null,
"videoWidth": null,
}
`);
});
});

Expand All @@ -209,31 +209,31 @@ describe('addMediaMetrics', () => {
}

expect(metricsSnapshot?.current).toMatchInlineSnapshot(`
{
"autoplay": "standard",
"duration": 0,
"firstPlayback": 0,
"nError": 0,
"nStalled": 0,
"nWaiting": 0,
"offset": 0,
"pageUrl": "http://localhost:3000/",
"playbackScore": null,
"player": "hls-1",
"playerHeight": null,
"playerWidth": null,
"preloadTime": 0,
"sourceType": "unknown",
"sourceUrl": null,
"timeStalled": 0,
"timeUnpaused": 0,
"timeWaiting": 0,
"ttff": 0,
"uid": "",
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36",
"videoHeight": null,
"videoWidth": null,
}
`);
{
"autoplay": "standard",
"duration": null,
"firstPlayback": null,
"nError": null,
"nStalled": 0,
"nWaiting": 0,
"offset": null,
"pageUrl": "http://localhost:3000/",
"playbackScore": null,
"player": "hls-1",
"playerHeight": null,
"playerWidth": null,
"preloadTime": null,
"sourceType": "unknown",
"sourceUrl": null,
"timeStalled": 0,
"timeUnpaused": 0,
"timeWaiting": 0,
"ttff": null,
"uid": "",
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36",
"videoHeight": null,
"videoWidth": null,
}
`);
});
});
Loading

2 comments on commit 570342f

@vercel
Copy link

@vercel vercel bot commented on 570342f Nov 14, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 570342f Nov 14, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.