Skip to content

Commit

Permalink
Merge branch 'main' into tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw authored Jun 3, 2024
2 parents a6afe24 + c725502 commit ed17e51
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 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 --disable-tokio-console > 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
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ pub struct CommonConfig {
/// Url to the tracing collector (Opentelemetry over gRPC)
#[arg(long = "tracing-collector-url", env = "TRACING_COLLECTOR_URL")]
pub tracing_url: Option<String>,

// 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
4 changes: 2 additions & 2 deletions 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 All @@ -56,7 +56,7 @@ where
runtime.block_on(spawn_signal_handler())?;

// init tracing
runtime.block_on(infra::init_tracing(config.common().tracing_url.as_ref()));
runtime.block_on(infra::init_tracing(config.common().tracing_url.as_ref(), config.common().tokio_console_address));

Ok(Self {
config,
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
5 changes: 3 additions & 2 deletions src/infra/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Tracing services.
use std::env;
use std::net::SocketAddr;

use console_subscriber::ConsoleLayer;
use opentelemetry::KeyValue;
Expand All @@ -22,7 +23,7 @@ use crate::ext::named_spawn;
use crate::ext::not;

/// Init application global tracing.
pub async fn init_tracing(url: Option<&String>) {
pub async fn init_tracing(url: Option<&String>, tokio_console_address: SocketAddr) {
println!("creating tracing registry");

// configure stdout layer
Expand Down Expand Up @@ -74,7 +75,7 @@ pub async fn init_tracing(url: Option<&String>) {

// init tokio console registry
println!("tracing registry enabling tokio console");
let (console_layer, console_server) = ConsoleLayer::builder().with_default_env().build();
let (console_layer, console_server) = ConsoleLayer::builder().with_default_env().server_addr(tokio_console_address).build();
let console_layer = console_layer.with_filter(TokioConsoleFilter);

// init tokio console server
Expand Down

0 comments on commit ed17e51

Please sign in to comment.