From bdabe6bbd748aadeeb0ac7130b199f7550f6c7bc Mon Sep 17 00:00:00 2001 From: Michael Jeffrey Date: Thu, 16 May 2024 11:32:56 -0700 Subject: [PATCH 1/3] settings shenans (#814) * mobile_config client humantime serde for durations * Remove public from unused serde default functions * Remove unused * Remove unused settings --- Cargo.lock | 1 + boost_manager/src/settings.rs | 4 +- denylist/src/settings.rs | 4 +- ingest/src/settings.rs | 14 +++---- iot_config/src/client/settings.rs | 6 +-- iot_config/src/settings.rs | 6 +-- iot_packet_verifier/src/settings.rs | 10 ++--- iot_verifier/src/settings.rs | 17 --------- mobile_config/Cargo.toml | 1 + .../src/client/authorization_client.rs | 2 +- .../src/client/carrier_service_client.rs | 2 +- mobile_config/src/client/entity_client.rs | 2 +- mobile_config/src/client/gateway_client.rs | 2 +- mobile_config/src/client/settings.rs | 37 +++++++++---------- mobile_config/src/settings.rs | 4 +- poc_entropy/src/settings.rs | 6 +-- price/src/settings.rs | 2 +- 17 files changed, 49 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea3e21f96..1686aeb45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4590,6 +4590,7 @@ dependencies = [ "hextree", "http 0.2.11", "http-serde", + "humantime-serde", "lazy_static", "metrics", "metrics-exporter-prometheus", diff --git a/boost_manager/src/settings.rs b/boost_manager/src/settings.rs index 2679a781d..bd0a6f32b 100644 --- a/boost_manager/src/settings.rs +++ b/boost_manager/src/settings.rs @@ -56,11 +56,11 @@ fn default_activation_check_interval() -> Duration { humantime::parse_duration("15 minutes").unwrap() } -pub fn default_start_after() -> DateTime { +fn default_start_after() -> DateTime { DateTime::UNIX_EPOCH } -pub fn default_log() -> String { +fn default_log() -> String { "boost_manager=info".to_string() } diff --git a/denylist/src/settings.rs b/denylist/src/settings.rs index 1c46da190..8873606a4 100644 --- a/denylist/src/settings.rs +++ b/denylist/src/settings.rs @@ -23,11 +23,11 @@ pub struct Settings { pub sign_keys: Vec, } -pub fn default_log() -> String { +fn default_log() -> String { "denylist=debug".to_string() } -pub fn default_denylist_url() -> String { +fn default_denylist_url() -> String { "https://api.github.com/repos/helium/denylist/releases/latest".to_string() } diff --git a/ingest/src/settings.rs b/ingest/src/settings.rs index 3b0f648f6..ad3e73671 100644 --- a/ingest/src/settings.rs +++ b/ingest/src/settings.rs @@ -41,30 +41,26 @@ pub struct Settings { pub metrics: poc_metrics::Settings, } -pub fn default_session_key_timeout() -> Duration { +fn default_session_key_timeout() -> Duration { humantime::parse_duration("30 minutes").unwrap() } -pub fn default_session_key_offer_timeout() -> Duration { +fn default_session_key_offer_timeout() -> Duration { humantime::parse_duration("5 seconds").unwrap() } -pub fn default_listen_addr() -> SocketAddr { +fn default_listen_addr() -> SocketAddr { "0.0.0.0:9081".parse().unwrap() } -pub fn default_log() -> String { +fn default_log() -> String { "ingest=debug,poc_store=info".to_string() } -pub fn default_tracing_cfg_file() -> String { +fn default_tracing_cfg_file() -> String { "tracing.cfg".to_string() } -pub fn default_sink() -> String { - "/var/data/ingest".to_string() -} - /// Mode to deploy the ingest engine in. Each mode exposes different submission /// grpc methods #[derive(Debug, Deserialize)] diff --git a/iot_config/src/client/settings.rs b/iot_config/src/client/settings.rs index 28efa9ba3..fc9e50c46 100644 --- a/iot_config/src/client/settings.rs +++ b/iot_config/src/client/settings.rs @@ -21,15 +21,15 @@ pub struct Settings { pub batch_size: u32, } -pub fn default_connect_timeout() -> u64 { +fn default_connect_timeout() -> u64 { 5 } -pub fn default_rpc_timeout() -> u64 { +fn default_rpc_timeout() -> u64 { 5 } -pub fn default_batch_size() -> u32 { +fn default_batch_size() -> u32 { 1000 } diff --git a/iot_config/src/settings.rs b/iot_config/src/settings.rs index ebf3c3dbf..ba8f05112 100644 --- a/iot_config/src/settings.rs +++ b/iot_config/src/settings.rs @@ -25,15 +25,15 @@ pub struct Settings { pub metrics: poc_metrics::Settings, } -pub fn default_log() -> String { +fn default_log() -> String { "iot_config=debug".to_string() } -pub fn default_listen_addr() -> SocketAddr { +fn default_listen_addr() -> SocketAddr { "0.0.0.0:8080".parse().unwrap() } -pub fn default_deleted_entry_retention() -> Duration { +fn default_deleted_entry_retention() -> Duration { humantime::parse_duration("48 hours").unwrap() } diff --git a/iot_packet_verifier/src/settings.rs b/iot_packet_verifier/src/settings.rs index e7bd45c52..807e44421 100644 --- a/iot_packet_verifier/src/settings.rs +++ b/iot_packet_verifier/src/settings.rs @@ -34,23 +34,23 @@ pub struct Settings { pub monitor_funds_period: Duration, } -pub fn default_start_after() -> DateTime { +fn default_start_after() -> DateTime { DateTime::UNIX_EPOCH } -pub fn default_burn_period() -> Duration { +fn default_burn_period() -> Duration { humantime::parse_duration("1 minute").unwrap() } -pub fn default_log() -> String { +fn default_log() -> String { "iot_packet_verifier=debug".to_string() } -pub fn default_minimum_allowed_balance() -> u64 { +fn default_minimum_allowed_balance() -> u64 { 3_500_000 } -pub fn default_monitor_funds_period() -> Duration { +fn default_monitor_funds_period() -> Duration { humantime::parse_duration("30 minutes").unwrap() } diff --git a/iot_verifier/src/settings.rs b/iot_verifier/src/settings.rs index 34993eb9c..8a8af7a8c 100644 --- a/iot_verifier/src/settings.rs +++ b/iot_verifier/src/settings.rs @@ -51,10 +51,6 @@ pub struct Settings { /// beaconing bucket sizes #[serde(with = "humantime_serde", default = "default_beacon_interval")] pub beacon_interval: Duration, - // FIXME: unused - /// Trigger interval for generating a transmit scaling map - #[serde(with = "humantime_serde", default = "default_transmit_scale_interval")] - pub transmit_scale_interval: Duration, // roll up time defined in the ingestors ( in seconds ) // ie the time after which they will write out files to s3 // this will be used when padding out the witness @@ -70,10 +66,6 @@ pub struct Settings { /// cadence for how often to look for poc reports from s3 buckets #[serde(with = "humantime_serde", default = "default_poc_loader_poll_time")] pub poc_loader_poll_time: Duration, - // FIXME: unused - /// the lifespan of a piece of entropy - #[serde(with = "humantime_serde", default = "default_entropy_lifespan ")] - pub entropy_lifespan: Duration, /// max window age for the poc report loader ( in seconds ) /// the starting point of the window will never be older than now - max age #[serde( @@ -123,10 +115,6 @@ fn default_entropy_interval() -> Duration { humantime::parse_duration("5 minutes").unwrap() } -fn default_entropy_lifespan() -> Duration { - humantime::parse_duration("5 minutes").unwrap() -} - fn default_poc_loader_window_width() -> Duration { humantime::parse_duration("5 minutes").unwrap() } @@ -149,10 +137,6 @@ fn default_beacon_interval() -> Duration { humantime::parse_duration("6 hours").unwrap() } -fn default_transmit_scale_interval() -> Duration { - humantime::parse_duration("30 minutes").unwrap() -} - fn default_log() -> String { "iot_verifier=debug,poc_store=info".to_string() } @@ -228,7 +212,6 @@ impl Settings { } pub fn beacon_interval(&self) -> anyhow::Result { - // FIXME: // validate the beacon_interval value is a factor of 24, if not bail out if (24 * 60 * 60) % self.beacon_interval.as_secs() != 0 { bail!("beacon interval is not a factor of 24") diff --git a/mobile_config/Cargo.toml b/mobile_config/Cargo.toml index 63cd3f5a6..25364bead 100644 --- a/mobile_config/Cargo.toml +++ b/mobile_config/Cargo.toml @@ -43,6 +43,7 @@ tracing-subscriber = {workspace = true} triggered = {workspace = true} task-manager = { path = "../task_manager" } solana-sdk = {workspace = true} +humantime-serde = { workspace = true } [dev-dependencies] rand = { workspace = true } diff --git a/mobile_config/src/client/authorization_client.rs b/mobile_config/src/client/authorization_client.rs index 37a99d2f4..8a4144a0e 100644 --- a/mobile_config/src/client/authorization_client.rs +++ b/mobile_config/src/client/authorization_client.rs @@ -43,7 +43,7 @@ impl AuthorizationClient { client: settings.connect_authorization_client(), signing_key: settings.signing_keypair()?, config_pubkey: settings.config_pubkey()?, - cache_ttl: settings.cache_ttl(), + cache_ttl: settings.cache_ttl, cache, }) } diff --git a/mobile_config/src/client/carrier_service_client.rs b/mobile_config/src/client/carrier_service_client.rs index 672612595..3a55ad4dd 100644 --- a/mobile_config/src/client/carrier_service_client.rs +++ b/mobile_config/src/client/carrier_service_client.rs @@ -77,7 +77,7 @@ impl CarrierServiceClient { client: settings.connect_carrier_service_client(), signing_key: settings.signing_keypair()?, config_pubkey: settings.config_pubkey()?, - cache_ttl: settings.cache_ttl(), + cache_ttl: settings.cache_ttl, cache, }) } diff --git a/mobile_config/src/client/entity_client.rs b/mobile_config/src/client/entity_client.rs index dccfd411e..510a882c2 100644 --- a/mobile_config/src/client/entity_client.rs +++ b/mobile_config/src/client/entity_client.rs @@ -74,7 +74,7 @@ impl EntityClient { client: settings.connect_entity_client(), signing_key: settings.signing_keypair()?, config_pubkey: settings.config_pubkey()?, - cache_ttl: settings.cache_ttl(), + cache_ttl: settings.cache_ttl, cache, }) } diff --git a/mobile_config/src/client/gateway_client.rs b/mobile_config/src/client/gateway_client.rs index b27900962..69ab7f128 100644 --- a/mobile_config/src/client/gateway_client.rs +++ b/mobile_config/src/client/gateway_client.rs @@ -35,7 +35,7 @@ impl GatewayClient { signing_key: settings.signing_keypair()?, config_pubkey: settings.config_pubkey()?, batch_size: settings.batch_size, - cache_ttl: settings.cache_ttl(), + cache_ttl: settings.cache_ttl, cache, }) } diff --git a/mobile_config/src/client/settings.rs b/mobile_config/src/client/settings.rs index ff73f8dff..902381fd3 100644 --- a/mobile_config/src/client/settings.rs +++ b/mobile_config/src/client/settings.rs @@ -1,4 +1,5 @@ use helium_proto::services::{mobile_config, Channel, Endpoint}; +use humantime_serde::re::humantime; use serde::Deserialize; use std::{str::FromStr, sync::Arc, time::Duration}; @@ -12,39 +13,39 @@ pub struct Settings { /// B58 encoded public key of the mobile config server for verification pub config_pubkey: String, /// Connect timeout for the mobile config client in seconds. Default 5 - #[serde(default = "default_connect_timeout")] - pub connect_timeout: u64, + #[serde(with = "humantime_serde", default = "default_connect_timeout")] + pub connect_timeout: Duration, /// RPC timeout for mobile config client in seconds. Default 5 - #[serde(default = "default_rpc_timeout")] - pub rpc_timeout: u64, + #[serde(with = "humantime_serde", default = "default_rpc_timeout")] + pub rpc_timeout: Duration, /// Batch size for hotspot metadata stream results. Default 100 #[serde(default = "default_batch_size")] pub batch_size: u32, /// Batch size for hex boosting stream results. Default 100 #[serde(default = "default_hex_boosting_batch_size")] pub hex_boosting_batch_size: u32, - #[serde(default = "default_cache_ttl_in_secs")] - pub cache_ttl_in_secs: u64, + #[serde(with = "humantime_serde", default = "default_cache_ttl_in_secs")] + pub cache_ttl: Duration, } -pub fn default_connect_timeout() -> u64 { - 5 +fn default_connect_timeout() -> Duration { + humantime::parse_duration("5 seconds").unwrap() } -pub fn default_rpc_timeout() -> u64 { - 5 +fn default_rpc_timeout() -> Duration { + humantime::parse_duration("5 seconds").unwrap() } -pub fn default_batch_size() -> u32 { +fn default_batch_size() -> u32 { 100 } -pub fn default_hex_boosting_batch_size() -> u32 { +fn default_hex_boosting_batch_size() -> u32 { 100 } -pub fn default_cache_ttl_in_secs() -> u64 { - 60 * 60 +fn default_cache_ttl_in_secs() -> Duration { + humantime::parse_duration("1 hour").unwrap() } impl Settings { @@ -83,15 +84,11 @@ impl Settings { pub fn config_pubkey(&self) -> Result { helium_crypto::PublicKey::from_str(&self.config_pubkey) } - - pub fn cache_ttl(&self) -> std::time::Duration { - std::time::Duration::from_secs(self.cache_ttl_in_secs) - } } fn connect_channel(settings: &Settings) -> Channel { Endpoint::from(settings.url.clone()) - .connect_timeout(Duration::from_secs(settings.connect_timeout)) - .timeout(Duration::from_secs(settings.rpc_timeout)) + .connect_timeout(settings.connect_timeout) + .timeout(settings.rpc_timeout) .connect_lazy() } diff --git a/mobile_config/src/settings.rs b/mobile_config/src/settings.rs index 1e9bcbedc..76a5afa8d 100644 --- a/mobile_config/src/settings.rs +++ b/mobile_config/src/settings.rs @@ -25,11 +25,11 @@ pub struct Settings { pub metrics: poc_metrics::Settings, } -pub fn default_log() -> String { +fn default_log() -> String { "mobile_config=debug".to_string() } -pub fn default_listen_addr() -> SocketAddr { +fn default_listen_addr() -> SocketAddr { "0.0.0.0:8080".parse().unwrap() } diff --git a/poc_entropy/src/settings.rs b/poc_entropy/src/settings.rs index 74b50d855..f4aad2de3 100644 --- a/poc_entropy/src/settings.rs +++ b/poc_entropy/src/settings.rs @@ -22,15 +22,15 @@ pub struct Settings { pub metrics: poc_metrics::Settings, } -pub fn default_log() -> String { +fn default_log() -> String { "poc_entropy=debug,poc_store=info".to_string() } -pub fn default_cache() -> String { +fn default_cache() -> String { "/var/data/entropy".to_string() } -pub fn default_listen_addr() -> String { +fn default_listen_addr() -> String { "0.0.0.0:8080".to_string() } diff --git a/price/src/settings.rs b/price/src/settings.rs index 1da3adfe9..86d557eeb 100644 --- a/price/src/settings.rs +++ b/price/src/settings.rs @@ -81,7 +81,7 @@ fn default_stale_price_duration() -> Duration { humantime::parse_duration("12 hours").unwrap() } -pub fn default_cache() -> String { +fn default_cache() -> String { "/var/data/price".to_string() } From c4e3d4ae2c7233d053964e16f11cf8b0def6f786 Mon Sep 17 00:00:00 2001 From: macpie Date: Thu, 16 May 2024 15:11:03 -0700 Subject: [PATCH 2/3] Revert "Revert "Attempt to make CI faster"" (#813) * Revert "Revert "Attempt to make CI faster" (#809)" This reverts commit a6d1430067f27ff239ddb54130cc44d688fe21b3. * Test Debian packaging without tag * Remove comments * Rename to try to trigger * Comment matrix for now * Empty matrix does not work comment the all thing * Change trigger * Add some log line * More logs * Add random version * Revert comments * Get back to using $VERSION * Fix package * Add build-release to main CI * Make it into 1 workflow * Separate test with postgres * remove env in tests * Experiment * Update readme * Add protoc to clippy2 * Move clippy --- .github/scripts/make_debian.sh | 7 +- .github/workflows/CI.yml | 201 +++++++++++++++++++++++++++++++++ .github/workflows/rust.yml | 71 ------------ README.md | 11 +- 4 files changed, 214 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/CI.yml delete mode 100644 .github/workflows/rust.yml diff --git a/.github/scripts/make_debian.sh b/.github/scripts/make_debian.sh index 10603f900..1cffe127b 100644 --- a/.github/scripts/make_debian.sh +++ b/.github/scripts/make_debian.sh @@ -99,14 +99,19 @@ run_fpm() sudo apt update sudo apt install --yes ruby sudo gem install fpm -v 1.14.2 # current as of 2022-11-08 +echo "ruby deps installed" for config_path in $( find . -name 'settings-template.toml' ) do oracle=$(echo $config_path | sed -E 's!\./([^/]+)/.+$!\1!' | sed -E 's!_!-!g') - + + echo "starting $oracle $config_path $VERSION" write_unit_template $oracle + echo "write_unit_template $oracle done" write_prepost_template $oracle + echo "write_prepost_template $oracle done" run_fpm $oracle $config_path $VERSION + echo "run_fpm $oracle done" done for deb in /tmp/*.deb diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 000000000..c6258f443 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,201 @@ +name: CI + +on: + pull_request: + branches: [main] + push: + branches: ["main"] + tags: ["*"] + +env: + CARGO_INCREMENTAL: 0 # this setting is automatically applied by rust-cache but documented here for explicitness + CARGO_NET_RETRY: 10 + RUST_BACKTRACE: short + RUSTFLAGS: "-D warnings" + RUSTUP_MAX_RETRIES: 10 + +jobs: + + build: + runs-on: oracles-20.04 + concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-build + cancel-in-progress: true + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Rust install + uses: dtolnay/rust-toolchain@stable + + - name: Install protoc + run: sudo apt-get install -y protobuf-compiler + + - name: Cache + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Build + run: cargo build --all --tests + + fmt: + runs-on: oracles-20.04 + concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-fmt + cancel-in-progress: true + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Rust install + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + + - name: Check formatting + run: cargo fmt -- --check + + clippy: + runs-on: oracles-20.04 + concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-clippy + cancel-in-progress: true + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Rust install + uses: dtolnay/rust-toolchain@stable + with: + components: clippy + + - name: Install protoc + run: sudo apt-get install -y protobuf-compiler + + - name: Clippy + run: cargo clippy --all-targets -- -Dclippy::all -D warnings + + tests-postgres: + needs: build + runs-on: oracles-20.04 + strategy: + fail-fast: false + matrix: + package: [boost-manager,iot-config,iot-packet-verifier,iot-verifier,mobile-config,mobile-verifier] + concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-tests-postgres-${{ matrix.package }} + cancel-in-progress: true + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Rust install + uses: dtolnay/rust-toolchain@stable + + - name: Install protoc + run: sudo apt-get install -y protobuf-compiler + + - name: Cache + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Run unit and integration tests + env: + DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres" + run: cargo test -p ${{ matrix.package }} -- --include-ignored + + tests: + needs: build + runs-on: oracles-20.04 + strategy: + fail-fast: false + matrix: + package: [file-store,ingest,mobile-packet-verifier,reward-scheduler,task-manager] + concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-tests-${{ matrix.package }} + cancel-in-progress: true + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Rust install + uses: dtolnay/rust-toolchain@stable + + - name: Install protoc + run: sudo apt-get install -y protobuf-compiler + + - name: Cache + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Run unit and integration tests + run: cargo test -p ${{ matrix.package }} -- --include-ignored + + build-release: + needs: [fmt, clippy, tests, tests-postgres] + runs-on: oracles-20.04 + concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-build-release + cancel-in-progress: true + if: contains(github.ref, 'refs/tags/') + steps: + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@stable + + - name: Install protoc + run: sudo apt-get install -y protobuf-compiler + + - name: Cache + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Build Release + run: cargo build --all --release + + - name: Debian packaging + env: + PACKAGECLOUD_API_KEY: ${{ secrets.PACKAGECLOUD_API_KEY }} + run: | + chmod +x ./.github/scripts/make_debian.sh + ./.github/scripts/make_debian.sh \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index c141ecc9e..000000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,71 +0,0 @@ -name: CI - -on: - pull_request: - branches: [main] - push: - branches: [main] - tags: ["*"] - -env: - CARGO_INCREMENTAL: 0 # this setting is automatically applied by rust-cache but documented here for explicitness - CARGO_NET_RETRY: 10 - RUST_BACKTRACE: short - RUSTFLAGS: "-D warnings" - RUSTUP_MAX_RETRIES: 10 - -jobs: - build: - runs-on: oracles-20.04 - - services: - postgres: - image: postgres - env: - POSTGRES_PASSWORD: postgres - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 - - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable - with: - components: clippy, rustfmt - - - name: Install protoc - run: sudo apt-get install -y protobuf-compiler - - - name: Setup cache - uses: Swatinem/rust-cache@v2 - - - name: Cancel previous runs - uses: styfle/cancel-workflow-action@0.11.0 - with: - access_token: ${{ github.token }} - - - name: Build - run: cargo build --all --release - - - name: Check formatting - run: cargo fmt -- --check - - - name: Clippy - run: cargo clippy --all-targets -- -Dclippy::all -D warnings - - - name: Run unit and integration tests - env: - DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres" - run: cargo test -r -- --include-ignored - - - name: Debian packaging - if: contains(github.ref, 'refs/tags/') - env: - PACKAGECLOUD_API_KEY: ${{ secrets.PACKAGECLOUD_API_KEY }} - run: | - chmod +x ./.github/scripts/make_debian.sh - ./.github/scripts/make_debian.sh diff --git a/README.md b/README.md index 5d741c250..eae2d542e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ flowchart TD MPV("`**Mobile Packet Verifier** - Burns DC for data transfer (on solana) `") - MB("`**Mobile Price** + MP("`**Mobile Price** - Records Pyth price for MOBILE `") DB1[(Foundation owned db populated by helius)] @@ -31,12 +31,15 @@ flowchart TD - Writes rewards to foundation db `") DB2[(Foundation owned db that stores reward totals)] + S[(Solana)] MI -- S3 --> MV MI -- S3 --> MPV MPV -- S3 --> MV - MB -- S3 --> MV - DB1 --> MB - MB --> MC + MPV -- gRPC --> MC + MPV --> S + MP <--> S + MP -- S3 --> MV + DB1 --> MC MC -- gRPC --> MV MV -- S3 --> MRI MRI --> DB2 From 79c8dae0b9743628c206a383f0fd0a90b2f7fa3b Mon Sep 17 00:00:00 2001 From: macpie Date: Thu, 16 May 2024 15:15:17 -0700 Subject: [PATCH 3/3] Macpie/custom tracing everywhere (#810) * Add custom tracing to boost manager * Add tracing layer to ingest iot server * Fix unused imports * Add custom tracing to iot_config * Add custom tracing to iot_packet_verifier * Remove unused imports * Add custom tracing to iot_verifier * Add custom tracing for mobile config * Fix clippy * Add custom-tracing to mobile_packet_verifier * Add custom-tracing to mobile_verifier * Add custom-tracing to poc_entropy * Add custom-tracing to price * Add custom-tracing to reward_index * Make custom-tracing settings * Add default settings * logs settings * format * Add default span name * Use [serde(default)] * Create custom_tracing::record_b58 --------- Co-authored-by: Michael Jeffrey --- Cargo.lock | 12 +++ boost_manager/Cargo.toml | 67 +++++++++-------- boost_manager/src/main.rs | 6 +- boost_manager/src/settings.rs | 2 + custom_tracing/Cargo.toml | 2 + custom_tracing/src/lib.rs | 19 ++++- custom_tracing/src/settings.rs | 12 +++ ingest/src/main.rs | 2 +- ingest/src/server_iot.rs | 12 +++ ingest/src/server_mobile.rs | 20 ++--- ingest/src/settings.rs | 9 +-- iot_config/Cargo.toml | 65 +++++++++-------- iot_config/src/admin_service.rs | 14 +++- iot_config/src/gateway_service.rs | 5 ++ iot_config/src/main.rs | 17 +++-- iot_config/src/org_service.rs | 13 +++- iot_config/src/route_service.rs | 22 +++++- iot_config/src/settings.rs | 2 + iot_packet_verifier/Cargo.toml | 59 ++++++++------- iot_packet_verifier/src/main.rs | 6 +- iot_packet_verifier/src/settings.rs | 2 + iot_verifier/Cargo.toml | 69 +++++++++--------- iot_verifier/src/main.rs | 6 +- iot_verifier/src/settings.rs | 2 + mobile_config/Cargo.toml | 71 +++++++++--------- mobile_config/src/admin_service.rs | 4 + mobile_config/src/authorization_service.rs | 3 + mobile_config/src/carrier_service.rs | 2 + mobile_config/src/entity_service.rs | 1 + mobile_config/src/gateway_service.rs | 4 + mobile_config/src/hex_boosting_service.rs | 2 + mobile_config/src/main.rs | 16 ++-- mobile_config/src/settings.rs | 2 + mobile_packet_verifier/Cargo.toml | 63 ++++++++-------- mobile_packet_verifier/src/main.rs | 6 +- mobile_packet_verifier/src/settings.rs | 2 + mobile_verifier/Cargo.toml | 85 +++++++++++----------- mobile_verifier/src/main.rs | 6 +- mobile_verifier/src/settings.rs | 2 + poc_entropy/Cargo.toml | 33 +++++---- poc_entropy/src/main.rs | 7 +- poc_entropy/src/server.rs | 5 ++ poc_entropy/src/settings.rs | 2 + price/Cargo.toml | 33 +++++---- price/src/main.rs | 7 +- price/src/settings.rs | 2 + reward_index/Cargo.toml | 51 ++++++------- reward_index/src/main.rs | 7 +- reward_index/src/settings.rs | 2 + 49 files changed, 491 insertions(+), 372 deletions(-) create mode 100644 custom_tracing/src/settings.rs diff --git a/Cargo.lock b/Cargo.lock index 1686aeb45..39e95b2ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1559,6 +1559,7 @@ dependencies = [ "chrono", "clap 4.4.8", "config", + "custom-tracing", "db-store", "file-store", "futures", @@ -2332,9 +2333,11 @@ version = "0.1.0" dependencies = [ "anyhow", "axum 0.7.4", + "bs58 0.4.0", "helium-proto", "http 0.2.11", "notify", + "serde", "tokio", "tower-http", "tower-layer", @@ -3958,6 +3961,7 @@ dependencies = [ "chrono", "clap 4.4.8", "config", + "custom-tracing", "db-store", "file-store", "futures", @@ -3999,6 +4003,7 @@ dependencies = [ "chrono", "clap 4.4.8", "config", + "custom-tracing", "db-store", "file-store", "futures", @@ -4038,6 +4043,7 @@ dependencies = [ "clap 4.4.8", "cmake", "config", + "custom-tracing", "db-store", "denylist", "file-store", @@ -4581,6 +4587,7 @@ dependencies = [ "chrono", "clap 4.4.8", "config", + "custom-tracing", "db-store", "file-store", "futures", @@ -4656,6 +4663,7 @@ dependencies = [ "chrono", "clap 4.4.8", "config", + "custom-tracing", "db-store", "file-store", "futures", @@ -4693,6 +4701,7 @@ dependencies = [ "chrono", "clap 4.4.8", "config", + "custom-tracing", "db-store", "file-store", "flate2", @@ -5329,6 +5338,7 @@ dependencies = [ "chrono", "clap 4.4.8", "config", + "custom-tracing", "file-store", "futures", "futures-util", @@ -5410,6 +5420,7 @@ dependencies = [ "chrono", "clap 4.4.8", "config", + "custom-tracing", "file-store", "futures", "futures-util", @@ -5972,6 +5983,7 @@ dependencies = [ "chrono", "clap 4.4.8", "config", + "custom-tracing", "db-store", "file-store", "futures", diff --git a/boost_manager/Cargo.toml b/boost_manager/Cargo.toml index cadf8b971..1a3115a70 100644 --- a/boost_manager/Cargo.toml +++ b/boost_manager/Cargo.toml @@ -8,44 +8,49 @@ license.workspace = true [dependencies] -anyhow = {workspace = true} -axum = {version = "0", features = ["tracing"]} -bs58 = {workspace = true} -config = {workspace = true} -clap = {workspace = true} -thiserror = {workspace = true} -serde = {workspace = true} -serde_json = {workspace = true} -sqlx = {workspace = true} -base64 = {workspace = true} -sha2 = {workspace = true} -lazy_static = {workspace = true} -triggered = {workspace = true} -futures = {workspace = true} -futures-util = {workspace = true} -prost = {workspace = true} -once_cell = {workspace = true} -mobile-config = {path = "../mobile_config"} -file-store = {path = "../file_store"} +anyhow = { workspace = true } +axum = { version = "0", features = ["tracing"] } +bs58 = { workspace = true } +config = { workspace = true } +clap = { workspace = true } +thiserror = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +sqlx = { workspace = true } +base64 = { workspace = true } +sha2 = { workspace = true } +lazy_static = { workspace = true } +triggered = { workspace = true } +futures = { workspace = true } +futures-util = { workspace = true } +prost = { workspace = true } +once_cell = { workspace = true } +mobile-config = { path = "../mobile_config" } +file-store = { path = "../file_store" } db-store = { path = "../db_store" } -poc-metrics = {path = "../metrics"} +poc-metrics = { path = "../metrics" } tokio = { workspace = true } tokio-util = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } chrono = { workspace = true, features = ["serde"] } -metrics = {workspace = true } +metrics = { workspace = true } metrics-exporter-prometheus = { workspace = true } helium-proto = { workspace = true } -helium-crypto = {workspace = true, features = ["sqlx-postgres", "multisig", "solana"]} -rust_decimal = {workspace = true} -rust_decimal_macros = {workspace = true} -tonic = {workspace = true} -rand = {workspace = true} -async-trait = {workspace = true} +helium-crypto = { workspace = true, features = [ + "sqlx-postgres", + "multisig", + "solana", +] } +rust_decimal = { workspace = true } +rust_decimal_macros = { workspace = true } +tonic = { workspace = true } +rand = { workspace = true } +async-trait = { workspace = true } task-manager = { path = "../task_manager" } -http = {workspace = true} -http-serde = {workspace = true} -solana = {path = "../solana"} -solana-sdk = {workspace = true} +http = { workspace = true } +http-serde = { workspace = true } +solana = { path = "../solana" } +solana-sdk = { workspace = true } humantime-serde = { workspace = true } +custom-tracing = { path = "../custom_tracing" } diff --git a/boost_manager/src/main.rs b/boost_manager/src/main.rs index f3be11d49..061868925 100644 --- a/boost_manager/src/main.rs +++ b/boost_manager/src/main.rs @@ -13,7 +13,6 @@ use mobile_config::client::hex_boosting_client::HexBoostingClient; use solana::start_boost::SolanaRpc; use std::path::{self, PathBuf}; use task_manager::TaskManager; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[derive(Debug, clap::Parser)] #[clap(version = env!("CARGO_PKG_VERSION"))] @@ -54,10 +53,7 @@ pub struct Server {} impl Server { pub async fn run(&self, settings: &Settings) -> Result<()> { - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::new(&settings.log)) - .with(tracing_subscriber::fmt::layer()) - .init(); + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; // Install the prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; diff --git a/boost_manager/src/settings.rs b/boost_manager/src/settings.rs index bd0a6f32b..809457d6b 100644 --- a/boost_manager/src/settings.rs +++ b/boost_manager/src/settings.rs @@ -10,6 +10,8 @@ pub struct Settings { /// "poc_entropy=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, + #[serde(default)] + pub custom_tracing: custom_tracing::Settings, /// Cache location for generated verified reports pub cache: String, /// Reward files check interval in seconds. (Default is 15 minutes) diff --git a/custom_tracing/Cargo.toml b/custom_tracing/Cargo.toml index 83ba8bd3a..1d70856ec 100644 --- a/custom_tracing/Cargo.toml +++ b/custom_tracing/Cargo.toml @@ -6,6 +6,7 @@ license.workspace = true edition.workspace = true [dependencies] +serde = { version = "1", features = ["derive"] } notify = { version = "6", default-features = false } anyhow = "1" tokio = { version = "1", features = ["rt-multi-thread", "sync", "signal"] } @@ -20,6 +21,7 @@ tower-layer = { version = "0" } axum = { version = "0.7", features = ["tracing"], optional = true } helium-proto = { workspace = true, optional = true } http = { workspace = true, optional = true } +bs58 = { version = "0.4", features = ["check"] } [target.'cfg(target_os = "macos")'.dependencies] diff --git a/custom_tracing/src/lib.rs b/custom_tracing/src/lib.rs index 03a4e03c3..d173ac97f 100644 --- a/custom_tracing/src/lib.rs +++ b/custom_tracing/src/lib.rs @@ -1,5 +1,7 @@ use anyhow::Result; use notify::{event::DataChange, Config, RecommendedWatcher, RecursiveMode, Watcher}; +mod settings; +pub use settings::Settings; use std::{fs, path::Path}; use tracing::Span; use tracing_subscriber::{ @@ -14,7 +16,9 @@ pub mod grpc_layer; #[cfg(feature = "http-1")] pub mod http_layer; -pub async fn init(og_filter: String, tracing_cfg_file: String) -> Result<()> { +pub const DEFAULT_SPAN: &str = "tracing"; + +pub async fn init(og_filter: String, settings: Settings) -> Result<()> { let (filtered_layer, reload_handle) = reload::Layer::new(tracing_subscriber::EnvFilter::new(og_filter.clone())); @@ -23,10 +27,13 @@ pub async fn init(og_filter: String, tracing_cfg_file: String) -> Result<()> { .with(tracing_subscriber::fmt::layer()) .init(); + let filter = og_filter.clone(); + let cfg_file = settings.tracing_cfg_file.clone(); + tokio::spawn(async move { let state = State { og_filter: og_filter.clone(), - tracing_cfg_file, + tracing_cfg_file: settings.tracing_cfg_file, reload_handle, }; if let Err(err) = state.watch().await { @@ -34,7 +41,7 @@ pub async fn init(og_filter: String, tracing_cfg_file: String) -> Result<()> { } }); - tracing::info!("custom tracing installed"); + tracing::info!(filter, cfg_file, "custom tracing installed"); Ok(()) } @@ -46,6 +53,12 @@ where Span::current().record(field, &tracing::field::display(value)); } +pub fn record_b58(key: &str, pub_key: &[u8]) { + let b58 = bs58::encode(pub_key).into_string(); + + record(key, b58); +} + #[derive(Clone)] pub struct State { pub og_filter: String, diff --git a/custom_tracing/src/settings.rs b/custom_tracing/src/settings.rs new file mode 100644 index 000000000..d0fd86bb9 --- /dev/null +++ b/custom_tracing/src/settings.rs @@ -0,0 +1,12 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +pub struct Settings { + /// File name to be watched by custom tracing + #[serde(default = "default_tracing_cfg_file")] + pub tracing_cfg_file: String, +} + +pub fn default_tracing_cfg_file() -> String { + "tracing.cfg".to_string() +} diff --git a/ingest/src/main.rs b/ingest/src/main.rs index 9bd6b117b..4a7f24681 100644 --- a/ingest/src/main.rs +++ b/ingest/src/main.rs @@ -40,7 +40,7 @@ pub struct Server {} impl Server { pub async fn run(&self, settings: &Settings) -> Result<()> { - custom_tracing::init(settings.log.clone(), settings.tracing_cfg_file.clone()).await?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; // Install the prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; diff --git a/ingest/src/server_iot.rs b/ingest/src/server_iot.rs index 737d3254d..2bb4b7dcd 100644 --- a/ingest/src/server_iot.rs +++ b/ingest/src/server_iot.rs @@ -186,6 +186,7 @@ impl ManagedTask for GrpcServer { let address = self.address; Box::pin(async move { let grpc_server = transport::Server::builder() + .layer(custom_tracing::grpc_layer::new_with_span(make_span)) .layer(poc_metrics::request_layer!("ingest_server_iot_connection")) .add_service(poc_lora::Server::new(*self)) .serve(address) @@ -204,6 +205,13 @@ impl ManagedTask for GrpcServer { } } +fn make_span(_request: &http::request::Request) -> tracing::Span { + tracing::info_span!( + custom_tracing::DEFAULT_SPAN, + pub_key = tracing::field::Empty + ) +} + fn verify_public_key(bytes: &[u8]) -> VerifyResult { PublicKey::try_from(bytes).map_err(|_| Status::invalid_argument("invalid public key")) } @@ -289,6 +297,8 @@ impl poc_lora::PocLora for GrpcServer { let timestamp: u64 = Utc::now().timestamp_millis() as u64; let event = request.into_inner(); + custom_tracing::record_b58("pub_key", &event.pub_key); + let pub_key = verify_public_key(&event.pub_key) .and_then(|pk| verify_network(self.required_network, pk))?; @@ -312,6 +322,8 @@ impl poc_lora::PocLora for GrpcServer { let timestamp: u64 = Utc::now().timestamp_millis() as u64; let event = request.into_inner(); + custom_tracing::record_b58("pub_key", &event.pub_key); + let pub_key = verify_public_key(&event.pub_key) .and_then(|pk| verify_network(self.required_network, pk))?; diff --git a/ingest/src/server_mobile.rs b/ingest/src/server_mobile.rs index 60ac67b34..afc1943aa 100644 --- a/ingest/src/server_mobile.rs +++ b/ingest/src/server_mobile.rs @@ -73,7 +73,7 @@ impl ManagedTask for GrpcServer { fn make_span(_request: &http::request::Request) -> tracing::Span { tracing::info_span!( - "tracing", + custom_tracing::DEFAULT_SPAN, pub_key = tracing::field::Empty, subscriber_id = tracing::field::Empty, ) @@ -112,7 +112,7 @@ impl poc_mobile::PocMobile for GrpcServer { let timestamp: u64 = Utc::now().timestamp_millis() as u64; let event = request.into_inner(); - custom_tracing::record("pub_key", pub_key_to_b58(&event.pub_key)); + custom_tracing::record_b58("pub_key", &event.pub_key); let report = self .verify_public_key(event.pub_key.as_ref()) @@ -136,7 +136,7 @@ impl poc_mobile::PocMobile for GrpcServer { let timestamp: u64 = Utc::now().timestamp_millis() as u64; let event = request.into_inner(); - custom_tracing::record("pub_key", pub_key_to_b58(&event.pub_key)); + custom_tracing::record_b58("pub_key", &event.pub_key); let report = self .verify_public_key(event.pub_key.as_ref()) @@ -160,7 +160,7 @@ impl poc_mobile::PocMobile for GrpcServer { let timestamp: u64 = Utc::now().timestamp_millis() as u64; let event = request.into_inner(); - custom_tracing::record("pub_key", pub_key_to_b58(&event.pub_key)); + custom_tracing::record_b58("pub_key", &event.pub_key); let report = self .verify_public_key(event.pub_key.as_ref()) @@ -184,7 +184,7 @@ impl poc_mobile::PocMobile for GrpcServer { let timestamp = Utc::now().timestamp_millis() as u64; let event = request.into_inner(); - custom_tracing::record("pub_key", pub_key_to_b58(&event.pub_key)); + custom_tracing::record_b58("pub_key", &event.pub_key); let report = self .verify_public_key(event.pub_key.as_ref()) @@ -251,7 +251,7 @@ impl poc_mobile::PocMobile for GrpcServer { let cbsd_id = event.cbsd_id.clone(); let threshold_timestamp = event.threshold_timestamp; - custom_tracing::record("pub_key", pub_key_to_b58(&hotspot_pubkey)); + custom_tracing::record_b58("pub_key", &hotspot_pubkey); let report = self .verify_public_key(event.carrier_pub_key.as_ref()) @@ -287,7 +287,7 @@ impl poc_mobile::PocMobile for GrpcServer { let cbsd_id = event.cbsd_id.clone(); let invalidated_timestamp = event.timestamp; - custom_tracing::record("pub_key", pub_key_to_b58(&hotspot_pubkey)); + custom_tracing::record_b58("pub_key", &hotspot_pubkey); let report = self .verify_public_key(event.carrier_pub_key.as_ref()) @@ -323,7 +323,7 @@ impl poc_mobile::PocMobile for GrpcServer { let timestamp: u64 = Utc::now().timestamp_millis() as u64; let event = request.into_inner(); - custom_tracing::record("pub_key", pub_key_to_b58(&event.pub_key)); + custom_tracing::record_b58("pub_key", &event.pub_key); let report = self .verify_public_key(event.pub_key.as_ref()) @@ -484,7 +484,3 @@ pub async fn grpc_server(settings: &Settings) -> Result<()> { .start() .await } - -fn pub_key_to_b58(pub_key: &[u8]) -> String { - bs58::encode(pub_key).into_string() -} diff --git a/ingest/src/settings.rs b/ingest/src/settings.rs index ad3e73671..9c9b8213a 100644 --- a/ingest/src/settings.rs +++ b/ingest/src/settings.rs @@ -10,9 +10,8 @@ pub struct Settings { /// "ingest=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, - /// File name to be watched by custom tracing - #[serde(default = "default_tracing_cfg_file")] - pub tracing_cfg_file: String, + #[serde(default)] + pub custom_tracing: custom_tracing::Settings, /// Mode to run the server in (iot or mobile). Required pub mode: Mode, /// Listen address. Required. Default is 0.0.0.0:9081 @@ -57,10 +56,6 @@ fn default_log() -> String { "ingest=debug,poc_store=info".to_string() } -fn default_tracing_cfg_file() -> String { - "tracing.cfg".to_string() -} - /// Mode to deploy the ingest engine in. Each mode exposes different submission /// grpc methods #[derive(Debug, Deserialize)] diff --git a/iot_config/Cargo.toml b/iot_config/Cargo.toml index 218dffc0f..5e4ff5c22 100644 --- a/iot_config/Cargo.toml +++ b/iot_config/Cargo.toml @@ -7,42 +7,43 @@ authors.workspace = true license.workspace = true [dependencies] -anyhow = {workspace = true} -async-trait = {workspace = true} -base64 = {workspace = true} -bs58 = {workspace = true} -chrono = {workspace = true} -clap = {workspace = true} -config = {workspace = true} -db-store = {path = "../db_store"} -file-store = {path = "../file_store"} -futures = {workspace = true} -futures-util = {workspace = true} -helium-crypto = {workspace = true} -helium-proto = {workspace = true} -hextree = {workspace = true} -http = {workspace = true} -http-serde = {workspace = true} +anyhow = { workspace = true } +async-trait = { workspace = true } +base64 = { workspace = true } +bs58 = { workspace = true } +chrono = { workspace = true } +clap = { workspace = true } +config = { workspace = true } +db-store = { path = "../db_store" } +file-store = { path = "../file_store" } +futures = { workspace = true } +futures-util = { workspace = true } +helium-crypto = { workspace = true } +helium-proto = { workspace = true } +hextree = { workspace = true } +http = { workspace = true } +http-serde = { workspace = true } libflate = "1" -metrics = {workspace = true} -metrics-exporter-prometheus = {workspace = true} -poc-metrics = {path = "../metrics"} -prost = {workspace = true} -retainer = {workspace = true} -serde = {workspace = true} -serde_json = {workspace = true} -sqlx = {workspace = true} -thiserror = {workspace = true} -tokio = {workspace = true} -tokio-stream = {workspace = true} +metrics = { workspace = true } +metrics-exporter-prometheus = { workspace = true } +poc-metrics = { path = "../metrics" } +prost = { workspace = true } +retainer = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +sqlx = { workspace = true } +thiserror = { workspace = true } +tokio = { workspace = true } +tokio-stream = { workspace = true } tokio-util = { workspace = true } -tonic = {workspace = true} -tower-http = {workspace = true} -tracing = {workspace = true} -tracing-subscriber = {workspace = true} -triggered = {workspace = true} +tonic = { workspace = true } +tower-http = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } +triggered = { workspace = true } task-manager = { path = "../task_manager" } humantime-serde = { workspace = true } +custom-tracing = { path = "../custom_tracing", features = ["grpc"] } [dev-dependencies] rand = { workspace = true } diff --git a/iot_config/src/admin_service.rs b/iot_config/src/admin_service.rs index 6260d3058..f5b7e96dd 100644 --- a/iot_config/src/admin_service.rs +++ b/iot_config/src/admin_service.rs @@ -83,6 +83,8 @@ impl iot_config::Admin for AdminService { async fn add_key(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("admin", "add-key"); + custom_tracing::record_b58("pub_key", &request.pubkey); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_admin_request_signature(&signer, &request)?; @@ -103,7 +105,7 @@ impl iot_config::Admin for AdminService { false } }) { - tracing::info!(%pubkey, %key_type, "key authorized"); + tracing::info!(%key_type, "key authorized"); Ok(()) } else { Err(anyhow!("key already registered")) @@ -111,7 +113,7 @@ impl iot_config::Admin for AdminService { }) .map_err(|err| { let pubkey: PublicKeyBinary = request.pubkey.into(); - tracing::error!(%pubkey, "pubkey add failed"); + tracing::error!("pubkey add failed"); Status::internal(format!("error saving requested key: {pubkey}, {err:?}")) }) .await?; @@ -131,6 +133,8 @@ impl iot_config::Admin for AdminService { async fn remove_key(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("admin", "remove-key"); + custom_tracing::record_b58("pub_key", &request.pubkey); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_admin_request_signature(&signer, &request)?; @@ -142,7 +146,7 @@ impl iot_config::Admin for AdminService { self.auth_updater.send_modify(|cache| { cache.remove(&pubkey); }); - tracing::info!(%pubkey, %key_type,"key de-authorized"); + tracing::info!(%key_type,"key de-authorized"); Ok(()) } None => Ok(()), @@ -150,7 +154,7 @@ impl iot_config::Admin for AdminService { }) .map_err(|_| { let pubkey: PublicKeyBinary = request.pubkey.into(); - tracing::error!(%pubkey, "pubkey remove failed"); + tracing::error!("pubkey remove failed"); Status::internal(format!("error removing request key: {pubkey}")) }) .await?; @@ -173,6 +177,7 @@ impl iot_config::Admin for AdminService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("admin", "load-region"); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_admin_request_signature(&signer, &request)?; @@ -239,6 +244,7 @@ impl iot_config::Admin for AdminService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("admin", "region-params"); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; diff --git a/iot_config/src/gateway_service.rs b/iot_config/src/gateway_service.rs index 454ab5cdd..78c5f67d5 100644 --- a/iot_config/src/gateway_service.rs +++ b/iot_config/src/gateway_service.rs @@ -138,6 +138,8 @@ impl iot_config::Gateway for GatewayService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("gateway", "location"); + custom_tracing::record_b58("pub_key", &request.gateway); + custom_tracing::record_b58("signer", &request.signer); self.verify_location_request(&request)?; @@ -178,6 +180,7 @@ impl iot_config::Gateway for GatewayService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("gateway", "region-params"); + custom_tracing::record_b58("pub_key", &request.address); let request_start = std::time::Instant::now(); let pubkey = verify_public_key(&request.address)?; @@ -247,6 +250,8 @@ impl iot_config::Gateway for GatewayService { async fn info(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("gateway", "info"); + custom_tracing::record_b58("pub_key", &request.address); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; diff --git a/iot_config/src/main.rs b/iot_config/src/main.rs index 04982a68b..308652ea2 100644 --- a/iot_config/src/main.rs +++ b/iot_config/src/main.rs @@ -11,7 +11,6 @@ use iot_config::{ use std::{net::SocketAddr, path::PathBuf, sync::Arc, time::Duration}; use task_manager::{ManagedTask, TaskManager}; use tonic::transport; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[derive(Debug, clap::Parser)] #[clap(version = env!("CARGO_PKG_VERSION"))] @@ -52,10 +51,7 @@ pub struct Daemon; impl Daemon { pub async fn run(&self, settings: &Settings) -> Result<()> { - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::new(&settings.log)) - .with(tracing_subscriber::fmt::layer()) - .init(); + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; // Install prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; @@ -145,7 +141,7 @@ impl ManagedTask for GrpcServer { let grpc_server = transport::Server::builder() .http2_keepalive_interval(Some(Duration::from_secs(250))) .http2_keepalive_timeout(Some(Duration::from_secs(60))) - .layer(tower_http::trace::TraceLayer::new_for_grpc()) + .layer(custom_tracing::grpc_layer::new_with_span(make_span)) .add_service(GatewayServer::new(self.gateway_svc)) .add_service(OrgServer::new(self.org_svc)) .add_service(RouteServer::new(self.route_svc)) @@ -171,6 +167,15 @@ impl ManagedTask for GrpcServer { }) } } +fn make_span(_request: &http::request::Request) -> tracing::Span { + tracing::info_span!( + custom_tracing::DEFAULT_SPAN, + pub_key = tracing::field::Empty, + signer = tracing::field::Empty, + oui = tracing::field::Empty, + route_id = tracing::field::Empty, + ) +} #[tokio::main] async fn main() -> Result<()> { diff --git a/iot_config/src/org_service.rs b/iot_config/src/org_service.rs index 5b598bd4d..a7379811f 100644 --- a/iot_config/src/org_service.rs +++ b/iot_config/src/org_service.rs @@ -173,11 +173,12 @@ impl iot_config::Org for OrgService { async fn get(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("org", "get"); + custom_tracing::record("oui", request.oui); let org = org::get(request.oui, &self.pool) .await .map_err(|err| { - tracing::error!(oui = request.oui, reason = ?err, "get org request failed"); + tracing::error!(reason = ?err, "get org request failed"); Status::internal("org get failed") })? .ok_or_else(|| Status::not_found(format!("oui: {}", request.oui)))?; @@ -214,6 +215,8 @@ impl iot_config::Org for OrgService { async fn create_helium(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("org", "create-helium"); + custom_tracing::record_b58("pub_key", &request.owner); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_admin_request_signature(&signer, &request)?; @@ -319,6 +322,8 @@ impl iot_config::Org for OrgService { async fn create_roamer(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("org", "create-roamer"); + custom_tracing::record_b58("pub_key", &request.owner); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_admin_request_signature(&signer, &request)?; @@ -401,6 +406,8 @@ impl iot_config::Org for OrgService { async fn update(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("org", "update"); + custom_tracing::record("oui", request.oui); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; let authorizer = self @@ -450,6 +457,8 @@ impl iot_config::Org for OrgService { async fn disable(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("org", "disable"); + custom_tracing::record("oui", request.oui); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; @@ -487,6 +496,8 @@ impl iot_config::Org for OrgService { async fn enable(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("org", "enable"); + custom_tracing::record("oui", request.oui); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; diff --git a/iot_config/src/route_service.rs b/iot_config/src/route_service.rs index a0b8262e3..5f566311f 100644 --- a/iot_config/src/route_service.rs +++ b/iot_config/src/route_service.rs @@ -190,12 +190,14 @@ impl iot_config::Route for RouteService { async fn list(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("route", "list"); + custom_tracing::record("oui", request.oui); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request, OrgId::Oui(request.oui)) .await?; - tracing::debug!(org = request.oui, "list routes"); + tracing::debug!("list routes"); let proto_routes: Vec = route::list_routes(request.oui, &self.pool) .await @@ -218,6 +220,8 @@ impl iot_config::Route for RouteService { async fn get(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("route", "get"); + custom_tracing::record("route_id", &request.id); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request, OrgId::RouteId(&request.id)) @@ -246,6 +250,8 @@ impl iot_config::Route for RouteService { async fn create(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("route", "create"); + custom_tracing::record("oui", request.oui); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request, OrgId::Oui(request.oui)) @@ -256,7 +262,7 @@ impl iot_config::Route for RouteService { .ok_or("missing route") .map_err(Status::invalid_argument)? .into(); - tracing::debug!(org = request.oui, "route create {route:?}"); + tracing::debug!("route create {route:?}"); if route.oui != request.oui { tracing::warn!( @@ -296,12 +302,17 @@ impl iot_config::Route for RouteService { let request = request.into_inner(); telemetry::count_request("route", "update"); + custom_tracing::record_b58("signer", &request.signer); + let route: Route = request .clone() .route .ok_or("missing route") .map_err(Status::invalid_argument)? .into(); + + custom_tracing::record("route_id", &route.id); + tracing::debug!( org = route.oui, route_id = route.id, @@ -338,6 +349,8 @@ impl iot_config::Route for RouteService { async fn delete(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("route", "delete"); + custom_tracing::record("route_id", &request.id); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request, OrgId::RouteId(&request.id)) @@ -376,6 +389,7 @@ impl iot_config::Route for RouteService { async fn stream(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("route", "stream"); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_stream_request_signature(&signer, &request)?; @@ -426,6 +440,8 @@ impl iot_config::Route for RouteService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("route", "get-euis"); + custom_tracing::record("route_id", &request.route_id); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature_or_stream( @@ -850,6 +866,8 @@ impl iot_config::Route for RouteService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("route", "update-skfs"); + custom_tracing::record("route_id", &request.route_id); + custom_tracing::record_b58("signer", &request.signer); if request.updates.len() > SKF_UPDATE_LIMIT { return Err(Status::invalid_argument( diff --git a/iot_config/src/settings.rs b/iot_config/src/settings.rs index ba8f05112..95938cafa 100644 --- a/iot_config/src/settings.rs +++ b/iot_config/src/settings.rs @@ -9,6 +9,8 @@ pub struct Settings { /// "iot_config=info" #[serde(default = "default_log")] pub log: String, + #[serde(default)] + pub custom_tracing: custom_tracing::Settings, /// Listen address. Required. Default is 0.0.0.0:8080 #[serde(default = "default_listen_addr")] pub listen: SocketAddr, diff --git a/iot_packet_verifier/Cargo.toml b/iot_packet_verifier/Cargo.toml index 6250136d2..8839d09a6 100644 --- a/iot_packet_verifier/Cargo.toml +++ b/iot_packet_verifier/Cargo.toml @@ -7,32 +7,37 @@ authors.workspace = true license.workspace = true [dependencies] -anyhow = {workspace = true} -async-trait = {workspace = true} -clap = {workspace = true} -config = {workspace = true} -chrono = {workspace = true} -db-store = {path = "../db_store"} -futures = {workspace = true} -futures-util = {workspace = true} -file-store = {path = "../file_store"} -helium-proto = {workspace = true} -helium-crypto = {workspace = true, features = ["sqlx-postgres", "multisig", "solana"]} -iot-config = {path = "../iot_config"} -metrics = {workspace = true} -poc-metrics = {path = "../metrics"} -prost = {workspace = true} -serde = {workspace = true} -sqlx = {workspace = true} -solana = {path = "../solana"} -solana-sdk = {workspace = true} +anyhow = { workspace = true } +async-trait = { workspace = true } +clap = { workspace = true } +config = { workspace = true } +chrono = { workspace = true } +db-store = { path = "../db_store" } +futures = { workspace = true } +futures-util = { workspace = true } +file-store = { path = "../file_store" } +helium-proto = { workspace = true } +helium-crypto = { workspace = true, features = [ + "sqlx-postgres", + "multisig", + "solana", +] } +iot-config = { path = "../iot_config" } +metrics = { workspace = true } +poc-metrics = { path = "../metrics" } +prost = { workspace = true } +serde = { workspace = true } +sqlx = { workspace = true } +solana = { path = "../solana" } +solana-sdk = { workspace = true } task-manager = { path = "../task_manager" } -thiserror = {workspace = true} -tokio = {workspace = true} -tonic = {workspace = true} -tracing = {workspace = true} -tracing-subscriber = {workspace = true} -triggered = {workspace = true} -http = {workspace = true} -http-serde = {workspace = true} +thiserror = { workspace = true } +tokio = { workspace = true } +tonic = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } +triggered = { workspace = true } +http = { workspace = true } +http-serde = { workspace = true } humantime-serde = { workspace = true } +custom-tracing = { path = "../custom_tracing" } diff --git a/iot_packet_verifier/src/main.rs b/iot_packet_verifier/src/main.rs index 08ed5a814..f84ff8dac 100644 --- a/iot_packet_verifier/src/main.rs +++ b/iot_packet_verifier/src/main.rs @@ -2,7 +2,6 @@ use anyhow::Result; use clap::Parser; use iot_packet_verifier::{daemon, settings::Settings}; use std::path::PathBuf; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[derive(clap::Parser)] #[clap(version = env!("CARGO_PKG_VERSION"))] @@ -21,10 +20,7 @@ pub struct Cli { impl Cli { pub async fn run(self) -> Result<()> { let settings = Settings::new(self.config)?; - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::new(&settings.log)) - .with(tracing_subscriber::fmt::layer()) - .init(); + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; self.cmd.run(settings).await } } diff --git a/iot_packet_verifier/src/settings.rs b/iot_packet_verifier/src/settings.rs index 807e44421..b30f253b9 100644 --- a/iot_packet_verifier/src/settings.rs +++ b/iot_packet_verifier/src/settings.rs @@ -10,6 +10,8 @@ pub struct Settings { /// "iot_packet_verifier=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, + #[serde(default)] + pub custom_tracing: custom_tracing::Settings, /// Cache location for generated verified reports pub cache: String, /// Data credit burn period in minutes. Default is 1. diff --git a/iot_verifier/Cargo.toml b/iot_verifier/Cargo.toml index 234e1ccc6..940445988 100644 --- a/iot_verifier/Cargo.toml +++ b/iot_verifier/Cargo.toml @@ -10,49 +10,50 @@ license.workspace = true cmake = "0.1" [dependencies] -anyhow = {workspace = true} -config = {workspace = true} -clap = {workspace = true} -thiserror = {workspace = true} -serde = {workspace = true} -serde_json = {workspace = true} -http-serde = {workspace = true} -sqlx = {workspace = true} +anyhow = { workspace = true } +config = { workspace = true } +clap = { workspace = true } +thiserror = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +http-serde = { workspace = true } +sqlx = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } -base64 = {workspace = true} -sha2 = {workspace = true} -tonic = {workspace = true} -triggered = {workspace = true} -futures = {workspace = true} -futures-util = {workspace = true} -prost = {workspace = true} +base64 = { workspace = true } +sha2 = { workspace = true } +tonic = { workspace = true } +triggered = { workspace = true } +futures = { workspace = true } +futures-util = { workspace = true } +prost = { workspace = true } chrono = { workspace = true } helium-proto = { workspace = true } -helium-crypto = {workspace = true } -async-trait = {workspace = true} -h3o = {workspace = true, features = ["geo"]} -xorf = {workspace = true} -lazy_static = {workspace = true} -once_cell = {workspace = true} -file-store = { path = "../file_store"} -metrics = {workspace = true} -retainer = {workspace = true} -blake3 = {workspace = true} +helium-crypto = { workspace = true } +async-trait = { workspace = true } +h3o = { workspace = true, features = ["geo"] } +xorf = { workspace = true } +lazy_static = { workspace = true } +once_cell = { workspace = true } +file-store = { path = "../file_store" } +metrics = { workspace = true } +retainer = { workspace = true } +blake3 = { workspace = true } iot-config = { path = "../iot_config" } poc-metrics = { path = "../metrics" } -db-store = {path = "../db_store"} -denylist = {path = "../denylist"} -reward-scheduler = {path = "../reward_scheduler"} -rust_decimal = {workspace = true, features = ["maths"]} -rust_decimal_macros = {workspace = true} -twox-hash = {workspace = true} -itertools = {workspace = true} -rand = {workspace = true} -beacon = {workspace = true} +db-store = { path = "../db_store" } +denylist = { path = "../denylist" } +reward-scheduler = { path = "../reward_scheduler" } +rust_decimal = { workspace = true, features = ["maths"] } +rust_decimal_macros = { workspace = true } +twox-hash = { workspace = true } +itertools = { workspace = true } +rand = { workspace = true } +beacon = { workspace = true } price = { path = "../price" } tokio-util = { workspace = true } tokio-stream = { workspace = true } task-manager = { path = "../task_manager" } humantime-serde = { workspace = true } +custom-tracing = { path = "../custom_tracing" } diff --git a/iot_verifier/src/main.rs b/iot_verifier/src/main.rs index 4efcc15ed..a1f3d4351 100644 --- a/iot_verifier/src/main.rs +++ b/iot_verifier/src/main.rs @@ -15,7 +15,6 @@ use iot_verifier::{ use price::PriceTracker; use std::path; use task_manager::TaskManager; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[derive(Debug, clap::Parser)] #[clap(version = env!("CARGO_PKG_VERSION"))] @@ -57,10 +56,7 @@ pub struct Server {} impl Server { pub async fn run(&self, settings: &Settings) -> Result<()> { - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::new(&settings.log)) - .with(tracing_subscriber::fmt::layer()) - .init(); + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; // Install the prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; diff --git a/iot_verifier/src/settings.rs b/iot_verifier/src/settings.rs index 8a8af7a8c..a1aae945a 100644 --- a/iot_verifier/src/settings.rs +++ b/iot_verifier/src/settings.rs @@ -10,6 +10,8 @@ pub struct Settings { /// "iot_verifier=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, + #[serde(default)] + pub custom_tracing: custom_tracing::Settings, /// Cache location for generated verified reports pub cache: String, /// the base_stale period in seconds diff --git a/mobile_config/Cargo.toml b/mobile_config/Cargo.toml index 25364bead..87b55125c 100644 --- a/mobile_config/Cargo.toml +++ b/mobile_config/Cargo.toml @@ -7,44 +7,45 @@ authors.workspace = true license.workspace = true [dependencies] -anyhow = {workspace = true} -async-trait = {workspace = true} -base64 = {workspace = true} -bs58 = {workspace = true} -chrono = {workspace = true} -clap = {workspace = true} -config = {workspace = true} -db-store = {path = "../db_store"} -file-store = {path = "../file_store"} -futures = {workspace = true} -futures-util = {workspace = true} -helium-crypto = {workspace = true} -helium-proto = {workspace = true} -hextree = {workspace = true} -http = {workspace = true} -http-serde = {workspace = true} -lazy_static = {workspace = true} -metrics = {workspace = true} -metrics-exporter-prometheus = {workspace = true} -poc-metrics = {path = "../metrics"} -prost = {workspace = true} -serde = {workspace = true} -serde_json = {workspace = true} -sqlx = {workspace = true} -retainer = {workspace = true} -thiserror = {workspace = true} -tokio = {workspace = true} -tokio-stream = {workspace = true} +anyhow = { workspace = true } +async-trait = { workspace = true } +base64 = { workspace = true } +bs58 = { workspace = true } +chrono = { workspace = true } +clap = { workspace = true } +config = { workspace = true } +db-store = { path = "../db_store" } +file-store = { path = "../file_store" } +futures = { workspace = true } +futures-util = { workspace = true } +helium-crypto = { workspace = true } +helium-proto = { workspace = true } +hextree = { workspace = true } +http = { workspace = true } +http-serde = { workspace = true } +lazy_static = { workspace = true } +metrics = { workspace = true } +metrics-exporter-prometheus = { workspace = true } +poc-metrics = { path = "../metrics" } +prost = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +sqlx = { workspace = true } +retainer = { workspace = true } +thiserror = { workspace = true } +tokio = { workspace = true } +tokio-stream = { workspace = true } tokio-util = { workspace = true } -tonic = {workspace = true} -tower-http = {workspace = true} -tracing = {workspace = true} -tracing-subscriber = {workspace = true} -triggered = {workspace = true} +tonic = { workspace = true } +tower-http = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } +triggered = { workspace = true } task-manager = { path = "../task_manager" } -solana-sdk = {workspace = true} +solana-sdk = { workspace = true } +custom-tracing = { path = "../custom_tracing", features = ["grpc"] } humantime-serde = { workspace = true } [dev-dependencies] rand = { workspace = true } -tokio-stream = { workspace = true, features = ["net"] } \ No newline at end of file +tokio-stream = { workspace = true, features = ["net"] } diff --git a/mobile_config/src/admin_service.rs b/mobile_config/src/admin_service.rs index 2e68b2781..bf5fee9e8 100644 --- a/mobile_config/src/admin_service.rs +++ b/mobile_config/src/admin_service.rs @@ -64,6 +64,8 @@ impl mobile_config::Admin for AdminService { async fn add_key(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("admin", "add-key"); + custom_tracing::record_b58("pub_key", &request.pubkey); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_admin_request_signature(&signer, &request)?; @@ -101,6 +103,8 @@ impl mobile_config::Admin for AdminService { async fn remove_key(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("admin", "remove-key"); + custom_tracing::record_b58("pub_key", &request.pubkey); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_admin_request_signature(&signer, &request)?; diff --git a/mobile_config/src/authorization_service.rs b/mobile_config/src/authorization_service.rs index 6aefb3257..ab46c6956 100644 --- a/mobile_config/src/authorization_service.rs +++ b/mobile_config/src/authorization_service.rs @@ -50,6 +50,8 @@ impl mobile_config::Authorization for AuthorizationService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("authorization", "verify"); + custom_tracing::record_b58("pub_key", &request.pubkey); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; @@ -82,6 +84,7 @@ impl mobile_config::Authorization for AuthorizationService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("authorization", "list"); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; diff --git a/mobile_config/src/carrier_service.rs b/mobile_config/src/carrier_service.rs index 22feb6af2..f80ddd397 100644 --- a/mobile_config/src/carrier_service.rs +++ b/mobile_config/src/carrier_service.rs @@ -61,6 +61,8 @@ impl mobile_config::CarrierService for CarrierService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("carrier_service", "key_to_entity"); + custom_tracing::record("pub_key", &request.pubkey); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; diff --git a/mobile_config/src/entity_service.rs b/mobile_config/src/entity_service.rs index 99741c1ad..383f42c13 100644 --- a/mobile_config/src/entity_service.rs +++ b/mobile_config/src/entity_service.rs @@ -56,6 +56,7 @@ impl mobile_config::Entity for EntityService { async fn verify(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("entity", "verify"); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; diff --git a/mobile_config/src/gateway_service.rs b/mobile_config/src/gateway_service.rs index b4304bbf4..048980d55 100644 --- a/mobile_config/src/gateway_service.rs +++ b/mobile_config/src/gateway_service.rs @@ -71,6 +71,8 @@ impl mobile_config::Gateway for GatewayService { async fn info(&self, request: Request) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("gateway", "info"); + custom_tracing::record_b58("pub_key", &request.address); + custom_tracing::record_b58("signer", &request.signer); self.verify_request_signature_for_info(&request)?; @@ -113,6 +115,7 @@ impl mobile_config::Gateway for GatewayService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("gateway", "info-batch"); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; @@ -148,6 +151,7 @@ impl mobile_config::Gateway for GatewayService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("gateway", "info-stream"); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; diff --git a/mobile_config/src/hex_boosting_service.rs b/mobile_config/src/hex_boosting_service.rs index 77a56ed23..08ed50f1c 100644 --- a/mobile_config/src/hex_boosting_service.rs +++ b/mobile_config/src/hex_boosting_service.rs @@ -57,6 +57,7 @@ impl mobile_config::HexBoosting for HexBoostingService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("hex-boosting", "info-stream"); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; @@ -84,6 +85,7 @@ impl mobile_config::HexBoosting for HexBoostingService { ) -> GrpcResult { let request = request.into_inner(); telemetry::count_request("hex-boosting", "modified-info-stream"); + custom_tracing::record_b58("signer", &request.signer); let signer = verify_public_key(&request.signer)?; self.verify_request_signature(&signer, &request)?; diff --git a/mobile_config/src/main.rs b/mobile_config/src/main.rs index 60562beb1..d12fd5233 100644 --- a/mobile_config/src/main.rs +++ b/mobile_config/src/main.rs @@ -15,7 +15,6 @@ use mobile_config::{ use std::{net::SocketAddr, path::PathBuf, time::Duration}; use task_manager::{ManagedTask, TaskManager}; use tonic::transport; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[derive(Debug, clap::Parser)] #[clap(version = env!("CARGO_PKG_VERSION"))] @@ -56,10 +55,7 @@ pub struct Daemon; impl Daemon { pub async fn run(&self, settings: &Settings) -> Result<()> { - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::new(&settings.log)) - .with(tracing_subscriber::fmt::layer()) - .init(); + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; // Install prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; @@ -133,7 +129,7 @@ impl ManagedTask for GrpcServer { transport::Server::builder() .http2_keepalive_interval(Some(Duration::from_secs(250))) .http2_keepalive_timeout(Some(Duration::from_secs(60))) - .layer(tower_http::trace::TraceLayer::new_for_grpc()) + .layer(custom_tracing::grpc_layer::new_with_span(make_span)) .add_service(AdminServer::new(self.admin_svc)) .add_service(GatewayServer::new(self.gateway_svc)) .add_service(AuthorizationServer::new(self.auth_svc)) @@ -147,6 +143,14 @@ impl ManagedTask for GrpcServer { } } +fn make_span(_request: &http::request::Request) -> tracing::Span { + tracing::info_span!( + custom_tracing::DEFAULT_SPAN, + pub_key = tracing::field::Empty, + signer = tracing::field::Empty, + ) +} + #[tokio::main] async fn main() -> Result<()> { let cli = Cli::parse(); diff --git a/mobile_config/src/settings.rs b/mobile_config/src/settings.rs index 76a5afa8d..10a20f479 100644 --- a/mobile_config/src/settings.rs +++ b/mobile_config/src/settings.rs @@ -9,6 +9,8 @@ pub struct Settings { /// "mobile_config=info" #[serde(default = "default_log")] pub log: String, + #[serde(default)] + pub custom_tracing: custom_tracing::Settings, /// Listen address. Required. Default to 0.0.0.0::8080 #[serde(default = "default_listen_addr")] pub listen: SocketAddr, diff --git a/mobile_packet_verifier/Cargo.toml b/mobile_packet_verifier/Cargo.toml index 820a84280..b936682dd 100644 --- a/mobile_packet_verifier/Cargo.toml +++ b/mobile_packet_verifier/Cargo.toml @@ -7,32 +7,37 @@ authors.workspace = true license.workspace = true [dependencies] -anyhow = {workspace = true} -async-trait = {workspace = true} -clap = {workspace = true} -config = {workspace = true} -chrono = {workspace = true} -db-store = {path = "../db_store"} -futures = {workspace = true} -futures-util = {workspace = true} -file-store = {path = "../file_store"} -helium-proto = {workspace = true} -helium-crypto = {workspace = true, features = ["sqlx-postgres", "multisig", "solana"]} -metrics = {workspace = true} -poc-metrics = {path = "../metrics"} -prost = {workspace = true} -serde = {workspace = true} -sqlx = {workspace = true} -solana = {path = "../solana"} -mobile-config = {path = "../mobile_config"} -task-manager = {path = "../task_manager"} -thiserror = {workspace = true} -tokio = {workspace = true} -tonic = {workspace = true} -tracing = {workspace = true} -tracing-subscriber = {workspace = true} -triggered = {workspace = true} -http = {workspace = true} -http-serde = {workspace = true} -sha2 = {workspace = true} -humantime-serde = { workspace=true } \ No newline at end of file +anyhow = { workspace = true } +async-trait = { workspace = true } +clap = { workspace = true } +config = { workspace = true } +chrono = { workspace = true } +db-store = { path = "../db_store" } +futures = { workspace = true } +futures-util = { workspace = true } +file-store = { path = "../file_store" } +helium-proto = { workspace = true } +helium-crypto = { workspace = true, features = [ + "sqlx-postgres", + "multisig", + "solana", +] } +metrics = { workspace = true } +poc-metrics = { path = "../metrics" } +prost = { workspace = true } +serde = { workspace = true } +sqlx = { workspace = true } +solana = { path = "../solana" } +mobile-config = { path = "../mobile_config" } +task-manager = { path = "../task_manager" } +thiserror = { workspace = true } +tokio = { workspace = true } +tonic = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } +triggered = { workspace = true } +http = { workspace = true } +http-serde = { workspace = true } +sha2 = { workspace = true } +humantime-serde = { workspace = true } +custom-tracing = { path = "../custom_tracing" } diff --git a/mobile_packet_verifier/src/main.rs b/mobile_packet_verifier/src/main.rs index 2114911db..ede970221 100644 --- a/mobile_packet_verifier/src/main.rs +++ b/mobile_packet_verifier/src/main.rs @@ -2,7 +2,6 @@ use anyhow::Result; use clap::Parser; use mobile_packet_verifier::{daemon, settings::Settings}; use std::path::PathBuf; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[derive(clap::Parser)] #[clap(version = env!("CARGO_PKG_VERSION"))] @@ -21,10 +20,7 @@ pub struct Cli { impl Cli { pub async fn run(self) -> Result<()> { let settings = Settings::new(self.config)?; - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::new(&settings.log)) - .with(tracing_subscriber::fmt::layer()) - .init(); + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; self.cmd.run(settings).await } } diff --git a/mobile_packet_verifier/src/settings.rs b/mobile_packet_verifier/src/settings.rs index 72ef9b586..2cd97bf26 100644 --- a/mobile_packet_verifier/src/settings.rs +++ b/mobile_packet_verifier/src/settings.rs @@ -10,6 +10,8 @@ pub struct Settings { /// "mobile_verifier=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, + #[serde(default)] + pub custom_tracing: custom_tracing::Settings, /// Cache location for generated verified reports pub cache: String, /// Burn period in hours. (Default is 1 hour) diff --git a/mobile_verifier/Cargo.toml b/mobile_verifier/Cargo.toml index 2620b6536..100343a09 100644 --- a/mobile_verifier/Cargo.toml +++ b/mobile_verifier/Cargo.toml @@ -7,51 +7,52 @@ edition.workspace = true authors.workspace = true [dependencies] -anyhow = {workspace = true} -config = {workspace = true} -thiserror = {workspace = true} -serde = {workspace = true} -serde_json = {workspace = true} -h3o = {workspace = true, features = ["geo"]} -hextree = {workspace = true} -http-serde = {workspace = true} -clap = {workspace = true} -sqlx = {workspace = true} -tokio = {workspace = true} -tracing = {workspace = true} -tracing-subscriber = {workspace = true} -base64 = {workspace = true} -sha2 = {workspace = true} -lazy_static = {workspace = true} -chrono = {workspace = true} -triggered = {workspace = true} +anyhow = { workspace = true } +config = { workspace = true } +thiserror = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +h3o = { workspace = true, features = ["geo"] } +hextree = { workspace = true } +http-serde = { workspace = true } +clap = { workspace = true } +sqlx = { workspace = true } +tokio = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } +base64 = { workspace = true } +sha2 = { workspace = true } +lazy_static = { workspace = true } +chrono = { workspace = true } +triggered = { workspace = true } flate2 = "1" -futures = {workspace = true} -futures-util = {workspace = true} -prost = {workspace = true} -once_cell = {workspace = true} -helium-proto = {workspace = true} -helium-crypto = {workspace = true} -humantime = {workspace = true} -rust_decimal = {workspace = true} -rust_decimal_macros = {workspace = true} -tonic = {workspace = true} +futures = { workspace = true } +futures-util = { workspace = true } +prost = { workspace = true } +once_cell = { workspace = true } +helium-proto = { workspace = true } +helium-crypto = { workspace = true } +humantime = { workspace = true } +rust_decimal = { workspace = true } +rust_decimal_macros = { workspace = true } +tonic = { workspace = true } tokio-stream = { workspace = true } -metrics = {workspace = true} -metrics-exporter-prometheus = {workspace = true} -mobile-config = {path = "../mobile_config"} -file-store = {path = "../file_store"} -db-store = {path = "../db_store"} -poc-metrics = {path = "../metrics"} -reward-scheduler = {path = "../reward_scheduler"} -price = {path = "../price"} -rand = {workspace = true} -async-trait = {workspace = true} -retainer = {workspace = true} -uuid = {workspace = true} -task-manager = {path = "../task_manager"} -solana-sdk = {workspace = true} +metrics = { workspace = true } +metrics-exporter-prometheus = { workspace = true } +mobile-config = { path = "../mobile_config" } +file-store = { path = "../file_store" } +db-store = { path = "../db_store" } +poc-metrics = { path = "../metrics" } +reward-scheduler = { path = "../reward_scheduler" } +price = { path = "../price" } +rand = { workspace = true } +async-trait = { workspace = true } +retainer = { workspace = true } +uuid = { workspace = true } +task-manager = { path = "../task_manager" } +solana-sdk = { workspace = true } humantime-serde = { workspace = true } +custom-tracing = { path = "../custom_tracing" } [dev-dependencies] backon = "0" diff --git a/mobile_verifier/src/main.rs b/mobile_verifier/src/main.rs index 6d597b45b..3b3c991b7 100644 --- a/mobile_verifier/src/main.rs +++ b/mobile_verifier/src/main.rs @@ -5,7 +5,6 @@ use mobile_verifier::{ Settings, }; use std::path; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[derive(clap::Parser)] #[clap(version = env!("CARGO_PKG_VERSION"))] @@ -24,10 +23,7 @@ pub struct Cli { impl Cli { pub async fn run(self) -> Result<()> { let settings = Settings::new(self.config)?; - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::new(&settings.log)) - .with(tracing_subscriber::fmt::layer()) - .init(); + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; self.cmd.run(settings).await } } diff --git a/mobile_verifier/src/settings.rs b/mobile_verifier/src/settings.rs index e154fdb2e..cfd5d91a6 100644 --- a/mobile_verifier/src/settings.rs +++ b/mobile_verifier/src/settings.rs @@ -13,6 +13,8 @@ pub struct Settings { /// "mobile_verifier=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, + #[serde(default)] + pub custom_tracing: custom_tracing::Settings, /// Cache location for generated verified reports pub cache: String, /// Reward period in hours. (Default is 24 hours) diff --git a/poc_entropy/Cargo.toml b/poc_entropy/Cargo.toml index c2c1322c6..bc468c8bc 100644 --- a/poc_entropy/Cargo.toml +++ b/poc_entropy/Cargo.toml @@ -7,27 +7,27 @@ authors.workspace = true license.workspace = true [dependencies] -anyhow = {workspace = true} -config = {workspace = true} -clap = {workspace = true} -thiserror = {workspace = true} -serde = {workspace = true} -serde_json = {workspace = true} -base64 = {workspace = true} -blake3 = {workspace = true} -http = {workspace = true} -tonic = {workspace = true} +anyhow = { workspace = true } +config = { workspace = true } +clap = { workspace = true } +thiserror = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +base64 = { workspace = true } +blake3 = { workspace = true } +http = { workspace = true } +tonic = { workspace = true } hyper = "0" jsonrpsee = { version = "0", features = ["async-client", "http-client"] } -tower = {version = "0.4" } -triggered = {workspace = true} -futures = {workspace = true} -futures-util = {workspace = true} -prost = {workspace = true} +tower = { version = "0.4" } +triggered = { workspace = true } +futures = { workspace = true } +futures-util = { workspace = true } +prost = { workspace = true } bs58 = "0" tracing = { workspace = true } tracing-subscriber = { workspace = true } -metrics = {workspace = true } +metrics = { workspace = true } metrics-exporter-prometheus = { workspace = true } tokio = { workspace = true } chrono = { workspace = true } @@ -35,3 +35,4 @@ helium-proto = { workspace = true } helium-crypto = { workspace = true } file-store = { path = "../file_store" } poc-metrics = { path = "../metrics" } +custom-tracing = { path = "../custom_tracing", features = ["grpc"] } diff --git a/poc_entropy/src/main.rs b/poc_entropy/src/main.rs index 8ed314bb3..1879ab59d 100644 --- a/poc_entropy/src/main.rs +++ b/poc_entropy/src/main.rs @@ -6,7 +6,6 @@ use futures_util::TryFutureExt; use poc_entropy::{entropy_generator::EntropyGenerator, server::ApiServer, Settings}; use std::{net::SocketAddr, path}; use tokio::{self, signal}; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; const ENTROPY_SINK_ROLL_MINS: i64 = 2; @@ -27,6 +26,7 @@ pub struct Cli { impl Cli { pub async fn run(self) -> Result<()> { let settings = Settings::new(self.config)?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; self.cmd.run(settings).await } } @@ -49,11 +49,6 @@ pub struct Server {} impl Server { pub async fn run(&self, settings: &Settings) -> Result<()> { - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::new(&settings.log)) - .with(tracing_subscriber::fmt::layer()) - .init(); - // Install the prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; diff --git a/poc_entropy/src/server.rs b/poc_entropy/src/server.rs index e771afffb..c752cfe9d 100644 --- a/poc_entropy/src/server.rs +++ b/poc_entropy/src/server.rs @@ -44,6 +44,7 @@ impl ApiServer { pub async fn run(self, shutdown: &triggered::Listener) -> anyhow::Result<()> { tracing::info!(listen = self.socket_addr.to_string(), "starting"); transport::Server::builder() + .layer(custom_tracing::grpc_layer::new_with_span(make_span)) .http2_keepalive_interval(Some(Duration::from_secs(250))) .http2_keepalive_timeout(Some(Duration::from_secs(60))) .add_service(self.service) @@ -53,3 +54,7 @@ impl ApiServer { Ok(()) } } + +fn make_span(_request: &http::request::Request) -> tracing::Span { + tracing::info_span!(custom_tracing::DEFAULT_SPAN) +} diff --git a/poc_entropy/src/settings.rs b/poc_entropy/src/settings.rs index f4aad2de3..126553c5a 100644 --- a/poc_entropy/src/settings.rs +++ b/poc_entropy/src/settings.rs @@ -8,6 +8,8 @@ pub struct Settings { /// "poc_entropy=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, + #[serde(default)] + pub custom_tracing: custom_tracing::Settings, /// Listen address for http requests for entropy. Default "0.0.0.0:8080" #[serde(default = "default_listen_addr")] pub listen: String, diff --git a/price/Cargo.toml b/price/Cargo.toml index 0ce8851fc..feddd874a 100644 --- a/price/Cargo.toml +++ b/price/Cargo.toml @@ -7,18 +7,18 @@ authors.workspace = true license.workspace = true [dependencies] -anyhow = {workspace = true} -config = {workspace = true} -clap = {workspace = true} -thiserror = {workspace = true} -serde = {workspace = true} -serde_json = {workspace = true} -futures = {workspace = true} -futures-util = {workspace = true} -prost = {workspace = true} +anyhow = { workspace = true } +config = { workspace = true } +clap = { workspace = true } +thiserror = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +futures = { workspace = true } +futures-util = { workspace = true } +prost = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } -metrics = {workspace = true } +metrics = { workspace = true } metrics-exporter-prometheus = { workspace = true } tokio = { workspace = true } tokio-util = { workspace = true } @@ -27,9 +27,10 @@ helium-anchor-gen = { workspace = true } helium-proto = { workspace = true } file-store = { path = "../file_store" } poc-metrics = { path = "../metrics" } -pyth-sdk-solana = {workspace = true} -triggered = {workspace = true} -solana-client = {workspace = true} -solana-sdk = {workspace = true} -task-manager = {path = "../task_manager"} -humantime-serde = { workspace = true } \ No newline at end of file +pyth-sdk-solana = { workspace = true } +triggered = { workspace = true } +solana-client = { workspace = true } +solana-sdk = { workspace = true } +task-manager = { path = "../task_manager" } +humantime-serde = { workspace = true } +custom-tracing = { path = "../custom_tracing" } diff --git a/price/src/main.rs b/price/src/main.rs index 3803a62fa..29a911c67 100644 --- a/price/src/main.rs +++ b/price/src/main.rs @@ -6,7 +6,6 @@ use helium_proto::BlockchainTokenTypeV1; use price::{cli::check, PriceGenerator, Settings}; use std::path::{self, PathBuf}; use task_manager::TaskManager; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; const PRICE_SINK_ROLL_MINS: i64 = 3; @@ -41,6 +40,7 @@ impl Cmd { match self { Self::Server(cmd) => { let settings = Settings::new(config)?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; cmd.run(&settings).await } Self::Check(options) => check::run(options.into()).await, @@ -71,11 +71,6 @@ pub struct Server {} impl Server { pub async fn run(&self, settings: &Settings) -> Result<()> { - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::new(&settings.log)) - .with(tracing_subscriber::fmt::layer()) - .init(); - // Install the prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; diff --git a/price/src/settings.rs b/price/src/settings.rs index 86d557eeb..8077ee5d2 100644 --- a/price/src/settings.rs +++ b/price/src/settings.rs @@ -37,6 +37,8 @@ pub struct Settings { /// "price=debug" #[serde(default = "default_log")] pub log: String, + #[serde(default)] + pub custom_tracing: custom_tracing::Settings, /// Source URL for price data. Required #[serde(default = "default_source")] pub source: String, diff --git a/reward_index/Cargo.toml b/reward_index/Cargo.toml index 29c34841c..c0d971815 100644 --- a/reward_index/Cargo.toml +++ b/reward_index/Cargo.toml @@ -8,36 +8,37 @@ license.workspace = true [dependencies] -anyhow = {workspace = true} -bs58 = {workspace = true} -config = {workspace = true} -clap = {workspace = true} -thiserror = {workspace = true} -serde = {workspace = true} -serde_json = {workspace = true} -sqlx = {workspace = true} -base64 = {workspace = true} -sha2 = {workspace = true} -lazy_static = {workspace = true} -triggered = {workspace = true} -futures = {workspace = true} -futures-util = {workspace = true} -prost = {workspace = true} -once_cell = {workspace = true} -file-store = {path = "../file_store"} +anyhow = { workspace = true } +bs58 = { workspace = true } +config = { workspace = true } +clap = { workspace = true } +thiserror = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +sqlx = { workspace = true } +base64 = { workspace = true } +sha2 = { workspace = true } +lazy_static = { workspace = true } +triggered = { workspace = true } +futures = { workspace = true } +futures-util = { workspace = true } +prost = { workspace = true } +once_cell = { workspace = true } +file-store = { path = "../file_store" } db-store = { path = "../db_store" } -poc-metrics = {path = "../metrics"} +poc-metrics = { path = "../metrics" } tokio = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } chrono = { workspace = true, features = ["serde"] } -metrics = {workspace = true } +metrics = { workspace = true } metrics-exporter-prometheus = { workspace = true } helium-proto = { workspace = true } helium-crypto = { workspace = true } -rust_decimal = {workspace = true} -rust_decimal_macros = {workspace = true} -tonic = {workspace = true} -rand = {workspace = true} -async-trait = {workspace = true} -humantime-serde = { workspace = true } \ No newline at end of file +rust_decimal = { workspace = true } +rust_decimal_macros = { workspace = true } +tonic = { workspace = true } +rand = { workspace = true } +async-trait = { workspace = true } +humantime-serde = { workspace = true } +custom-tracing = { path = "../custom_tracing" } diff --git a/reward_index/src/main.rs b/reward_index/src/main.rs index 600c6764f..227504b63 100644 --- a/reward_index/src/main.rs +++ b/reward_index/src/main.rs @@ -8,7 +8,6 @@ use futures_util::TryFutureExt; use reward_index::{settings::Settings, telemetry, Indexer}; use std::path::PathBuf; use tokio::signal; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[derive(Debug, clap::Parser)] #[clap(version = env!("CARGO_PKG_VERSION"))] @@ -27,6 +26,7 @@ pub struct Cli { impl Cli { pub async fn run(self) -> Result<()> { let settings = Settings::new(self.config)?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; self.cmd.run(settings).await } } @@ -49,11 +49,6 @@ pub struct Server {} impl Server { pub async fn run(&self, settings: &Settings) -> Result<()> { - tracing_subscriber::registry() - .with(tracing_subscriber::EnvFilter::new(&settings.log)) - .with(tracing_subscriber::fmt::layer()) - .init(); - // Install the prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; // diff --git a/reward_index/src/settings.rs b/reward_index/src/settings.rs index e41231059..e72e1d913 100644 --- a/reward_index/src/settings.rs +++ b/reward_index/src/settings.rs @@ -28,6 +28,8 @@ pub struct Settings { /// "poc_entropy=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, + #[serde(default)] + pub custom_tracing: custom_tracing::Settings, /// Check interval in seconds. (Default is 900; 15 minutes) #[serde(with = "humantime_serde", default = "default_interval")] pub interval: Duration,