Skip to content

Commit

Permalink
More info in telemetry event (MystenLabs#4531)
Browse files Browse the repository at this point in the history
  • Loading branch information
gegaowp authored Sep 13, 2022
1 parent 35a9911 commit 87e126e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
5 changes: 3 additions & 2 deletions crates/sui-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ async fn main() -> Result<()> {
});
}

task::spawn(async {
let is_validator = config.consensus_config().is_some();
task::spawn(async move {
loop {
sleep(Duration::from_secs(3600)).await;
send_telemetry_event().await;
send_telemetry_event(is_validator).await;
}
});

Expand Down
37 changes: 35 additions & 2 deletions crates/sui-telemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::process::Command;
use std::time::{SystemTime, UNIX_EPOCH};
use tracing::trace;

pub(crate) const GA_API_SECRET: &str = "zeq-aYEzS0aGdRJ8kNZTEg";
Expand Down Expand Up @@ -35,11 +37,30 @@ struct IpResponse {
ip: String,
}

pub async fn send_telemetry_event() {
pub async fn send_telemetry_event(is_validator: bool) {
let git_rev = get_git_rev();
let ip_address = get_ip().await;
let since_the_epoch = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Now should be later than epoch!");
let telemetry_event = TelemetryEvent {
name: GA_EVENT_NAME.into(),
params: BTreeMap::from([("node_address".into(), ip_address.clone())]),
params: BTreeMap::from([
("node_address".into(), ip_address.clone()),
(
"node_type".into(),
if is_validator {
"validator".into()
} else {
"full_node".into()
},
),
("git_rev".into(), git_rev),
(
"seconds_since_epoch".into(),
since_the_epoch.as_secs().to_string(),
),
]),
};

let telemetry_payload = TelemetryPayload {
Expand All @@ -50,6 +71,18 @@ pub async fn send_telemetry_event() {
send_telemetry_event_impl(telemetry_payload).await
}

fn get_git_rev() -> String {
let output_res = Command::new("git")
.args(&["describe", "--always", "--dirty"])
.output();
if let Ok(output) = output_res {
if output.status.success() {
return String::from_utf8(output.stdout).unwrap().trim().to_owned();
}
}
"GIT_CMD_ERROR".into()
}

async fn get_ip() -> String {
let resp = reqwest::get(IPLOOKUP_URL).await;
match resp {
Expand Down

0 comments on commit 87e126e

Please sign in to comment.