Skip to content

Commit

Permalink
feat: add profiler server
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Aug 19, 2024
1 parent 04abd6e commit 9099f76
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@fastify/multipart": "^7.1.0",
"@fastify/swagger": "^8.3.1",
"@fastify/type-provider-typebox": "^3.2.0",
"@hirosystems/api-toolkit": "^1.4.0",
"@hirosystems/api-toolkit": "^1.7.0",
"@hirosystems/chainhook-client": "^1.8.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^10.0.4",
Expand Down
2 changes: 2 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const schema = Type.Object({
EVENT_SERVER_BODY_LIMIT: Type.Integer({ default: 20971520 }),
/** Hostname that will be reported to the ordhook node so it can call us back with events */
EXTERNAL_HOSTNAME: Type.String({ default: '127.0.0.1' }),
/** Port in which to serve the profiler */
PROFILER_PORT: Type.Number({ default: 9119 }),

/** Hostname of the ordhook node we'll use to register predicates */
ORDHOOK_NODE_RPC_HOST: Type.String({ default: '127.0.0.1' }),
Expand Down
17 changes: 16 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { isProdEnv, logger, registerShutdownConfig } from '@hirosystems/api-toolkit';
import {
buildProfilerServer,
isProdEnv,
logger,
registerShutdownConfig,
} from '@hirosystems/api-toolkit';
import { buildApiServer, buildPromServer } from './api/init';
import { startOrdhookServer } from './ordhook/server';
import { ENV } from './env';
Expand Down Expand Up @@ -56,6 +61,16 @@ async function initApp() {
await initApiService(db);
}

const profilerServer = await buildProfilerServer();
registerShutdownConfig({
name: 'Profiler Server',
forceKillable: false,
handler: async () => {
await profilerServer.close();
},
});
await profilerServer.listen({ host: ENV.API_HOST, port: ENV.PROFILER_PORT });

registerShutdownConfig({
name: 'DB',
forceKillable: false,
Expand Down

0 comments on commit 9099f76

Please sign in to comment.