What
Similar to #4219, separate k6 metric generation from the browser module's core logic. Instead of pushing metrics from multiple goroutines, create a dedicated goroutine to manage metrics.
Why
- Prevent race condition issues, such as #5341 and #4203.
- Reduce flaky test runs, both in
k6 runs and CI (i.e., #5367).
- Separation of concerns.
How
- Delegate custom metric management to a new type out of the
common package.
- Listen for metric generation events from the core logic and push them to the metric system.
- Research whether these metrics should be pushed on the event loop and in another dedicated goroutine.