Skip to content

Commit

Permalink
0xcadams/warnings (#559)
Browse files Browse the repository at this point in the history
* fix: moved warnings to a separate counter and event type

* chore: changeset

* test: fix tests
  • Loading branch information
0xcadams authored Jun 21, 2024
1 parent 443467f commit dff0c23
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 20 deletions.
8 changes: 8 additions & 0 deletions .changeset/ninety-mangos-end.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 12 additions & 6 deletions packages/core/src/media/metrics-new.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const getDummyPlaybackEvent = (
timestamp: Date.now(),
type,
errors: 0,
warnings: 0,
autoplay_status: "autoplay",
stalled_count: 1,
waiting_count: 0,
Expand All @@ -27,8 +28,8 @@ const getDummyPlaybackEvent = (
: {
timestamp: Date.now(),
type,
error_message: "Error",
category: "fallback",
message: "Error",
category: "access-control",
};

describe("PlaybackEventBuffer", () => {
Expand All @@ -53,6 +54,7 @@ describe("PlaybackEventBuffer", () => {
"timestamp": 1643673600000,
"type": "heartbeat",
"waiting_count": 0,
"warnings": 0,
},
]
`);
Expand Down Expand Up @@ -83,6 +85,7 @@ describe("PlaybackEventBuffer", () => {
"timestamp": 1643673600000,
"type": "heartbeat",
"waiting_count": 0,
"warnings": 0,
},
]
`);
Expand Down Expand Up @@ -119,6 +122,7 @@ describe("PlaybackEventBuffer", () => {
"timestamp": 1643673600000,
"type": "heartbeat",
"waiting_count": 0,
"warnings": 0,
}
`);
});
Expand All @@ -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",
}
Expand All @@ -156,6 +160,7 @@ describe("PlaybackEventBuffer", () => {
"timestamp": 1643673600000,
"type": "heartbeat",
"waiting_count": 0,
"warnings": 0,
}
`);
});
Expand All @@ -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",
}
Expand All @@ -193,6 +198,7 @@ describe("PlaybackEventBuffer", () => {
"timestamp": 1643673600000,
"type": "heartbeat",
"waiting_count": 0,
"warnings": 0,
}
`);
});
Expand Down
61 changes: 47 additions & 14 deletions packages/core/src/media/metrics-new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -140,6 +148,7 @@ export type VideoQualityEvent = {
export type PlaybackEvent =
| HeartbeatEvent
| ErrorEvent
| WarningEvent
| ClipEvent
| HtmlEvent
| RateChangeEvent
Expand Down Expand Up @@ -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,
},
);
}
},
);
Expand Down Expand Up @@ -357,6 +375,7 @@ export function addMetricsToStore(

const ic = new IncrementalCounter([
"errors",
"warnings",
"stalled_count",
"waiting_count",
"time_errored_ms",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -765,6 +788,7 @@ type RawMetrics = {

duration: number | null;
errorCount: number;
warningCount: number;
offset: number | null;
playerHeight: number | null;
playerWidth: number | null;
Expand Down Expand Up @@ -807,6 +831,7 @@ class MetricsMonitor {

duration: null,
errorCount: 0,
warningCount: 0,
offset: null,
playerHeight: null,
playerWidth: null,
Expand Down Expand Up @@ -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();
}
}
},
);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit dff0c23

Please sign in to comment.