Skip to content

Commit

Permalink
Populate most of the headers information.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryn committed May 12, 2022
1 parent 4510527 commit 9aedc1d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions apollo-router/Cargo.toml
Expand Up @@ -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"] }
Expand All @@ -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"
Expand Down
38 changes: 33 additions & 5 deletions apollo-router/src/plugins/telemetry/metrics/apollo.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -76,6 +77,29 @@ impl MetricsConfigurator for Config {
}
}

#[cfg(not(target_os = "windows"))]
fn get_uname() -> Result<String, std::io::Error> {
let u = uname::uname()?;
Ok(format!(
"{}, {}, {}, {}, {},",
u.sysname, u.nodename, u.release, u.version, u.machine
))
}

#[cfg(target_os = "windows")]
fn get_uname() -> Result<String, std::io::Error> {
// 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<Metrics>,
}
Expand All @@ -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
Expand Down

0 comments on commit 9aedc1d

Please sign in to comment.