Skip to content

Commit

Permalink
feat: add tracing setup for worker and controller binaries (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
lffg authored Apr 12, 2024
1 parent 3b4401a commit 537292f
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 3 deletions.
129 changes: 129 additions & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["ctl", "proto", "worker"]
members = ["crates/*", "ctl", "proto", "worker"]
resolver = "2"

[workspace.package]
Expand All @@ -10,6 +10,7 @@ edition = "2021"
# Internal deps
ctl.path = "ctl"
proto.path = "proto"
setup.path = "crates/setup"
worker.path = "worker"
# External deps (keep alphabetically sorted)
axum = "0.7"
Expand All @@ -31,6 +32,8 @@ tokio = { version = "1.36", features = [
"time",
"sync",
] }
tracing = "0.1"
tracing-subscriber = "0.3"
uuid = { version = "1", features = ["serde", "v4"] }

[workspace.lints.clippy]
Expand Down
10 changes: 10 additions & 0 deletions crates/setup/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "setup"
version.workspace = true
edition.workspace = true

[dependencies]
tracing-subscriber.workspace = true

[lints]
workspace = true
4 changes: 4 additions & 0 deletions crates/setup/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// Sets up tracing.
pub fn tracing() {
tracing_subscriber::fmt::init();
}
3 changes: 3 additions & 0 deletions ctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ edition.workspace = true
workspace = true

[dependencies]
setup.workspace = true

tracing.workspace = true
6 changes: 5 additions & 1 deletion ctl/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use tracing::info;

fn main() {
println!("Hello, world!");
setup::tracing();

info!("started controller");
}
5 changes: 4 additions & 1 deletion worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ edition.workspace = true
workspace = true

[dependencies]
setup.workspace = true
proto.workspace = true

clap.workspace = true
eyre.workspace = true
proto.workspace = true
sysinfo.workspace = true
tokio.workspace = true
tracing.workspace = true
1 change: 1 addition & 0 deletions worker/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{net::SocketAddr, time::Duration};

use clap::{value_parser, Parser};

#[derive(Debug)]
pub struct WorkerArgs {
/// Controller's address.
pub controller_addr: SocketAddr,
Expand Down
4 changes: 4 additions & 0 deletions worker/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use eyre::Result;
use tokio::time::sleep;
use tracing::info;

use crate::{args::WorkerArgs, monitor::collector::MetricsCollector};

Expand All @@ -8,7 +9,10 @@ mod monitor;

#[tokio::main]
async fn main() -> Result<()> {
setup::tracing();

let args = WorkerArgs::parse();
info!(?args, "started worker");

let mut metrics_report: MetricsCollector = MetricsCollector::new();

Expand Down

0 comments on commit 537292f

Please sign in to comment.