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

feat: add playback monitoring #267

Merged
merged 6 commits into from
Oct 14, 2024
Merged

feat: add playback monitoring #267

merged 6 commits into from
Oct 14, 2024

Conversation

amtins
Copy link
Member

@amtins amtins commented Sep 9, 2024

Description

Resolves #262, by allowing to track media playback sessions. With to the data sent, it will be possible to have a better overview of the quality of our service. Finally, it will help us to investigate potential causes of playback problems, so that we can better help our users or provide them with a more accurate response.

Changes made

  • rename analytics folder to trackers
  • add PillarboxMonitoring class
  • modify srgssr middleware to add support for new tracker
  • add unit test
  • extract srg-analytics player mock to make it reusable
  • rename test/analytics folder to test/trackers

Resolves #262, by allowing to track media playback sessions. With to the data
sent, it will be possible to have a better overview of the quality of our
service. Finally, it will help us to investigate potential causes of playback
problems, so that we can better help our users or provide them with a more
accurate response.

- rename `analytics` folder to `trackers`
- add `PillarboxMonitoring` class
- modify `srgssr` middleware to add support for new tracker
- add unit test
- extract `srg-analytics` player mock to make it reusable
- rename `test/analytics` folder to `test/trackers`
Copy link

github-actions bot commented Sep 9, 2024

PR Preview Action v1.4.8
Preview removed because the pull request was closed.
2024-10-14 15:09 UTC

Copy link

github-actions bot commented Sep 9, 2024

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements
98.1% (-0.62% 🔻)
825/841
🟢 Branches
92.96% (-2.78% 🔻)
383/412
🟢 Functions
98.67% (-0.75% 🔻)
223/226
🟢 Lines
98.49% (-0.66% 🔻)
782/794
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / PillarboxMonitoring.js
96.14% 84.16% 96.08% 96.5%
🟢
... / SRGAnalytics.js
97.5% 90.16% 100% 98.3%

Test suite run success

247 tests passing in 10 suites.

Report generated by 🧪jest coverage report action from dccfca7

src/middleware/srgssr.js Outdated Show resolved Hide resolved
* @param {Event} [event] The event that triggered the stop. This is passed
* to the reset function.
*/
sessionStop(event) {
Copy link
Contributor

@jboix jboix Sep 24, 2024

Choose a reason for hiding this comment

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

It looks like sessionStop can be called multiple times under different conditions and events: loadStart, sessionStart, player dispose, beforeUnload... However, there’s no check in sessionStop to ensure the stop signal is only sent once per session. Maybe we can mitigate this by doing:

sessionStop(event) {
    if (this.sessionStopped) return;

    // ...

    this.sessionStopped = true;  // Mark session as stopped
}

And then when we send the start event:

loadedData() {
    // ...
    
    this.sessionStopped = false; 
}

* Starts a new session by first stopping the previous session, then resetting
* the session start timestamp and media ID to their new values.
*/
sessionStart() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest a name here too, I find it inconsistent that:

  • sessionStop: Sends the stop event and resets the state of the session.
  • sessionStart: Starts tracking the session but doesn't send the start event.

I would suggests something like initSessionTracking or initMetricsTracking.

// active, we still want to send the STOP event so that it is properly
// stopped.
if (
(this.isTrackerDisabled() && !this.currentSessionId) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like a lot of this logic can be simplified and decoupled from this class by introducing a state machine pattern, I would suggest something like this:

class SessionStateMachine {
  constructor() {
    this.state = 'INITIAL';  // Initial state
  }

  get isInitial() {
    return this.state === 'INITIAL';
  }

  startSession() {
    if (this.isInitial) return false;
    this.state = 'SESSION_STARTED';
    return true;
  }

  get isSessionStarted() {
    return this.state === 'SESSION_STARTED';
  }

  endSession() {
    if (this.isSessionStarted) return false;
    this.state = 'SESSION_ENDED';
    return true;
  }

  errorSession() {
    if (this.state !== 'SESSION_STARTED') return false;
    this.state = 'SESSION_IN_ERROR';
    return true;
  }

  get isSessionStopped() {
    return this.state === 'SESSION_IN_ERROR' ||
           this.state === 'SESSION_ENDED';
  }

  resetSession() {
    if (this.isSessionStopped) return false;
    this.state = 'INITIAL';
    return true;
  }
}

Then you could simply check the machine state here:

if (!this.state.sessionStarted) return;

Resolves #269, sending the number of frame drops during the media playback
session.

- adds `frame_drops` property
- adds the `getVideoPlaybackQuality` function to the player mock
This fix mainly conforms to the latest version of the specification, as some
values were not in capital case.

- srgssr middleware: rename tracker instance from `srgMonitoring` to
`pillarboxMonitoring`
- srgssr middleware: start a session directly by calling the `sessionStart`
function instead of sending an event
- pillarbox-monitoring: delete `pillarbox-monitoring/sessionstart` event
- pillarbox-monitoring: stringify error log
- srgssr middleware: add test cases for tracker initialization
@MGaetan89 MGaetan89 linked an issue Oct 4, 2024 that may be closed by this pull request
1 task
@amtins
Copy link
Member Author

amtins commented Oct 14, 2024

After a discussion with @jboix, it's not impossible that in a future iteration this class will be extracted into a plugin/component.

@amtins amtins merged commit 2b31e9b into main Oct 14, 2024
5 checks passed
@amtins amtins deleted the feat/qos-tracker branch October 14, 2024 15:09
Copy link

🎉 This PR is included in version 1.14.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Update monitoring data format Gather QoS data
2 participants