Skip to content

Commit

Permalink
feat: add profiler server (#376)
Browse files Browse the repository at this point in the history
* feat: add profiler server

* ci: docker compose
  • Loading branch information
rafaelcr authored Sep 17, 2024
1 parent a625224 commit ced2cd0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 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.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"generate:docs": "redoc-cli build --output ./tmp/index.html ./tmp/openapi.yaml",
"generate:git-info": "rimraf .git-info && node_modules/.bin/api-toolkit-git-info",
"generate:vercel": "npm run generate:git-info && npm run generate:openapi && npm run generate:docs",
"testenv:run": "docker-compose -f docker/docker-compose.dev.postgres.yml up",
"testenv:stop": "docker-compose -f docker/docker-compose.dev.postgres.yml down -v -t 0",
"testenv:logs": "docker-compose -f docker/docker-compose.dev.postgres.yml logs -t -f",
"testenv:run": "docker compose -f docker/docker-compose.dev.postgres.yml up",
"testenv:stop": "docker compose -f docker/docker-compose.dev.postgres.yml down -v -t 0",
"testenv:logs": "docker compose -f docker/docker-compose.dev.postgres.yml logs -t -f",
"generate:client:typescript": "swagger-codegen generate -i ./tmp/openapi.yaml -l typescript-fetch -o ./client/typescript -c ./client/typescript.json"
},
"prettier": "@stacks/prettier-config",
Expand Down 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 ced2cd0

Please sign in to comment.