From dff0c2353d4267e70a4f58ef560d8f429f3f2685 Mon Sep 17 00:00:00 2001 From: Chase Adams Date: Fri, 21 Jun 2024 10:31:41 -0700 Subject: [PATCH] 0xcadams/warnings (#559) * fix: moved warnings to a separate counter and event type * chore: changeset * test: fix tests --- .changeset/ninety-mangos-end.md | 8 +++ packages/core/src/media/metrics-new.test.ts | 18 ++++-- packages/core/src/media/metrics-new.ts | 61 ++++++++++++++++----- 3 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 .changeset/ninety-mangos-end.md diff --git a/.changeset/ninety-mangos-end.md b/.changeset/ninety-mangos-end.md new file mode 100644 index 00000000..4fa214e7 --- /dev/null +++ b/.changeset/ninety-mangos-end.md @@ -0,0 +1,8 @@ +--- +"@livepeer/core-react": patch +"@livepeer/core-web": patch +"@livepeer/react": patch +"@livepeer/core": patch +--- + +**Fix:** moved `warning` events to `warning` event type and counter. diff --git a/packages/core/src/media/metrics-new.test.ts b/packages/core/src/media/metrics-new.test.ts index a876cecf..f1dc13a0 100644 --- a/packages/core/src/media/metrics-new.test.ts +++ b/packages/core/src/media/metrics-new.test.ts @@ -16,6 +16,7 @@ const getDummyPlaybackEvent = ( timestamp: Date.now(), type, errors: 0, + warnings: 0, autoplay_status: "autoplay", stalled_count: 1, waiting_count: 0, @@ -27,8 +28,8 @@ const getDummyPlaybackEvent = ( : { timestamp: Date.now(), type, - error_message: "Error", - category: "fallback", + message: "Error", + category: "access-control", }; describe("PlaybackEventBuffer", () => { @@ -53,6 +54,7 @@ describe("PlaybackEventBuffer", () => { "timestamp": 1643673600000, "type": "heartbeat", "waiting_count": 0, + "warnings": 0, }, ] `); @@ -83,6 +85,7 @@ describe("PlaybackEventBuffer", () => { "timestamp": 1643673600000, "type": "heartbeat", "waiting_count": 0, + "warnings": 0, }, ] `); @@ -119,6 +122,7 @@ describe("PlaybackEventBuffer", () => { "timestamp": 1643673600000, "type": "heartbeat", "waiting_count": 0, + "warnings": 0, } `); }); @@ -138,8 +142,8 @@ describe("PlaybackEventBuffer", () => { expect(events[events.length - 1]).toMatchInlineSnapshot(` { - "category": "fallback", - "error_message": "Error", + "category": "access-control", + "message": "Error", "timestamp": 1643673600000, "type": "error", } @@ -156,6 +160,7 @@ describe("PlaybackEventBuffer", () => { "timestamp": 1643673600000, "type": "heartbeat", "waiting_count": 0, + "warnings": 0, } `); }); @@ -175,8 +180,8 @@ describe("PlaybackEventBuffer", () => { expect(events[events.length - 1]).toMatchInlineSnapshot(` { - "category": "fallback", - "error_message": "Error", + "category": "access-control", + "message": "Error", "timestamp": 1643673600000, "type": "error", } @@ -193,6 +198,7 @@ describe("PlaybackEventBuffer", () => { "timestamp": 1643673600000, "type": "heartbeat", "waiting_count": 0, + "warnings": 0, } `); }); diff --git a/packages/core/src/media/metrics-new.ts b/packages/core/src/media/metrics-new.ts index 951e7e19..8e734b8e 100644 --- a/packages/core/src/media/metrics-new.ts +++ b/packages/core/src/media/metrics-new.ts @@ -19,6 +19,8 @@ export type HeartbeatEvent = { timestamp: number; /** The number of errors that have occurred since last heartbeat. */ errors: number; + /** The number of warnings that have occurred since last heartbeat. */ + warnings: number; /** The number of times the current playback has stalled, since last heartbeat. */ stalled_count: number; @@ -73,14 +75,20 @@ export type ErrorEvent = { /** The timestamp of the event, in milliseconds. */ timestamp: number; /** The raw event error message. */ - error_message: string; + message: string; /** The category of the error. */ - category: - | "offline" - | "access-control" - | "fallback" - | "permissions" - | "unknown"; + category: "access-control" | "permissions" | "unknown"; +}; + +export type WarningEvent = { + /** The event type. */ + type: "warning"; + /** The timestamp of the event, in milliseconds. */ + timestamp: number; + /** The raw event warning message. */ + message: string; + /** The category of the warning. */ + category: "offline" | "fallback"; }; export type HtmlEvent = { @@ -140,6 +148,7 @@ export type VideoQualityEvent = { export type PlaybackEvent = | HeartbeatEvent | ErrorEvent + | WarningEvent | ClipEvent | HtmlEvent | RateChangeEvent @@ -234,12 +243,21 @@ export function addMetricsToStore( (state) => state.error, async (error) => { if (error) { - eventBuffer.addEvent({ - type: "error", - timestamp: Date.now(), - category: error.type, - error_message: error.message, - }); + eventBuffer.addEvent( + error.type === "offline" || error.type === "fallback" + ? { + type: "warning", + timestamp: Date.now(), + category: error.type, + message: error.message, + } + : { + type: "error", + timestamp: Date.now(), + category: error.type, + message: error.message, + }, + ); } }, ); @@ -357,6 +375,7 @@ export function addMetricsToStore( const ic = new IncrementalCounter([ "errors", + "warnings", "stalled_count", "waiting_count", "time_errored_ms", @@ -415,6 +434,10 @@ export function addMetricsToStore( type: "heartbeat", timestamp: Date.now(), errors: ic.calculateIncrement("errors", metricsSnapshot.errorCount), + warnings: ic.calculateIncrement( + "warnings", + metricsSnapshot.warningCount, + ), stalled_count: ic.calculateIncrement( "stalled_count", @@ -765,6 +788,7 @@ type RawMetrics = { duration: number | null; errorCount: number; + warningCount: number; offset: number | null; playerHeight: number | null; playerWidth: number | null; @@ -807,6 +831,7 @@ class MetricsMonitor { duration: null, errorCount: 0, + warningCount: 0, offset: null, playerHeight: null, playerWidth: null, @@ -896,7 +921,11 @@ class MetricsMonitor { this.timerErrored.start(); this.timerPlaying.stop(); - this.addError(); + if (error.type === "offline" || error.type === "fallback") { + this.addWarning(); + } else { + this.addError(); + } } }, ); @@ -935,6 +964,10 @@ class MetricsMonitor { this.currentMetrics.errorCount = this.currentMetrics.errorCount + 1; } + addWarning() { + this.currentMetrics.warningCount = this.currentMetrics.warningCount + 1; + } + setConnected(isConnected: boolean) { this.connected = isConnected; }