Skip to content

Commit

Permalink
chore(dashmate): expose metrics from Drive
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Apr 26, 2024
1 parent 3909b28 commit d867fe1
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 53 deletions.
5 changes: 5 additions & 0 deletions packages/dashmate/configs/defaults/getBaseConfigFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ export default function getBaseConfigFactory(homeDir) {
dkgInterval: 288,
llmqSize: 400,
},
metrics: {
enabled: false,
host: '127.0.0.1',
port: 29090,
},
epochTime: 788400,
},
tenderdash: {
Expand Down
95 changes: 48 additions & 47 deletions packages/dashmate/configs/getConfigFileMigrationsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,51 +524,56 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs)
'1.0.0-dev.12': (configFile) => {
Object.entries(configFile.configs)
.forEach(([name, options]) => {
// Do nothing if it's already migrated for some reason
if (!options.platform.dapi.envoy) {
return;
// Update tenderdash config
options.platform.drive.tenderdash.docker.image = base.get('platform.drive.tenderdash.docker.image');
options.platform.drive.tenderdash.mempool.maxConcurrentCheckTx = base.get('platform.drive.tenderdash.mempool.maxConcurrentCheckTx');

// Add metrics to Drive ABCI
options.platform.drive.abci.metrics = base.get('platform.drive.abci.metrics');

// Envoy -> Gateway
if (options.platform.dapi.envoy) {
options.platform.gateway = lodash.cloneDeep(options.platform.dapi.envoy);

// add new options
options.platform.gateway.maxConnections = base.get('platform.gateway.maxConnections');
options.platform.gateway.maxHeapSizeInBytes = base.get('platform.gateway.maxHeapSizeInBytes');
options.platform.gateway.metrics = base.get('platform.gateway.metrics');
options.platform.gateway.admin = base.get('platform.gateway.admin');
options.platform.gateway.upstreams = base.get('platform.gateway.upstreams');
options.platform.gateway.log = base.get('platform.gateway.log');

// http -> listeners
options.platform.gateway.listeners = lodash.cloneDeep(
base.get('platform.gateway.listeners'),
);

options.platform.gateway.listeners.dapiAndDrive.host = options.platform.dapi.envoy
.http.host;
options.platform.gateway.listeners.dapiAndDrive.port = options.platform.dapi.envoy
.http.port;

delete options.platform.gateway.http;

// update rate limiter
options.platform.gateway.rateLimiter.docker = base.get('platform.gateway.rateLimiter.docker');
options.platform.gateway.rateLimiter.unit = base.get('platform.gateway.rateLimiter.unit');
options.platform.gateway.rateLimiter.requestsPerUnit = base.get('platform.gateway.rateLimiter.requestsPerUnit');
options.platform.gateway.rateLimiter.blacklist = base.get('platform.gateway.rateLimiter.blacklist');
options.platform.gateway.rateLimiter.whitelist = base.get('platform.gateway.rateLimiter.whitelist');
options.platform.gateway.rateLimiter.metrics = base.get('platform.gateway.rateLimiter.metrics');

delete options.platform.gateway.rateLimiter.fillInterval;
delete options.platform.gateway.rateLimiter.maxTokens;
delete options.platform.gateway.rateLimiter.tokensPerFill;

// delete envoy
delete options.platform.dapi.envoy;

// update image
options.platform.gateway.docker.image = base.get('platform.gateway.docker.image');
}

options.platform.gateway = lodash.cloneDeep(options.platform.dapi.envoy);

// add new options
options.platform.gateway.maxConnections = base.get('platform.gateway.maxConnections');
options.platform.gateway.maxHeapSizeInBytes = base.get('platform.gateway.maxHeapSizeInBytes');
options.platform.gateway.metrics = base.get('platform.gateway.metrics');
options.platform.gateway.admin = base.get('platform.gateway.admin');
options.platform.gateway.upstreams = base.get('platform.gateway.upstreams');
options.platform.gateway.log = base.get('platform.gateway.log');

// http -> listeners
options.platform.gateway.listeners = lodash.cloneDeep(
base.get('platform.gateway.listeners'),
);

options.platform.gateway.listeners.dapiAndDrive.host = options.platform.dapi.envoy
.http.host;
options.platform.gateway.listeners.dapiAndDrive.port = options.platform.dapi.envoy
.http.port;

delete options.platform.gateway.http;

// update rate limiter
options.platform.gateway.rateLimiter.docker = base.get('platform.gateway.rateLimiter.docker');
options.platform.gateway.rateLimiter.unit = base.get('platform.gateway.rateLimiter.unit');
options.platform.gateway.rateLimiter.requestsPerUnit = base.get('platform.gateway.rateLimiter.requestsPerUnit');
options.platform.gateway.rateLimiter.blacklist = base.get('platform.gateway.rateLimiter.blacklist');
options.platform.gateway.rateLimiter.whitelist = base.get('platform.gateway.rateLimiter.whitelist');
options.platform.gateway.rateLimiter.metrics = base.get('platform.gateway.rateLimiter.metrics');

delete options.platform.gateway.rateLimiter.fillInterval;
delete options.platform.gateway.rateLimiter.maxTokens;
delete options.platform.gateway.rateLimiter.tokensPerFill;

// delete envoy
delete options.platform.dapi.envoy;

// update image
options.platform.gateway.docker.image = base.get('platform.gateway.docker.image');

// rename non conventional field
if (options.platform.drive.abci.tokioConsole.retention_secs) {
options.platform.drive.abci.tokioConsole.retention = options.platform.drive.abci
Expand Down Expand Up @@ -603,10 +608,6 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs)
fs.rmSync(oldFilePath, { recursive: true });
}
}

// Update tenderdash config
options.platform.drive.tenderdash.docker.image = base.get('platform.drive.tenderdash.docker.image');
options.platform.drive.tenderdash.mempool.maxConcurrentCheckTx = base.get('platform.drive.tenderdash.mempool.maxConcurrentCheckTx');
}
});

Expand Down
4 changes: 2 additions & 2 deletions packages/dashmate/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ services:
- DB_PATH=/var/lib/dash/rs-drive-abci/db
- ABCI_CONSENSUS_BIND_ADDRESS=tcp://0.0.0.0:26658
- GRPC_BIND_ADDRESS=0.0.0.0:26670
- PROMETHEUS_BIND_ADDRESS=http://0.0.0.0:29090
- PROMETHEUS_BIND_ADDRESS=${PLATFORM_DRIVE_ABCI_METRICS_URL}
- TOKIO_CONSOLE_ENABLED=${PLATFORM_DRIVE_ABCI_TOKIO_CONSOLE_ENABLED:?err}
- TOKIO_CONSOLE_ADDRESS=0.0.0.0:${PLATFORM_DRIVE_ABCI_TOKIO_CONSOLE_PORT:?err}
- TOKIO_CONSOLE_RETENTION_SECS=${PLATFORM_DRIVE_ABCI_TOKIO_CONSOLE_RETENTION:?err}
Expand All @@ -81,14 +81,14 @@ services:
- 26658
- 26659
- 26670
- 29090
env_file:
# Logger settings
- ${DASHMATE_HOME_DIR:?err}/${CONFIG_NAME:?err}/platform/drive/abci/logger.env
profiles:
- platform
ports:
- ${PLATFORM_DRIVE_ABCI_TOKIO_CONSOLE_HOST:?err}:${PLATFORM_DRIVE_ABCI_TOKIO_CONSOLE_PORT:?err}:${PLATFORM_DRIVE_ABCI_TOKIO_CONSOLE_PORT:?err}
- ${PLATFORM_DRIVE_ABCI_METRICS_HOST:?err}:${PLATFORM_DRIVE_ABCI_METRICS_PORT:?err}:29090

drive_tenderdash:
image: ${PLATFORM_DRIVE_TENDERDASH_DOCKER_IMAGE:?err}
Expand Down
5 changes: 4 additions & 1 deletion packages/dashmate/src/config/configJsonSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,12 @@ export default {
type: 'integer',
minimum: 180,
},
metrics: {
$ref: '#/definitions/enabledHostPort',
},
},
additionalProperties: false,
required: ['docker', 'logs', 'tokioConsole', 'validatorSet', 'chainLock', 'epochTime'],
required: ['docker', 'logs', 'tokioConsole', 'validatorSet', 'chainLock', 'epochTime', 'metrics'],
},
tenderdash: {
type: 'object',
Expand Down
6 changes: 6 additions & 0 deletions packages/dashmate/src/config/generateEnvsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export default function generateEnvsFactory(configFile, homeDir, getConfigProfil
tenderdashLogDirectoryPath = path.dirname(tenderdashLogFilePath);
}

let driveAbciMetricsUrl = '';
if (config.get('platform.drive.abci.metrics.enabled')) {
driveAbciMetricsUrl = 'http://0.0.0.0:29090';
}

return {
DASHMATE_HOME_DIR: homeDir.getPath(),
LOCAL_UID: uid,
Expand All @@ -93,6 +98,7 @@ export default function generateEnvsFactory(configFile, homeDir, getConfigProfil
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
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export default function setupLocalPresetTaskFactory(
config.set('platform.drive.tenderdash.node.key', key);

config.set('platform.drive.abci.tokioConsole.port', config.get('platform.drive.abci.tokioConsole.port') + (i * 100));
config.set('platform.drive.abci.metrics.port', config.get('platform.drive.abci.metrics.port') + (i * 100));
config.set('platform.gateway.admin.port', config.get('platform.gateway.admin.port') + (i * 100));
config.set('platform.gateway.listeners.dapiAndDrive.port', config.get('platform.gateway.listeners.dapiAndDrive.port') + (i * 100));
config.set('platform.gateway.metrics.port', config.get('platform.gateway.metrics.port') + (i * 100));
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive-abci/.env.local
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ABCI host and port to listen
ABCI_CONSENSUS_BIND_ADDRESS="tcp://0.0.0.0:26658"
PROMETHEUS_BIND_ADDRESS="http://0.0.0.0:29090"
#PROMETHEUS_BIND_ADDRESS="http://0.0.0.0:29090"
GRPC_BIND_ADDRESS="0.0.0.0:26670"

# stderr logging for humans
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive-abci/.env.mainnet
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ABCI host and port to listen
ABCI_CONSENSUS_BIND_ADDRESS="tcp://0.0.0.0:26658"
PROMETHEUS_BIND_ADDRESS="http://0.0.0.0:29090"
#PROMETHEUS_BIND_ADDRESS="http://0.0.0.0:29090"
GRPC_BIND_ADDRESS="0.0.0.0:26670"

# stderr logging for humans
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive-abci/.env.testnet
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ABCI host and port to listen
ABCI_CONSENSUS_BIND_ADDRESS="tcp://0.0.0.0:26658"
PROMETHEUS_BIND_ADDRESS="http://0.0.0.0:29090"
#PROMETHEUS_BIND_ADDRESS="http://0.0.0.0:29090"
GRPC_BIND_ADDRESS="0.0.0.0:26670"

# stderr logging for humans
Expand Down
2 changes: 2 additions & 0 deletions packages/rs-drive-abci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ fn start_prometheus(config: &PlatformConfig) -> Result<Option<Prometheus>, Strin
.filter(|s| !s.is_empty());

if let Some(addr) = prometheus_addr {
tracing::info!("Expose prometheus metrics on {}", addr);

let addr = url::Url::parse(&addr).map_err(|e| e.to_string())?;
Ok(Some(Prometheus::new(addr).map_err(|e| e.to_string())?))
} else {
Expand Down

0 comments on commit d867fe1

Please sign in to comment.