From 50e7545e62fc09157a1f96acd99ad6af364d72e4 Mon Sep 17 00:00:00 2001 From: Eric Doughty-Papassideris Date: Fri, 13 Dec 2024 19:53:45 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20back:=20preparing=20attempt=20at?= =?UTF-8?q?=20route=20statistics,=20non=20functional=20without=20fastify?= =?UTF-8?q?=20upgrade=20(#762)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/services/diagnostics/index.ts | 3 +++ .../services/diagnostics/web/provider.ts | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tdrive/backend/node/src/core/platform/services/diagnostics/web/provider.ts diff --git a/tdrive/backend/node/src/core/platform/services/diagnostics/index.ts b/tdrive/backend/node/src/core/platform/services/diagnostics/index.ts index 95fe4d59..35217965 100644 --- a/tdrive/backend/node/src/core/platform/services/diagnostics/index.ts +++ b/tdrive/backend/node/src/core/platform/services/diagnostics/index.ts @@ -8,6 +8,7 @@ import diagnostics, { getConfig as getDiagnosticsGetConfig, TDiagnosticTag, } from "../../framework/api/diagnostics"; +import registerFastifyRoutesDiagnosticsProvider from "./web/provider"; /** * The diagnostics service exposes endpoint that are of use for operational reasons. @@ -29,7 +30,9 @@ export default class DiagnosticsService extends TdriveService { this.service = new DiagnosticsServiceImpl(); const fastify = this.context.getProvider("webserver").getServer(); + registerBasicProviders(); + registerFastifyRoutesDiagnosticsProvider(fastify); fastify.register((instance, _opts, next) => { web(instance, { prefix: this.prefix }); diff --git a/tdrive/backend/node/src/core/platform/services/diagnostics/web/provider.ts b/tdrive/backend/node/src/core/platform/services/diagnostics/web/provider.ts new file mode 100644 index 00000000..87a543a9 --- /dev/null +++ b/tdrive/backend/node/src/core/platform/services/diagnostics/web/provider.ts @@ -0,0 +1,23 @@ +import diagnostics from "../../../framework/api/diagnostics"; + +export default fastify => { + // TODO: registering @fastify/routes-stats creates errors (performance mark not found) + // on the request performance marks, the hook doesn't seem to be called for every route + // and some of the more important ones like browse start failing... + // Version tested had to be 3.4.0 because 4+ needs Fastify 5. + return; + // Don't require it at all until it's fixed + // eslint-disable-next-line @typescript-eslint/no-var-requires + fastify.register(require("@fastify/routes-stats"), { + printInterval: 4000, // milliseconds + decoratorName: "performanceMarked", // decorator is set to true if a performace.mark was called for the request + }); + diagnostics.registerProviders({ + key: "fastify-routes", + tags: ["stats", "stats-full"], + async get() { + fastify.measurements(); + return { ok: true, ...fastify.stats() }; + }, + }); +};