Skip to content

Commit

Permalink
add metrics exporter config
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-aranha-cw committed Jun 3, 2024
1 parent 18c356e commit ec8e0c6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ e2e-relayer-external-up:
wait-service --tcp 0.0.0.0:5432 -t {{ wait_service_timeout }} -- echo

# Start Stratus binary
cargo run --release --bin stratus --no-default-features --features "dev,rocks,kubernetes" -- --enable-test-accounts --block-mode 1s --perm-storage=rocks --relayer-db-url "postgres://postgres:123@localhost:5432/stratus" --relayer-db-connections 5 --relayer-db-timeout 1s -a 0.0.0.0:3000 > e2e_logs/stratus.log &
cargo run --release --bin stratus --features dev -- --enable-test-accounts --block-mode 1s --perm-storage=rocks --relayer-db-url "postgres://postgres:123@localhost:5432/stratus" --relayer-db-connections 5 --relayer-db-timeout 1s -a 0.0.0.0:3000 > e2e_logs/stratus.log &

# Wait for Stratus to start
wait-service --tcp 0.0.0.0:3000 -t {{ wait_service_timeout }} -- echo
Expand All @@ -391,7 +391,7 @@ e2e-relayer-external-up:
sleep 5

# Start Relayer External binary
cargo run --release --bin relayer --no-default-features --features "rocks,kubernetes" -- --db-url postgres://postgres:123@localhost:5432/stratus --db-connections 5 --db-timeout 1s --forward-to http://localhost:8545 --backoff 10ms --tokio-console-address 0.0.0.0:6979 > e2e_logs/relayer.log &
cargo run --release --bin relayer --features dev -- --db-url postgres://postgres:123@localhost:5432/stratus --db-connections 5 --db-timeout 1s --forward-to http://localhost:8545 --backoff 10ms --tokio-console-address 0.0.0.0:6979 --metrics-exporter-address 0.0.0.0:9001 > e2e_logs/relayer.log &

if [ -d e2e ]; then
(
Expand Down
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ pub struct CommonConfig {
// Address for the Tokio Console
#[arg(long = "tokio-console-address", env = "TOKIO_CONSOLE_ADDRESS", default_value = "0.0.0.0:6669")]
pub tokio_console_address: SocketAddr,

// Address for the Prometheus Metrics Exporter
#[arg(long = "metrics-exporter-address", env = "METRICS_EXPORTER_ADDRESS", default_value = "0.0.0.0:9000")]
pub metrics_exporter_address: SocketAddr,
}

impl WithCommonConfig for CommonConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ where

// init metrics
#[cfg(feature = "metrics")]
infra::init_metrics(config.common().metrics_histogram_kind);
infra::init_metrics(config.common().metrics_exporter_address, config.common().metrics_histogram_kind);

// init sentry
let _sentry_guard = config.common().sentry_url.as_ref().map(|sentry_url| infra::init_sentry(sentry_url));
Expand Down
5 changes: 3 additions & 2 deletions src/infra/metrics/metrics_init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Metrics services.
#![cfg(feature = "metrics")]

use std::net::SocketAddr;
use std::stringify;

use metrics_exporter_prometheus::Matcher;
Expand Down Expand Up @@ -29,7 +30,7 @@ const BUCKET_FOR_DURATION: [f64; 37] = [
/// Init application global metrics.
///
/// Default configuration runs metrics exporter on port 9000.
pub fn init_metrics(histogram_kind: MetricsHistogramKind) {
pub fn init_metrics(metrics_exporter_address: SocketAddr, histogram_kind: MetricsHistogramKind) {
tracing::info!("creating metrics exporter");

// get metric definitions
Expand All @@ -45,7 +46,7 @@ pub fn init_metrics(histogram_kind: MetricsHistogramKind) {
metrics.extend(metrics_for_external_relayer());

// init exporter
let mut builder = PrometheusBuilder::new();
let mut builder = PrometheusBuilder::new().with_http_listener(metrics_exporter_address);

// init buckets
if histogram_kind == MetricsHistogramKind::Histogram {
Expand Down

0 comments on commit ec8e0c6

Please sign in to comment.