From a3e43ef68bf67d4dd06400558a0e777d561202ba Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 15 Jun 2022 15:03:13 -0400 Subject: [PATCH] fix otlp --- Cargo.lock | 11 +++++++++++ veilid-core/src/network_manager/mod.rs | 5 +++-- veilid-server/Cargo.toml | 2 ++ veilid-server/src/cmdline.rs | 18 ++++++++---------- veilid-server/src/settings.rs | 6 +++--- veilid-server/src/veilid_logs.rs | 20 ++++++++++++++------ 6 files changed, 41 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c48dd07c..a2c0d8f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3139,6 +3139,15 @@ dependencies = [ "tonic-build", ] +[[package]] +name = "opentelemetry-semantic-conventions" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985cc35d832d412224b2cffe2f9194b1b89b6aa5d0bef76d080dce09d90e62bd" +dependencies = [ + "opentelemetry", +] + [[package]] name = "ordered-multimap" version = "0.4.3" @@ -5280,10 +5289,12 @@ dependencies = [ "failure", "flume", "futures", + "hostname", "lazy_static", "nix 0.24.1", "opentelemetry", "opentelemetry-otlp", + "opentelemetry-semantic-conventions", "parking_lot 0.12.1", "rpassword 6.0.1", "serde 1.0.137", diff --git a/veilid-core/src/network_manager/mod.rs b/veilid-core/src/network_manager/mod.rs index 33527239..2267d75d 100644 --- a/veilid-core/src/network_manager/mod.rs +++ b/veilid-core/src/network_manager/mod.rs @@ -90,6 +90,7 @@ impl Default for NetworkManagerStats { } } +#[derive(Debug)] struct ClientWhitelistEntry { last_seen_ts: u64, } @@ -364,7 +365,6 @@ impl NetworkManager { } } - #[instrument(level = "trace", skip(self))] pub fn purge_client_whitelist(&self) { let timeout_ms = self.config.get().network.client_whitelist_timeout_ms; let mut inner = self.inner.lock(); @@ -376,7 +376,8 @@ impl NetworkManager { .map(|v| v.1.last_seen_ts < cutoff_timestamp) .unwrap_or_default() { - inner.client_whitelist.remove_lru(); + let (k, v) = inner.client_whitelist.remove_lru().unwrap(); + trace!(key=?k, value=?v, "purge_client_whitelist: remove_lru") } } diff --git a/veilid-server/Cargo.toml b/veilid-server/Cargo.toml index f8416600..934acbbc 100644 --- a/veilid-server/Cargo.toml +++ b/veilid-server/Cargo.toml @@ -17,6 +17,7 @@ tracing-appender = "^0" tracing-opentelemetry = "^0" opentelemetry = { version = "^0", features = ["rt-async-std"] } opentelemetry-otlp = { version = "^0", features = ["grpc-sys"] } +opentelemetry-semantic-conventions = "^0" clap = "^3" async-std = { version = "^1", features = ["unstable"] } async-tungstenite = { version = "^0", features = ["async-std-runtime", "async-tls"] } @@ -38,6 +39,7 @@ lazy_static = "^1" bugsalot = "^0" flume = { version = "^0", features = ["async"] } rpassword = "^6" +hostname = "^0" [target.'cfg(windows)'.dependencies] windows-service = "^0" diff --git a/veilid-server/src/cmdline.rs b/veilid-server/src/cmdline.rs index a4bf4ab7..0d209070 100644 --- a/veilid-server/src/cmdline.rs +++ b/veilid-server/src/cmdline.rs @@ -66,7 +66,7 @@ fn do_clap_matches(default_config_path: &OsStr) -> Result Result<(Settings, ArgMatches), String> { } if matches.occurrences_of("otlp") != 0 { settingsrw.logging.otlp.enabled = true; - settingsrw.logging.otlp.grpc_endpoint = Some( - ParsedUrl::from_str( - &matches - .value_of("otlp") - .expect("should not be null because of default missing value") - .to_string(), - ) - .map_err(|e| format!("failed to parse OTLP url: {}", e))?, - ); + settingsrw.logging.otlp.grpc_endpoint = NamedSocketAddrs::from_str( + &matches + .value_of("otlp") + .expect("should not be null because of default missing value") + .to_string(), + ) + .map_err(|e| format!("failed to parse OTLP address: {}", e))?; settingsrw.logging.otlp.level = LogLevel::Trace; } if matches.is_present("attach") { diff --git a/veilid-server/src/settings.rs b/veilid-server/src/settings.rs index be9a92ae..97eea6bc 100644 --- a/veilid-server/src/settings.rs +++ b/veilid-server/src/settings.rs @@ -39,7 +39,7 @@ logging: otlp: enabled: false level: 'trace' - grpc_endpoint: 'http://localhost:4317' + grpc_endpoint: 'localhost:4317' testing: subnode_index: 0 core: @@ -435,7 +435,7 @@ pub struct Api { pub struct Otlp { pub enabled: bool, pub level: LogLevel, - pub grpc_endpoint: Option, + pub grpc_endpoint: NamedSocketAddrs, } #[derive(Debug, Deserialize, Serialize)] @@ -1423,7 +1423,7 @@ mod tests { assert_eq!(s.logging.otlp.level, LogLevel::Trace); assert_eq!( s.logging.otlp.grpc_endpoint, - Some(ParsedUrl::from_str("http://127.0.0.1:4317").unwrap()) + NamedSocketAddrs::from_str("localhost:4317").unwrap() ); assert_eq!(s.testing.subnode_index, 0); diff --git a/veilid-server/src/veilid_logs.rs b/veilid-server/src/veilid_logs.rs index 505d3894..4cddd87a 100644 --- a/veilid-server/src/veilid_logs.rs +++ b/veilid-server/src/veilid_logs.rs @@ -1,5 +1,7 @@ use crate::settings::*; use cfg_if::*; +use opentelemetry::sdk::*; +use opentelemetry::*; use opentelemetry_otlp::WithExportConfig; use std::path::*; use tracing::*; @@ -61,12 +63,7 @@ impl VeilidLogs { convert_loglevel(settingsr.logging.otlp.level) .to_tracing_level() .into(); - let grpc_endpoint = match &settingsr.logging.otlp.grpc_endpoint { - Some(v) => &v.urlstring, - None => { - return Err("missing OTLP GRPC endpoint url".to_owned()); - } - }; + let grpc_endpoint = settingsr.logging.otlp.grpc_endpoint.name.clone(); // Required for GRPC dns resolution to work std::env::set_var("GRPC_DNS_RESOLVER", "native"); @@ -78,6 +75,17 @@ impl VeilidLogs { .grpcio() .with_endpoint(grpc_endpoint), ) + .with_trace_config(opentelemetry::sdk::trace::config().with_resource( + Resource::new(vec![KeyValue::new( + opentelemetry_semantic_conventions::resource::SERVICE_NAME, + format!( + "veilid_server:{}", + hostname::get() + .map(|s| s.to_string_lossy().into_owned()) + .unwrap_or_else(|_| "unknown".to_owned()) + ), + )]), + )) .install_batch(opentelemetry::runtime::AsyncStd) .map_err(|e| format!("failed to install OpenTelemetry tracer: {}", e))?;