1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

feat: add capability to write heap snapshot. (#2611)

Is protected behind a config option called `enableHeapSnapshotEnpoint`.
When API endpoint is triggered it will write a heapSnapshot to disk.

Steps to create heap snapshot:

1. Add env variable `ENABLE_HEAP_SNAPSHOT_ENPOINT=true`. 
2. Call this endpoint: `/internal-backstage/heapSnapshot`
3. Download the created heapdump from the server. 

The snapshot can be loaded in the chrome dev-tool to analysis.
This commit is contained in:
Ivar Conradi Østhus 2022-12-08 11:25:39 +01:00 committed by GitHub
parent 353f50237d
commit d9d9f01b37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 0 deletions

View File

@ -126,6 +126,7 @@ exports[`should create default config 1`] = `
"server": {
"baseUriPath": "",
"cdnPrefix": undefined,
"enableHeapSnapshotEnpoint": false,
"enableRequestLogger": false,
"gracefulShutdownEnable": true,
"gracefulShutdownTimeout": 1000,

View File

@ -165,6 +165,10 @@ const defaultServerOption: IServerOption = {
cdnPrefix: process.env.CDN_PREFIX,
unleashUrl: process.env.UNLEASH_URL || 'http://localhost:4242',
serverMetrics: true,
enableHeapSnapshotEnpoint: parseEnvVarBoolean(
process.env.ENABLE_HEAP_SNAPSHOT_ENPOINT,
false,
),
keepAliveTimeout: minutesToMilliseconds(1),
headersTimeout: secondsToMilliseconds(61),
enableRequestLogger: false,

View File

@ -1,3 +1,4 @@
import { writeHeapSnapshot } from 'v8';
import { register as prometheusRegister } from 'prom-client';
import Controller from './controller';
import { IUnleashConfig } from '../types/option';
@ -16,6 +17,14 @@ class BackstageController extends Controller {
res.end(await prometheusRegister.metrics());
});
}
if (config.server.enableHeapSnapshotEnpoint) {
this.get('/heap-snapshot', async (req, res) => {
writeHeapSnapshot();
res.status(200);
res.end('Snapshot written');
});
}
}
}

View File

@ -79,6 +79,7 @@ export interface IServerOption {
cdnPrefix?: string;
unleashUrl: string;
serverMetrics: boolean;
enableHeapSnapshotEnpoint: boolean;
enableRequestLogger: boolean;
gracefulShutdownEnable: boolean;
gracefulShutdownTimeout: number;

View File

@ -23,6 +23,7 @@ process.nextTick(async () => {
// keepAliveTimeout: 1,
gracefulShutdownEnable: true,
// cdnPrefix: 'https://cdn.getunleash.io/unleash/v4.4.1',
enableHeapSnapshotEnpoint: true,
},
logLevel: LogLevel.debug,
enableOAS: true,