diff --git a/Cargo.lock b/Cargo.lock index d48fc756cb..07867c5bd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,6 +142,7 @@ dependencies = [ "serde_json", "serde_json_bytes", "serde_yaml", + "sys-info", "tempfile", "test-log", "test-span", @@ -159,6 +160,7 @@ dependencies = [ "tracing-subscriber", "tracing-test", "typed-builder 0.10.0", + "uname", "url", "uuid 1.0.0", "walkdir", diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index f87a732925..f713a24afc 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -76,6 +76,7 @@ serde = { version = "1.0.136", features = ["derive", "rc"] } serde_json_bytes = { version = "0.2.0", features = ["preserve_order"] } serde_json = { version = "1.0.79", features = ["preserve_order"] } serde_yaml = "0.8.24" +sys-info = "0.9.1" thiserror = "1.0.30" tokio = { version = "1.17.0", features = ["full"] } tokio-util = { version = "0.7.1", features = ["net", "codec"] } @@ -95,6 +96,12 @@ rhai = { version = "1.7.0", features = ["sync", "serde", "internals"] } libc = "0.2.125" yaml-rust = "0.4.5" +[target.'cfg(macos)'.dependencies] +uname = "0.1.1" + +[target.'cfg(unix)'.dependencies] +uname = "0.1.1" + [dev-dependencies] insta = "1.12.0" jsonpath_lib = "0.3.0" diff --git a/apollo-router/src/plugins/telemetry/metrics/apollo.rs b/apollo-router/src/plugins/telemetry/metrics/apollo.rs index cd1f88cc29..900f87a997 100644 --- a/apollo-router/src/plugins/telemetry/metrics/apollo.rs +++ b/apollo-router/src/plugins/telemetry/metrics/apollo.rs @@ -12,6 +12,7 @@ use futures_batch::ChunksTimeoutStreamExt; use std::time::Duration; use studio::AggregatedMetrics; use studio::Metrics; +use sys_info::hostname; use tower::BoxError; use url::Url; @@ -76,6 +77,29 @@ impl MetricsConfigurator for Config { } } +#[cfg(not(target_os = "windows"))] +fn get_uname() -> Result { + let u = uname::uname()?; + Ok(format!( + "{}, {}, {}, {}, {},", + u.sysname, u.nodename, u.release, u.version, u.machine + )) +} + +#[cfg(target_os = "windows")] +fn get_uname() -> Result { + // Best we can do on windows right now + let sysname = sys_info::os_type().unwrap_or_else(|_| "Windows".to_owned()); + let nodename = sys_info::hostname().unwrap_or_else(|_| "unknown".to_owned()); + let release = sys_info::os_release().unwrap_or_else(|_| "unknown".to_owned()); + let version = "unknown"; + let machine = "unknown"; + Ok(format!( + "{}, {}, {}, {}, {}", + sysname, nodename, release, version, machine + )) +} + struct ApolloMetricsExporter { tx: mpsc::Sender, } @@ -98,12 +122,16 @@ impl ApolloMetricsExporter { // TODO fill out this stuff let header = apollo_spaceport::ReportHeader { graph_ref: apollo_graph_ref.to_string(), - hostname: "".to_string(), - agent_version: "".to_string(), - service_version: "".to_string(), - runtime_version: "".to_string(), - uname: "".to_string(), + hostname: hostname()?, + agent_version: format!( + "{}@{}", + std::env!("CARGO_PKG_NAME"), + std::env!("CARGO_PKG_VERSION") + ), + runtime_version: "rust".to_string(), + uname: get_uname()?, executable_schema_id: schema_id.to_string(), + ..Default::default() }; // Deadpool gives us connection pooling to spaceport