Skip to content

Commit

Permalink
Merge pull request #29 from worldcoin/0xkitsune/datadog
Browse files Browse the repository at this point in the history
Tree Availability Datadog logic
  • Loading branch information
0xKitsune authored Nov 7, 2023
2 parents 4077c32 + 2041728 commit e583d7d
Show file tree
Hide file tree
Showing 11 changed files with 377 additions and 10 deletions.
102 changes: 102 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions bin/state_bridge_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::Arc;
use std::time::Duration;

use clap::Parser;
use common::tracing::{init_datadog_subscriber, init_subscriber};
use ethers::abi::Address;
use ethers::prelude::{
Http, LocalWallet, NonceManagerMiddleware, Provider, Signer,
Expand All @@ -18,6 +19,7 @@ use state_bridge::abi::{
};
use state_bridge::bridge::StateBridge;
use state_bridge::StateBridgeService;
use tracing::Level;

#[derive(Parser, Debug)]
#[clap(
Expand All @@ -31,6 +33,9 @@ struct Opts {
help = "Path to the TOML state bridge service config file"
)]
config: PathBuf,

#[clap(long, help = "Enable datadog backend for instrumentation")]
datadog: bool,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -76,12 +81,20 @@ struct Config {
block_confirmations: Option<usize>,
}

const SERVICE_NAME: &str = "state-bridge-service";

#[tokio::main]
async fn main() -> eyre::Result<()> {
let opts = Opts::parse();
let contents = fs::read_to_string(&opts.config)?;
let config: Config = toml::from_str(&contents)?;

if opts.datadog {
init_datadog_subscriber(SERVICE_NAME, Level::INFO);
} else {
init_subscriber(Level::INFO);
}

spawn_state_bridge_service(
config.rpc_url,
config.private_key,
Expand All @@ -92,6 +105,8 @@ async fn main() -> eyre::Result<()> {
)
.await?;

shutdown_tracer_provider();

Ok(())
}

Expand Down
14 changes: 11 additions & 3 deletions bin/tree_availability_service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::sync::Arc;

use clap::Parser;
use common::tracing::init_subscriber;
use common::metrics::init_statsd_exporter;
use common::shutdown_tracer_provider;
use common::tracing::{init_datadog_subscriber, init_subscriber};
use ethers::providers::{Http, Provider};
use ethers::types::H160;
use futures::stream::FuturesUnordered;
Expand Down Expand Up @@ -52,13 +54,17 @@ struct Opts {
datadog: bool,
}

const SERVICE_NAME: &str = "tree-availability-service";
const METRICS_HOST: &str = "localhost";
const METRICS_PORT: u16 = 8125;

#[tokio::main]
pub async fn main() -> eyre::Result<()> {
let opts = Opts::parse();

if opts.datadog {
todo!("Initialize datadog tracing backend");
// init_datadog_subscriber("tree-availability-service", Level::INFO);
init_datadog_subscriber(SERVICE_NAME, Level::INFO);
init_statsd_exporter(METRICS_HOST, METRICS_PORT);
} else {
init_subscriber(Level::INFO);
}
Expand All @@ -82,5 +88,7 @@ pub async fn main() -> eyre::Result<()> {
result??;
}

shutdown_tracer_provider();

Ok(())
}
8 changes: 7 additions & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ opentelemetry = { version = "0.20.0", features = ["rt-tokio"] }
opentelemetry-datadog = {verison = "0.8.0", features = ["reqwest-client"]}
tracing = "0.1.40"
tracing-opentelemetry = "0.21.0"
tracing-subscriber = {version = "0.3.17", features = ["env-filter"]}
tracing-subscriber = {version = "0.3.17", features = ["env-filter", "json"]}
tokio = "1.33.0"
http = "0.2.9"
opentelemetry-http = "0.9.0"
serde_json = "1.0.108"
tracing-serde = "0.1.3"
chrono = "0.4.31"
tracing-appender = "0.2.2"
dirs = "5.0.1"
metrics-exporter-statsd = "0.6.0"
2 changes: 2 additions & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod metrics;
pub mod test_utilities;
pub mod tracing;
pub use opentelemetry::global::shutdown_tracer_provider;
12 changes: 12 additions & 0 deletions crates/common/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use metrics_exporter_statsd::StatsdBuilder;

pub fn init_statsd_exporter(host: &str, port: u16) {
//TODO: update these to be args
let recorder = StatsdBuilder::from(host, port)
.with_queue_size(5000)
.with_buffer_size(1024)
.build(None)
.expect("Could not create StatsdRecorder");

metrics::set_boxed_recorder(Box::new(recorder)).expect("TODO:");
}
Loading

0 comments on commit e583d7d

Please sign in to comment.