Skip to content

Commit

Permalink
Use sensitive url
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed May 4, 2021
1 parent 4902f59 commit e29b6ed
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion common/monitoring_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2018"
reqwest = { version = "0.11.0", features = ["json","stream"] }
futures = "0.3.7"
task_executor = { path = "../task_executor" }
tokio = { version = "1.1.0", features = ["full"] }
tokio = "1.1.0"
eth2 = {path = "../eth2"}
serde_json = "1.0.58"
serde = "1.0.116"
Expand All @@ -21,3 +21,4 @@ slog = "2.5.2"
store = { path = "../../beacon_node/store" }
lazy_static = "1.4.0"
regex = "1"
sensitive_url = { path = "../sensitive_url" }
24 changes: 15 additions & 9 deletions common/monitoring_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use eth2::lighthouse::SystemHealth;
use gather::{gather_beacon_metrics, gather_validator_metrics};
use reqwest::{IntoUrl, Response};
pub use reqwest::{StatusCode, Url};
use sensitive_url::SensitiveUrl;
use serde::{Deserialize, Serialize};
use slog::{debug, error, info};
use task_executor::TaskExecutor;
Expand All @@ -24,7 +25,7 @@ pub enum Error {
/// The `reqwest` client raised an error.
Reqwest(reqwest::Error),
/// The supplied URL is badly formatted. It should look something like `http://127.0.0.1:5052`.
InvalidUrl(Url),
InvalidUrl(SensitiveUrl),
SystemMetricsFailed(String),
BeaconMetricsFailed(String),
ValidatorMetricsFailed(String),
Expand All @@ -38,7 +39,11 @@ pub enum Error {

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
if let Error::Reqwest(e) = self {
write!(f, "Reqwest error: {}", e)
} else {
write!(f, "{}", self)
}
}
}

Expand All @@ -61,7 +66,7 @@ pub struct MonitoringHttpClient {
db_path: Option<PathBuf>,
/// Path to the freezer database.
freezer_db_path: Option<PathBuf>,
monitoring_endpoint: Url,
monitoring_endpoint: SensitiveUrl,
log: slog::Logger,
}

Expand All @@ -71,8 +76,8 @@ impl MonitoringHttpClient {
client: reqwest::Client::new(),
db_path: config.db_path.clone(),
freezer_db_path: config.freezer_db_path.clone(),
monitoring_endpoint: Url::parse(&config.monitoring_endpoint)
.map_err(|e| format!("Invalid explorer endpoint: {}", e))?,
monitoring_endpoint: SensitiveUrl::parse(&config.monitoring_endpoint)
.map_err(|e| format!("Invalid monitoring endpoint: {:?}", e))?,
log,
})
}
Expand Down Expand Up @@ -100,14 +105,14 @@ impl MonitoringHttpClient {
Duration::from_secs(UPDATE_DURATION),
);

info!(self.log, "Starting monitoring api");
info!(self.log, "Starting monitoring api"; "endpoint" => %self.monitoring_endpoint);

let update_future = async move {
loop {
interval.tick().await;
match self.send_metrics(&processes).await {
Ok(()) => {
debug!(self.log, "Sent metrics to remote server"; "endpoint" => %self.monitoring_endpoint);
debug!(self.log, "Metrics sent to remote server"; "endpoint" => %self.monitoring_endpoint);
}
Err(e) => {
error!(self.log, "Failed to send metrics to remote endpoint"; "error" => %e)
Expand Down Expand Up @@ -154,7 +159,7 @@ impl MonitoringHttpClient {
})
}

/// Return explorer metric based on process type.
/// Return metric based on process type.
pub async fn get_metrics(
&self,
process_type: &ProcessType,
Expand Down Expand Up @@ -185,7 +190,8 @@ impl MonitoringHttpClient {
"Sending metrics to remote endpoint";
"endpoint" => %self.monitoring_endpoint
);
self.post(self.monitoring_endpoint.clone(), &metrics).await
self.post(self.monitoring_endpoint.full.clone(), &metrics)
.await
}
}

Expand Down

0 comments on commit e29b6ed

Please sign in to comment.