mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[cli] Add workaround to set a custom heap snapshot dir (#170756)
This commit is contained in:
parent
8c26f7cfe9
commit
a173300abc
3 changed files with 49 additions and 0 deletions
|
@ -128,6 +128,7 @@ COPY --chown=1000:0 config/serverless.oblt.yml /usr/share/kibana/config/serverle
|
|||
COPY --chown=1000:0 config/serverless.security.yml /usr/share/kibana/config/serverless.security.yml
|
||||
# Supportability enhancement: enable capturing heap snapshots. See https://nodejs.org/api/cli.html#--heapsnapshot-signalsignal
|
||||
RUN echo '\n--heapsnapshot-signal=SIGUSR2' >> config/node.options
|
||||
RUN echo '--diagnostic-dir=./data' >> config/node.options
|
||||
{{/serverless}}
|
||||
{{^opensslLegacyProvider}}
|
||||
RUN sed 's/\(--openssl-legacy-provider\)/#\1/' -i config/node.options
|
||||
|
|
46
src/setup_node_env/heap_snapshot.js
Normal file
46
src/setup_node_env/heap_snapshot.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
var getopts = require('getopts');
|
||||
var path = require('path');
|
||||
var v8 = require('node:v8');
|
||||
var worker = require('node:worker_threads');
|
||||
|
||||
var execOpts = getopts(process.execArgv);
|
||||
var envOpts = getopts(process.env.NODE_OPTIONS ? process.env.NODE_OPTIONS.split(/\s+/) : []);
|
||||
var diagnosticDir = execOpts['diagnostic-dir'] || envOpts['diagnostic-dir'];
|
||||
var heapSnapshotSignal = execOpts['heapsnapshot-signal'] || envOpts['heapsnapshot-signal'];
|
||||
var heapSnapshotSerial = 0;
|
||||
|
||||
function getHeapSnapshotPath() {
|
||||
var now = new Date();
|
||||
|
||||
var year = now.getFullYear();
|
||||
var month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
var day = String(now.getDate()).padStart(2, '0');
|
||||
var hours = String(now.getHours()).padStart(2, '0');
|
||||
var minutes = String(now.getMinutes()).padStart(2, '0');
|
||||
var seconds = String(now.getSeconds()).padStart(2, '0');
|
||||
|
||||
var date = `${year}${month}${day}`;
|
||||
var time = `${hours}${minutes}${seconds}`;
|
||||
var pid = process.pid;
|
||||
var threadId = worker.threadId;
|
||||
var serial = (++heapSnapshotSerial).toString().padStart(3, '0');
|
||||
|
||||
return path.join(diagnosticDir, `Heap.${date}.${time}.${pid}.${threadId}.${serial}.heapsnapshot`);
|
||||
}
|
||||
|
||||
if (diagnosticDir && heapSnapshotSignal) {
|
||||
process.removeAllListeners(heapSnapshotSignal);
|
||||
|
||||
process.on(heapSnapshotSignal, function () {
|
||||
var heapSnapshotPath = getHeapSnapshotPath();
|
||||
v8.writeHeapSnapshot(heapSnapshotPath);
|
||||
});
|
||||
}
|
|
@ -11,6 +11,8 @@ require('./exit_on_warning');
|
|||
require('./harden');
|
||||
// The following require statements MUST be executed before any others - END
|
||||
|
||||
// @todo Remove when migrated to Node 20 (#162696)
|
||||
require('./heap_snapshot');
|
||||
require('symbol-observable');
|
||||
require('source-map-support').install();
|
||||
require('./node_version_validator');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue