add 0013-metrics-track-unidentified-innertube-errors.patch and 0014-metrics-add-more-errors.patch
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m7s

This commit is contained in:
Fijxu 2025-04-15 19:38:33 -04:00
parent 8fb25fa658
commit a47a5e5cd5
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
15 changed files with 212 additions and 102 deletions

View file

@ -1,7 +1,7 @@
From f813d76c7b7b3e2627c1a5819540df0273e92432 Mon Sep 17 00:00:00 2001 From 6097b8cf2bb2369e28cb360578f10796a60c7795 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Mon, 24 Mar 2025 19:37:34 -0300 Date: Mon, 24 Mar 2025 19:37:34 -0300
Subject: [PATCH 01/14] ci: update deno to 2.2.10 Subject: [PATCH 01/15] ci: update deno to 2.2.10
--- ---
Dockerfile | 2 +- Dockerfile | 2 +-

View file

@ -1,7 +1,7 @@
From dcb9a4c1f8a3a4f41616fc0b71f3d0bd18e1cc84 Mon Sep 17 00:00:00 2001 From 47ce40eddb29252a3e3a92861db1dd131de3f594 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Mon, 24 Mar 2025 18:44:10 -0300 Date: Mon, 24 Mar 2025 18:44:10 -0300
Subject: [PATCH 02/14] feat: add support for an external videoplayback proxy Subject: [PATCH 02/15] feat: add support for an external videoplayback proxy
--- ---
config/config.example.toml | 1 + config/config.example.toml | 1 +

View file

@ -1,7 +1,7 @@
From e5c325ce9068bad9b703d4303955525cfa6fa02b Mon Sep 17 00:00:00 2001 From 4f44c539943140ac416989f11eee5a98c5a52d3b Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Mon, 24 Mar 2025 18:52:53 -0300 Date: Mon, 24 Mar 2025 18:52:53 -0300
Subject: [PATCH 03/14] feat: report the external videoplayback proxy via /info Subject: [PATCH 03/15] feat: report the external videoplayback proxy via /info
endpoint endpoint
--- ---

View file

@ -1,7 +1,7 @@
From 02c6d11dddeb5b4517749efb9649715e060c39b3 Mon Sep 17 00:00:00 2001 From 72b7cc213b4afe510f530990f252913c0003af15 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Mon, 24 Mar 2025 19:02:01 -0300 Date: Mon, 24 Mar 2025 19:02:01 -0300
Subject: [PATCH 04/14] feat: add resolution limit on DASH streams to save Subject: [PATCH 04/15] feat: add resolution limit on DASH streams to save
bandwidth bandwidth
--- ---

View file

@ -1,7 +1,7 @@
From c4d1b1a5237519f61bd1b2f4f710c4ff121ae044 Mon Sep 17 00:00:00 2001 From 459e129d76649ab6f542997bfbe9a2ff479ade85 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Mon, 24 Mar 2025 19:06:04 -0300 Date: Mon, 24 Mar 2025 19:06:04 -0300
Subject: [PATCH 05/14] feat: add env variable to set verify_requests Subject: [PATCH 05/15] feat: add env variable to set verify_requests
--- ---
src/lib/helpers/config.ts | 4 +++- src/lib/helpers/config.ts | 4 +++-

View file

@ -1,7 +1,7 @@
From 4c15fe0647cdb65dd5096abd0055f551fb1279d9 Mon Sep 17 00:00:00 2001 From 756b8f855e2dd075c3fbe2608d42e65a0d1ff75e Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Mon, 24 Mar 2025 19:20:52 -0300 Date: Mon, 24 Mar 2025 19:20:52 -0300
Subject: [PATCH 06/14] feat: add support for multiple proxies Subject: [PATCH 06/15] feat: add support for multiple proxies
--- ---
src/lib/helpers/getFetchClient.ts | 17 ++++++++++++++++- src/lib/helpers/getFetchClient.ts | 17 ++++++++++++++++-

View file

@ -1,7 +1,7 @@
From 04b2d1b14e126f110239603f897b837f25c46461 Mon Sep 17 00:00:00 2001 From 430f56a70febeb210b3fa778dea723b0d8bb0544 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Mon, 24 Mar 2025 20:34:33 -0300 Date: Mon, 24 Mar 2025 20:34:33 -0300
Subject: [PATCH 07/14] feat: add option to disable potoken generation check Subject: [PATCH 07/15] feat: add option to disable potoken generation check
--- ---
config/config.example.toml | 1 + config/config.example.toml | 1 +

View file

@ -1,7 +1,7 @@
From 57e891ca1e0405bfeb4d73114098d89d75149caf Mon Sep 17 00:00:00 2001 From bd911e4a62caf445c6130b88a15a0a4320ba7cb4 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Tue, 25 Mar 2025 00:04:47 -0300 Date: Tue, 25 Mar 2025 00:04:47 -0300
Subject: [PATCH 08/14] add proxy retries on innertube error Subject: [PATCH 08/15] add proxy retries on innertube error
--- ---
src/lib/helpers/config.ts | 1 + src/lib/helpers/config.ts | 1 +

View file

@ -1,7 +1,7 @@
From 44b89748a577274682f291ab05097acad0488151 Mon Sep 17 00:00:00 2001 From d821439a2acc0b9372ce85092d0a97d640db6e86 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Tue, 25 Mar 2025 00:07:28 -0300 Date: Tue, 25 Mar 2025 00:07:28 -0300
Subject: [PATCH 09/14] add metrics for proxy retries Subject: [PATCH 09/15] add metrics for proxy retries
--- ---
src/lib/helpers/metrics.ts | 5 +++++ src/lib/helpers/metrics.ts | 5 +++++

View file

@ -1,7 +1,7 @@
From 6f91b54bdf136d57100c7522e81495d1d918807d Mon Sep 17 00:00:00 2001 From aa870191d360deb13242ed9ed850cc3a84e3c17f Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Tue, 25 Mar 2025 00:24:07 -0300 Date: Tue, 25 Mar 2025 00:24:07 -0300
Subject: [PATCH 10/14] fix: fix tokio overflow on compile Subject: [PATCH 10/15] fix: fix tokio overflow on compile
--- ---
Dockerfile | 2 ++ Dockerfile | 2 ++

View file

@ -1,7 +1,7 @@
From 006b487781fb692ffd2e7079415c1138386b42cd Mon Sep 17 00:00:00 2001 From 94a10f097341f2118ab8b67cb47802a115b2141f Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Wed, 26 Mar 2025 12:24:49 -0300 Date: Wed, 26 Mar 2025 12:24:49 -0300
Subject: [PATCH 11/14] Add environment variable for youtube_session.frequency Subject: [PATCH 11/15] Add environment variable for youtube_session.frequency
--- ---
src/lib/helpers/config.ts | 4 +++- src/lib/helpers/config.ts | 4 +++-

View file

@ -1,7 +1,7 @@
From f183210a4d5448418386ad1a4f47eb4235d31e16 Mon Sep 17 00:00:00 2001 From faf7a41daae9c470a4d9eefdb92f626ed91ac4b5 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Tue, 8 Apr 2025 02:21:10 -0400 Date: Tue, 8 Apr 2025 02:21:10 -0400
Subject: [PATCH 12/14] add option to disable logging Subject: [PATCH 12/15] add option to disable logging
--- ---
src/lib/helpers/config.ts | 7 ++++++- src/lib/helpers/config.ts | 7 ++++++-

View file

@ -1,46 +1,21 @@
From 47c2f3b7d94185f96d2e2e0e576b83b92a7d35f2 Mon Sep 17 00:00:00 2001 From dc22979ab91e2275f367823d9babe7b9fc3d0301 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Wed, 9 Apr 2025 13:37:16 -0400 Date: Mon, 14 Apr 2025 01:24:57 -0400
Subject: [PATCH 13/14] metrics: track unidentified innertube errors Subject: [PATCH 13/15] metrics: track unidentified innertube errors
--- ---
src/lib/helpers/config.ts | 4 ++ src/lib/helpers/metrics.ts | 142 +++++++++++++++++++++++++++++--------
src/lib/helpers/metrics.ts | 117 +++++++++++++++++++++++++++++++------ 1 file changed, 111 insertions(+), 31 deletions(-)
src/main.ts | 4 +-
3 files changed, 106 insertions(+), 19 deletions(-)
diff --git a/src/lib/helpers/config.ts b/src/lib/helpers/config.ts
index acb04bb..20e5560 100644
--- a/src/lib/helpers/config.ts
+++ b/src/lib/helpers/config.ts
@@ -23,6 +23,10 @@ export const ConfigSchema = z.object({
disable_logs: z.boolean().default(
Deno.env.get("SERVER_DISABLE_LOGS") === "true" || false,
),
+ track_unknown_innertube_errors: z.boolean().default(
+ Deno.env.get("SERVER_TRACK_UNKNOWN_INNERTUBE_ERRORS") === "true" ||
+ false,
+ ),
}).strict().default({}),
cache: z.object({
enabled: z.boolean().default(true),
diff --git a/src/lib/helpers/metrics.ts b/src/lib/helpers/metrics.ts diff --git a/src/lib/helpers/metrics.ts b/src/lib/helpers/metrics.ts
index 5dee540..c22c792 100644 index 5dee540..2464fe7 100644
--- a/src/lib/helpers/metrics.ts --- a/src/lib/helpers/metrics.ts
+++ b/src/lib/helpers/metrics.ts +++ b/src/lib/helpers/metrics.ts
@@ -2,14 +2,24 @@ import { IRawResponse } from "youtubei.js"; @@ -5,11 +5,16 @@ export class Metrics {
import { Counter, Registry } from "prom-client";
export class Metrics {
+ trackUnknownInnertubeErrors: boolean;
private METRICS_PREFIX = "invidious_companion_"; private METRICS_PREFIX = "invidious_companion_";
public register = new Registry(); public register = new Registry();
- public createCounter(name: string, help?: string): Counter { - public createCounter(name: string, help?: string): Counter {
+ constructor(trackUnknownInnertubeErrors: boolean) {
+ this.trackUnknownInnertubeErrors = trackUnknownInnertubeErrors;
+ }
+
+ public createCounter( + public createCounter(
+ name: string, + name: string,
+ help?: string, + help?: string,
@ -54,7 +29,7 @@ index 5dee540..c22c792 100644
}); });
} }
@@ -26,6 +36,7 @@ export class Metrics { @@ -26,6 +31,7 @@ export class Metrics {
private innertubeErrorStatusUnknown = this.createCounter( private innertubeErrorStatusUnknown = this.createCounter(
"innertube_error_status_unknown_total", "innertube_error_status_unknown_total",
"Number of times that an unknown status has been returned by Innertube API", "Number of times that an unknown status has been returned by Innertube API",
@ -62,7 +37,21 @@ index 5dee540..c22c792 100644
); );
private innertubeErrorReasonSignIn = this.createCounter( private innertubeErrorReasonSignIn = this.createCounter(
@@ -66,26 +77,62 @@ export class Metrics { @@ -41,11 +47,13 @@ export class Metrics {
private innertubeErrorReasonUnknown = this.createCounter(
"innertube_error_reason_unknown_total",
"Number of times that an unknown reason has been returned by the Innertube API",
+ ["error"],
);
private innertubeErrorSubreasonUnknown = this.createCounter(
"innertube_error_subreason_unknown_total",
"Number of times that an unknown subreason has been returned by the Innertube API",
+ ["error"],
);
public innertubeSuccessfulRequest = this.createCounter(
@@ -66,26 +74,70 @@ export class Metrics {
private checkStatus(videoData: IRawResponse) { private checkStatus(videoData: IRawResponse) {
const status = videoData.playabilityStatus?.status; const status = videoData.playabilityStatus?.status;
@ -90,6 +79,8 @@ index 5dee540..c22c792 100644
+ case "UNPLAYABLE": + case "UNPLAYABLE":
+ error.unplayable = true; + error.unplayable = true;
+ return error; + return error;
+ // Sensitive content videos
+ // Example video id: `VuSU7PcEKpU`
+ case "CONTENT_CHECK_REQUIRED": + case "CONTENT_CHECK_REQUIRED":
+ error.contentCheckRequired = true; + error.contentCheckRequired = true;
+ return error; + return error;
@ -103,8 +94,8 @@ index 5dee540..c22c792 100644
} }
private checkReason(videoData: IRawResponse) { private checkReason(videoData: IRawResponse) {
const reason = videoData.playabilityStatus?.reason; - const reason = videoData.playabilityStatus?.reason;
-
- return { - return {
- signInToConfirmAge: reason?.includes( - signInToConfirmAge: reason?.includes(
- "Sign in to confirm your age", - "Sign in to confirm your age",
@ -112,6 +103,13 @@ index 5dee540..c22c792 100644
- SignInToConfirmBot: reason?.includes( - SignInToConfirmBot: reason?.includes(
- "Sign in to confirm youre not a bot", - "Sign in to confirm youre not a bot",
- ), - ),
+ // On specific status like `CONTENT_CHECK_REQUIRED`, the reason is
+ // contained inside `errorScreen`, just like how we check subReason.
+ const reason = videoData.playabilityStatus?.reason ||
+ videoData.playabilityStatus?.errorScreen
+ ?.playerErrorMessageRenderer
+ ?.reason?.simpleText;
+
+ interface Error { + interface Error {
+ signInToConfirmAge: boolean; + signInToConfirmAge: boolean;
+ SignInToConfirmBot: boolean; + SignInToConfirmBot: boolean;
@ -125,12 +123,13 @@ index 5dee540..c22c792 100644
}; };
+ +
+ switch (true) { + switch (true) {
+ case reason?.includes("Sign in to confirm your age"):
+ error.signInToConfirmAge = true;
+ return error;
+ case reason?.includes("Sign in to confirm youre not a bot"): + case reason?.includes("Sign in to confirm youre not a bot"):
+ error.SignInToConfirmBot = true; + error.SignInToConfirmBot = true;
+ return error; + return error;
+ // Age restricted videos
+ case reason?.includes("Sign in to confirm your age"):
+ error.signInToConfirmAge = true;
+ return error;
+ default: + default:
+ error.unknown = reason; + error.unknown = reason;
+ return error; + return error;
@ -138,7 +137,7 @@ index 5dee540..c22c792 100644
} }
private checkSubreason(videoData: IRawResponse) { private checkSubreason(videoData: IRawResponse) {
@@ -93,17 +140,51 @@ export class Metrics { @@ -93,39 +145,67 @@ export class Metrics {
?.playerErrorMessageRenderer ?.playerErrorMessageRenderer
?.subreason?.runs?.[0]?.text; ?.subreason?.runs?.[0]?.text;
@ -168,47 +167,59 @@ index 5dee540..c22c792 100644
public checkInnertubeResponse(videoData: IRawResponse) { public checkInnertubeResponse(videoData: IRawResponse) {
this.innertubeFailedRequest.inc(); this.innertubeFailedRequest.inc();
const status = this.checkStatus(videoData); - const status = this.checkStatus(videoData);
+ if (this.trackUnknownInnertubeErrors) { + const status = this.checkStatus(videoData);
+ if (status?.unknown) {
+ this.innertubeErrorStatusUnknown.labels({
+ error: status.unknown,
+ }).inc();
+ const reason = this.checkReason(videoData);
+ if (reason) {
+ this.innertubeErrorReasonUnknown.labels({
+ error: status.unknown,
+ }).inc();
+ const subReason = this.checkSubreason(videoData);
+ if (subReason) {
+ this.innertubeErrorStatusUnknown.labels({
+ error: status.unknown,
+ }).inc();
+ }
+ }
+ return;
+ }
+ }
+
if (status.contentCheckRequired || status.unplayable) return; if (status.contentCheckRequired || status.unplayable) return;
+ if (status?.unknown) {
+ this.innertubeErrorStatusUnknown.labels({
+ error: status.unknown,
+ }).inc();
+ }
+
+ const reason = this.checkReason(videoData);
+ if (reason.signInToConfirmAge) return;
+
+ if (reason.unknown) {
+ this.innertubeErrorReasonUnknown.labels({
+ error: reason.unknown,
+ }).inc();
+ }
+
+ // On specific `playabilityStatus.status` like `CONTENT_CHECK_REQUIRED`,
+ // `subReason` doesn't come with a `playabilityStatus.reason`
+ // key. So we need to check this separately from `reason`
+ const subReason = this.checkSubreason(videoData);
+ if (subReason.unknown) {
+ this.innertubeErrorSubreasonUnknown.labels({
+ error: subReason.unknown,
+ }).inc();
+ }
+
if (status.loginRequired) { if (status.loginRequired) {
diff --git a/src/main.ts b/src/main.ts this.innertubeErrorStatusLoginRequired.inc();
index f659d97..84ef286 100644 - const reason = this.checkReason(videoData);
--- a/src/main.ts -
+++ b/src/main.ts - if (reason.signInToConfirmAge) return;
@@ -27,7 +27,9 @@ declare module "hono" {
interface ContextVariableMap extends HonoVariables {}
}
const app = new Hono();
-const metrics = config.server.enable_metrics ? new Metrics() : undefined;
+const metrics = config.server.enable_metrics
+ ? new Metrics(config.server.track_unknown_innertube_errors)
+ : undefined;
let tokenMinter: TokenMinter; if (reason.SignInToConfirmBot) {
let innertubeClient: Innertube; this.innertubeErrorReasonSignIn.inc();
- const subReason = this.checkSubreason(videoData);
if (subReason.thisHelpsProtectCommunity) {
this.innertubeErrorSubreasonProtectCommunity.inc();
- } else {
- this.innertubeErrorSubreasonUnknown.inc();
}
- } else {
- this.innertubeErrorReasonUnknown.inc();
}
- } else {
- this.innertubeErrorStatusUnknown.inc();
}
}
}
-- --
2.49.0 2.49.0

View file

@ -0,0 +1,99 @@
From f99728a40b9950a1130d99ee2a6ef29768f3afc9 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net>
Date: Mon, 14 Apr 2025 01:25:40 -0400
Subject: [PATCH 14/15] metrics: add more errors
Added reason and subreason for sentitive content videos ("CONTENT_CHECK_REQUIRED")
fix: fix typo: `SignInToConfirmBot` -> `signInToConfirmBot`
---
src/lib/helpers/metrics.ts | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/src/lib/helpers/metrics.ts b/src/lib/helpers/metrics.ts
index 2464fe7..e1b0b73 100644
--- a/src/lib/helpers/metrics.ts
+++ b/src/lib/helpers/metrics.ts
@@ -116,24 +116,32 @@ export class Metrics {
interface Error {
signInToConfirmAge: boolean;
- SignInToConfirmBot: boolean;
+ signInToConfirmBot: boolean;
+ selfHarmTopics: boolean;
unknown: string | undefined;
}
const error: Error = {
signInToConfirmAge: false,
- SignInToConfirmBot: false,
+ signInToConfirmBot: false,
+ selfHarmTopics: false,
unknown: undefined,
};
switch (true) {
case reason?.includes("Sign in to confirm youre not a bot"):
- error.SignInToConfirmBot = true;
+ error.signInToConfirmBot = true;
return error;
// Age restricted videos
case reason?.includes("Sign in to confirm your age"):
error.signInToConfirmAge = true;
return error;
+ // For videos with playabilityStatus.status == `CONTENT_CHECK_REQUIRED`
+ case reason?.includes(
+ "The following content may contain suicide or self-harm topics",
+ ):
+ error.selfHarmTopics = true;
+ return error;
default:
error.unknown = reason;
return error;
@@ -147,11 +155,15 @@ export class Metrics {
interface Error {
thisHelpsProtectCommunity: boolean;
+ thisVideoMayBeInnapropiate: boolean;
+ viewerDiscretionAdvised: boolean;
unknown: string | undefined;
}
const error: Error = {
thisHelpsProtectCommunity: false,
+ thisVideoMayBeInnapropiate: false,
+ viewerDiscretionAdvised: false,
unknown: undefined,
};
@@ -159,6 +171,18 @@ export class Metrics {
case subReason?.includes("This helps protect our community"):
error.thisHelpsProtectCommunity = true;
return error;
+ // Age restricted videos
+ case subReason?.includes(
+ "This video may be inappropriate for some users",
+ ):
+ error.thisVideoMayBeInnapropiate = true;
+ return error;
+ // For videos with playabilityStatus.status == `CONTENT_CHECK_REQUIRED`
+ case subReason?.includes(
+ "Viewer discretion is advised",
+ ):
+ error.viewerDiscretionAdvised = true;
+ return error;
default:
error.unknown = subReason;
return error;
@@ -199,7 +223,7 @@ export class Metrics {
if (status.loginRequired) {
this.innertubeErrorStatusLoginRequired.inc();
- if (reason.SignInToConfirmBot) {
+ if (reason.signInToConfirmBot) {
this.innertubeErrorReasonSignIn.inc();
if (subReason.thisHelpsProtectCommunity) {
--
2.49.0

View file

@ -1,7 +1,7 @@
From bfb146eb36da60b3e5cb078ffb4b875e7a28887a Mon Sep 17 00:00:00 2001 From 5538e30c2aff030b667fdf7e8d79d77978bc9ba5 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net> From: Fijxu <fijxu@nadeko.net>
Date: Tue, 15 Apr 2025 19:20:52 -0400 Date: Tue, 15 Apr 2025 19:20:52 -0400
Subject: [PATCH 14/14] ci: improve container image build times Subject: [PATCH 15/15] ci: improve container image build times
--- ---
.github/workflows/docker-build-push.yaml | 2 ++ .github/workflows/docker-build-push.yaml | 2 ++