Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashmate)!: enhance core logging configuration #2121

Merged
merged 11 commits into from
Sep 17, 2024
15 changes: 10 additions & 5 deletions packages/dashmate/configs/defaults/getBaseConfigFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { version } = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT_DIR, 'pack
* @param {HomeDir} homeDir
* @returns {getBaseConfig}
*/
export default function getBaseConfigFactory(homeDir) {
export default function getBaseConfigFactory() {
const prereleaseTag = semver.prerelease(version) === null ? '' : `-${semver.prerelease(version)[0]}`;
const dockerImageVersion = `${semver.major(version)}${prereleaseTag}`;

Expand Down Expand Up @@ -134,12 +134,17 @@ export default function getBaseConfigFactory(homeDir) {
},
},
log: {
file: {
categories: [],
path: homeDir.joinPath('logs', 'base', 'core.log'),
filePath: null,
debug: {
enabled: false,
ips: false,
sourceLocations: false,
threadNames: false,
timeMicros: false,
includeOnly: [],
exclude: [],
},
},
logIps: 0,
indexes: [],
},
platform: {
Expand Down
7 changes: 0 additions & 7 deletions packages/dashmate/configs/defaults/getMainnetConfigFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ export default function getMainnetConfigFactory(homeDir, getBaseConfig) {
subnet: '172.26.24.0/24',
},
},
core: {
log: {
file: {
path: homeDir.joinPath('logs', 'mainnet', 'core.log'),
},
},
},
network: NETWORK_MAINNET,
platform: {
enable: false,
Expand Down
5 changes: 0 additions & 5 deletions packages/dashmate/configs/defaults/getTestnetConfigFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ export default function getTestnetConfigFactory(homeDir, getBaseConfig) {
rpc: {
port: 19998,
},
log: {
file: {
path: homeDir.joinPath('logs', 'testnet', 'core.log'),
},
},
spork: {
address: 'yjPtiKh2uwk3bDutTEA2q9mCtXyiZRWn55',
},
Expand Down
27 changes: 26 additions & 1 deletion packages/dashmate/configs/getConfigFileMigrationsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,11 +853,36 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs)
});
return configFile;
},
'1.3.0-dev.2': (configFile) => {
'1.3.0-dev.3': (configFile) => {
Object.entries(configFile.configs)
.forEach(([, options]) => {
options.platform.drive.abci.docker.image = 'dashpay/drive:1-dev';
options.platform.dapi.api.docker.image = 'dashpay/dapi:1-dev';

// Update core log settings
options.core.log.filePath = null;
options.core.log.debug = {
enabled: false,
ips: !!options.core.logIps,
sourceLocations: false,
threadNames: false,
timeMicros: false,
includeOnly: [],
exclude: [],
};

// If debug log was enabled
if (options.core.log.file.categories.length > 0) {
options.core.log.filePath = options.core.log.file.path;
options.core.log.debug.enabled = true;

if (!options.core.log.file.categories.includes('all')) {
options.core.log.debug.includeOnly = options.core.log.file.categories;
}
}

delete options.core.log.file;
delete options.core.logIps;
});
return configFile;
},
Expand Down
2 changes: 0 additions & 2 deletions packages/dashmate/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ services:
volumes:
- core_data:/home/dash
- ${DASHMATE_HOME_DIR:?err}/${CONFIG_NAME:?err}/core/dash.conf:/home/dash/.dashcore/dash.conf:ro
- ${CORE_LOG_DIRECTORY_PATH:?err}:/var/log/dash
command:
- dashd
stop_grace_period: 30s
Expand Down Expand Up @@ -112,7 +111,6 @@ services:
volumes:
- drive_tenderdash:/tenderdash
- ${DASHMATE_HOME_DIR:?err}/${CONFIG_NAME:?err}/platform/drive/tenderdash:/tenderdash/config:ro
- ${PLATFORM_DRIVE_TENDERDASH_LOG_DIRECTORY_PATH:?err}:/var/log/tenderdash
stop_grace_period: 10s
profiles:
- platform
Expand Down
49 changes: 36 additions & 13 deletions packages/dashmate/src/config/configJsonSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,36 +401,59 @@ export default {
log: {
type: 'object',
properties: {
file: {
filePath: {
type: ['null', 'string'],
minLength: 1,
},
debug: {
type: 'object',
properties: {
categories: {
enabled: {
type: 'boolean',
},
ips: {
type: 'boolean',
},
sourceLocations: {
type: 'boolean',
},
threadNames: {
type: 'boolean',
},
timeMicros: {
type: 'boolean',
},
includeOnly: {
type: 'array',
uniqueItems: true,
items: {
type: 'string',
enum: ['all', 'net', 'tor', 'mempool', 'http', 'bench', 'zmq', 'walletdb', 'rpc', 'estimatefee',
enum: ['net', 'tor', 'mempool', 'http', 'bench', 'zmq', 'walletdb', 'rpc', 'estimatefee',
'addrman', 'selectcoins', 'reindex', 'cmpctblock', 'rand', 'prune', 'proxy', 'mempoolrej',
'libevent', 'coindb', 'qt', 'leveldb', 'chainlocks', 'gobject', 'instantsend', 'llmq',
'llmq-dkg', 'llmq-sigs', 'mnpayments', 'mnsync', 'coinjoin', 'spork', 'netconn',
],
},
},
path: {
type: 'string',
minLength: 1,
exclude: {
type: 'array',
uniqueItems: true,
items: {
type: 'string',
enum: ['net', 'tor', 'mempool', 'http', 'bench', 'zmq', 'walletdb', 'rpc', 'estimatefee',
'addrman', 'selectcoins', 'reindex', 'cmpctblock', 'rand', 'prune', 'proxy', 'mempoolrej',
'libevent', 'coindb', 'qt', 'leveldb', 'chainlocks', 'gobject', 'instantsend', 'llmq',
'llmq-dkg', 'llmq-sigs', 'mnpayments', 'mnsync', 'coinjoin', 'spork', 'netconn',
],
},
},
},
additionalProperties: false,
required: ['categories', 'path'],
required: ['enabled', 'ips', 'sourceLocations', 'threadNames', 'timeMicros', 'includeOnly', 'exclude'],
},
},
additionalProperties: false,
required: ['file'],
},
logIps: {
type: 'integer',
enum: [0, 1],
required: ['filePath', 'debug'],
},
indexes: {
type: ['array'],
Expand All @@ -444,7 +467,7 @@ export default {
},
},
required: ['docker', 'p2p', 'rpc', 'spork', 'masternode', 'miner', 'devnet', 'log',
'logIps', 'indexes', 'insight'],
'indexes', 'insight'],
additionalProperties: false,
},
platform: {
Expand Down
13 changes: 0 additions & 13 deletions packages/dashmate/src/config/generateEnvsFactory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import path from 'path';
import os from 'os';
import convertObjectToEnvs from './convertObjectToEnvs.js';
import { DASHMATE_HELPER_DOCKER_IMAGE } from '../constants.js';
Expand All @@ -20,7 +19,6 @@ export default function generateEnvsFactory(configFile, homeDir, getConfigProfil
* COMPOSE_PROJECT_NAME: string,
* COMPOSE_FILE: string,
* COMPOSE_PATH_SEPARATOR: string,
* CORE_LOG_DIRECTORY_PATH: string
* }}
*/
function generateEnvs(config) {
Expand Down Expand Up @@ -69,13 +67,6 @@ export default function generateEnvsFactory(configFile, homeDir, getConfigProfil

const { uid, gid } = os.userInfo();

// Determine logs directory to mount into tenderdash container
let tenderdashLogDirectoryPath = homeDir.joinPath('logs', config.get('network'));
const tenderdashLogFilePath = config.get('platform.drive.tenderdash.log.path');
if (tenderdashLogFilePath !== null) {
tenderdashLogDirectoryPath = path.dirname(tenderdashLogFilePath);
}

let driveAbciMetricsUrl = '';
if (config.get('platform.drive.abci.metrics.enabled')) {
driveAbciMetricsUrl = 'http://0.0.0.0:29090';
Expand All @@ -92,11 +83,7 @@ export default function generateEnvsFactory(configFile, homeDir, getConfigProfil
COMPOSE_PATH_SEPARATOR: ':',
DOCKER_BUILDKIT: 1,
COMPOSE_DOCKER_CLI_BUILD: 1,
CORE_LOG_DIRECTORY_PATH: path.dirname(
config.get('core.log.file.path'),
),
DASHMATE_HELPER_DOCKER_IMAGE,
PLATFORM_DRIVE_TENDERDASH_LOG_DIRECTORY_PATH: tenderdashLogDirectoryPath,
PLATFORM_GATEWAY_RATE_LIMITER_METRICS_DISABLED: !config.get('platform.gateway.rateLimiter.metrics.enabled'),
PLATFORM_DRIVE_ABCI_METRICS_URL: driveAbciMetricsUrl,
...convertObjectToEnvs(config.getOptions()),
Expand Down
6 changes: 4 additions & 2 deletions packages/dashmate/src/core/startCoreFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ export default function startCoreFactory(
coreCommand.push('--disablewallet=1');
}

const logFilePath = config.get('core.log.file.path');
ensureFileMountExists(logFilePath, 0o666);
const logFilePath = config.get('core.log.filePath');
if (logFilePath !== null) {
ensureFileMountExists(logFilePath, 0o666);
}

const coreContainer = await dockerCompose.runService(
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,8 @@ export default function setupLocalPresetTaskFactory(
config.set('docker.network.subnet', subnet.join('.'));

// Setup Core debug logs
const coreLogFilePath = homeDir.joinPath('logs', config.getName(), 'core.log');
config.set('core.log.file.path', coreLogFilePath);

if (ctx.debugLogs) {
config.set('core.log.file.categories', ['all']);
config.set('core.log.debug.enabled', true);
}

// Although not all nodes are miners, all nodes should be aware of
Expand Down
6 changes: 4 additions & 2 deletions packages/dashmate/src/listr/tasks/startNodeTaskFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ export default function startNodeTaskFactory(
throw new Error(`'core.miner.enable' option only works with local network. Your network is ${config.get('network')}.`);
}

const coreLogFilePath = config.get('core.log.file.path');
ensureFileMountExists(coreLogFilePath, 0o666);
const coreLogFilePath = config.get('core.log.filePath');
if (coreLogFilePath !== null) {
ensureFileMountExists(coreLogFilePath, 0o666);
}

// Check Drive log files are created
if (config.get('platform.enable')) {
Expand Down
1 change: 0 additions & 1 deletion packages/dashmate/src/test/mock/getConfigMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default function getConfigMock(sinon) {
configMock.get.withArgs('platform.drive.tenderdash.rpc.host').returns('127.0.0.1');
configMock.get.withArgs('platform.drive.tenderdash.rpc.port').returns('8103');
configMock.get.withArgs('platform.enable').returns(true);
configMock.get.withArgs('core.log.file.path').returns('/Users/user/.dashmate/logs/base/core.log');

return configMock;
}
28 changes: 22 additions & 6 deletions packages/dashmate/templates/core/dash.conf.dot
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@ daemon=0 # leave this set to 0 for Docker
logtimestamps=1
maxconnections=256
reindex={{?it.reindex}}1{{??}}0{{?}}
{{~it.core.log.file.categories :category}}
{{? category === 'all'}}

{{? it.core.log.debug.enabled }}
logips={{? it.core.log.debug.ips }}1{{??}}0{{?}}
logsourcelocations={{? it.core.log.debug.sourceLocations }}1{{??}}0{{?}}
logthreadnames={{? it.core.log.debug.threadNames }}1{{??}}0{{?}}
logtimemicros={{? it.core.log.debug.timeMicros }}1{{??}}0{{?}}

{{? it.core.log.debug.includeOnly.length === 0 }}
debug=1
{{??}}
{{~it.core.log.debug.includeOnly :category}}
debug={{= category }}
{{~}}
{{?}}
{{~it.core.log.debug.exclude :category}}
debugexclude={{= category}}
{{~}}
{{?}}

{{? it.core.log.filePath === null }}
nodebuglogfile=1
{{??}}
debug={{=category}}{{?}}{{~}}
debuglogfile=/var/log/dash/{{= it.core.log.file.path.split('/').pop() }}
logips={{=it.core.logIps }}
fallbackfee=0.00001
debuglogfile=/var/log/dash/debug.log }}
{{?}}

# JSON RPC
server=1
Expand Down
10 changes: 10 additions & 0 deletions packages/dashmate/templates/dynamic-compose.yml.dot
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ services:
{{~ it.core.docker.commandArgs :arg }}
- {{=arg}}
{{~}}
{{? it.core.log.filePath !== null }}
volumes:
- {{=it.core.log.filePath}}:/var/log/dash/debug.log
{{?}}

{{ driveLogs = Object.entries(it.platform.drive.abci.logs).filter(([, settings]) => settings.destination !== 'stderr' && settings.destination !== 'stdout'); }}
{{? driveLogs.length > 0 }}
Expand All @@ -18,6 +22,12 @@ services:
{{~}}
{{?}}

{{? it.platform.drive.tenderdash.log.path !== null }}
drive_tenderdash:
volumes:
- {{=it.platform.drive.tenderdash.log.path}}:/var/log/tenderdash/tenderdash.log
{{?}}

{{ gatewayLogs = it.platform.gateway.log.accessLogs.filter((l) => l.type === 'file'); }}
{{? gatewayLogs.length > 0 }}
gateway:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ db-dir = "data"
log-level = "{{=it.platform.drive.tenderdash.log.level}}"

# Path to the log file. This parameter is an additional option to the existing stderr output
{{? it.platform.drive.tenderdash.log.path }}log-file-path = "/var/log/tenderdash/{{= it.platform.drive.tenderdash.log.path.split('/').pop() }}"{{?}}
{{? it.platform.drive.tenderdash.log.path }}log-file-path = "/var/log/tenderdash/tenderdash.log"{{?}}

# Output format: 'plain' (colored text) or 'json'
log-format = "{{=it.platform.drive.tenderdash.log.format}}"
Expand Down
Loading