mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-23 11:44:06 -08:00
⚡ Add debug log in healthcheck and enable DB logging via environment (#2744)
* ⚡ add debug log in healthcheck * ⚡ add DB logging * CR
This commit is contained in:
parent
b487d4f392
commit
135d5a89cd
|
@ -22,6 +22,26 @@ const config = convict({
|
|||
default: '',
|
||||
env: 'DB_TABLE_PREFIX',
|
||||
},
|
||||
logging: {
|
||||
enabled: {
|
||||
doc: 'Typeorm logging enabled flag.',
|
||||
format: 'Boolean',
|
||||
default: false,
|
||||
env: 'DB_LOGGING_ENABLED',
|
||||
},
|
||||
options: {
|
||||
doc: 'Logging level options, default is "error". Possible values: query,error,schema,warn,info,log. To enable all logging, specify "all"',
|
||||
format: String,
|
||||
default: 'error',
|
||||
env: 'DB_LOGGING_OPTIONS',
|
||||
},
|
||||
maxQueryExecutionTime: {
|
||||
doc: 'Maximum number of milliseconds query should be executed before logger logs a warning. Set 0 to disable long running query warning',
|
||||
format: Number,
|
||||
default: 1000,
|
||||
env: 'DB_LOGGING_MAX_EXECUTION_TIME',
|
||||
},
|
||||
},
|
||||
postgresdb: {
|
||||
database: {
|
||||
doc: 'PostgresDB Database',
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
/* eslint-disable no-case-declarations */
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { UserSettings } from 'n8n-core';
|
||||
import { ConnectionOptions, createConnection, getRepository } from 'typeorm';
|
||||
import { ConnectionOptions, createConnection, getRepository, LoggerOptions } from 'typeorm';
|
||||
import { TlsOptions } from 'tls';
|
||||
import * as path from 'path';
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
|
@ -104,10 +104,29 @@ export async function init(): Promise<IDatabaseCollections> {
|
|||
throw new Error(`The database "${dbType}" is currently not supported!`);
|
||||
}
|
||||
|
||||
let loggingOption: LoggerOptions = (await GenericHelpers.getConfigValue(
|
||||
'database.logging.enabled',
|
||||
)) as boolean;
|
||||
|
||||
if (loggingOption) {
|
||||
const optionsString = (
|
||||
(await GenericHelpers.getConfigValue('database.logging.options')) as string
|
||||
).replace(/\s+/g, '');
|
||||
|
||||
if (optionsString === 'all') {
|
||||
loggingOption = optionsString;
|
||||
} else {
|
||||
loggingOption = optionsString.split(',') as LoggerOptions;
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(connectionOptions, {
|
||||
entities: Object.values(entities),
|
||||
synchronize: false,
|
||||
logging: false,
|
||||
logging: loggingOption,
|
||||
maxQueryExecutionTime: (await GenericHelpers.getConfigValue(
|
||||
'database.logging.maxQueryExecutionTime',
|
||||
)) as string,
|
||||
});
|
||||
|
||||
let connection = await createConnection(connectionOptions);
|
||||
|
|
|
@ -615,6 +615,8 @@ class App {
|
|||
|
||||
// Does very basic health check
|
||||
this.app.get('/healthz', async (req: express.Request, res: express.Response) => {
|
||||
LoggerProxy.debug('Health check started!');
|
||||
|
||||
const connection = getConnectionManager().get();
|
||||
|
||||
try {
|
||||
|
@ -635,6 +637,8 @@ class App {
|
|||
status: 'ok',
|
||||
};
|
||||
|
||||
LoggerProxy.debug('Health check completed successfully!');
|
||||
|
||||
ResponseHelper.sendSuccessResponse(res, responseData, true, 200);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue