Skip to content

Commit

Permalink
[debug-endpoint]: add api for dumping config + git revision
Browse files Browse the repository at this point in the history
Adding a /node-info route to collect data about the node_config and git_revision from a given node. NodeDebugService now takes in a reference to a NodeConfig as a parameter. Created a NodeInfo struct to contain the git_revision and node_config fields and make it easy to serialize the data using Serde macros. Also added dependencies to cargo.toml to support serde serialization and updated references to NodeDebugService in other files like in diem-node > src > lib.rs.

Closes: aptos-labs#9376
  • Loading branch information
hariria authored and bors-libra committed Oct 11, 2021
1 parent 33c8d87 commit de75d11
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion common/debug-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ edition = "2018"
[dependencies]
anyhow = "1.0.38"
bytes = "1.0.1"
tokio = { version = "1.8.1", features = ["full"] }
reqwest = { version = "0.11.2", features = ["blocking", "json"], default_features = false }
serde = { version = "1.0.124", features = ["derive"], default-features = false }
serde_json = "1.0.64"
tokio = { version = "1.8.1", features = ["full"] }
warp = "0.3.0"

diem-config = { path = "../../config" }
diem-logger = { path = "../logger" }
diem-metrics = { path = "../metrics" }
diem-workspace-hack = { path = "../workspace-hack" }
22 changes: 20 additions & 2 deletions common/debug-interface/src/node_debug_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

//! Debug interface to access information in a specific node.
use diem_config::config::NodeConfig;
use diem_logger::{info, json_log, Filter, Logger};
use diem_metrics::json_metrics::get_git_rev;
use serde::{Deserialize, Serialize};
use std::{net::SocketAddr, sync::Arc};
use tokio::runtime::{Builder, Runtime};
use warp::Filter as _;
Expand All @@ -13,8 +16,16 @@ pub struct NodeDebugService {
runtime: Runtime,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
struct NodeInfo {
#[serde(default)]
node_config: NodeConfig,
#[serde(default)]
git_revision: String,
}

impl NodeDebugService {
pub fn new(address: SocketAddr, logger: Option<Arc<Logger>>) -> Self {
pub fn new(address: SocketAddr, logger: Option<Arc<Logger>>, node_config: &NodeConfig) -> Self {
let runtime = Builder::new_multi_thread()
.thread_name("nodedebug")
.enable_all()
Expand Down Expand Up @@ -65,7 +76,14 @@ impl NodeDebugService {
.and(warp::path("log"))
.and(local_filter.or(remote_filter));

let routes = log.or(warp::get().and(metrics.or(events)));
// Get /node-info (git revision the node was built at and the node config being used)
let node_info = NodeInfo {
git_revision: get_git_rev(),
node_config: node_config.clone(),
};
let node_info_route = warp::path("node-info").map(move || warp::reply::json(&node_info));

let routes = log.or(warp::get().and(metrics.or(events).or(node_info_route)));

runtime
.handle()
Expand Down
4 changes: 4 additions & 0 deletions common/metrics/src/json_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ fn add_revision_hash(mut json_metrics: HashMap<String, String>) -> HashMap<Strin
json_metrics.insert("revision".to_string(), env!("GIT_REV").to_string());
json_metrics
}

pub fn get_git_rev() -> String {
env!("GIT_REV").to_string()
}
2 changes: 1 addition & 1 deletion common/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#![recursion_limit = "128"]

mod json_encoder;
mod json_metrics;
pub mod json_metrics;
pub mod metric_server;
mod public_metrics;

Expand Down
2 changes: 1 addition & 1 deletion diem-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ fn setup_debug_interface(config: &NodeConfig, logger: Option<Arc<Logger>>) -> No
.next()
.unwrap();

NodeDebugService::new(addr, logger)
NodeDebugService::new(addr, logger, config)
}

async fn periodic_state_dump(node_config: NodeConfig, db: DbReaderWriter) {
Expand Down

0 comments on commit de75d11

Please sign in to comment.