🚧 back: preparing attempt at route statistics, non functional without fastify upgrade (#762)
This commit is contained in:
@@ -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<DiagnosticsService
|
||||
public async doInit(): Promise<this> {
|
||||
this.service = new DiagnosticsServiceImpl();
|
||||
const fastify = this.context.getProvider<WebServerAPI>("webserver").getServer();
|
||||
|
||||
registerBasicProviders();
|
||||
registerFastifyRoutesDiagnosticsProvider(fastify);
|
||||
|
||||
fastify.register((instance, _opts, next) => {
|
||||
web(instance, { prefix: this.prefix });
|
||||
|
||||
@@ -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() };
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user