-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable configuration hot-reloading (#231)
- Loading branch information
1 parent
d396f7b
commit 248538a
Showing
23 changed files
with
224 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
mod get_header; | ||
mod register_validator; | ||
mod reload; | ||
mod status; | ||
mod submit_block; | ||
|
||
pub use get_header::get_header; | ||
pub use register_validator::register_validator; | ||
pub use reload::reload; | ||
pub use status::get_status; | ||
pub use submit_block::submit_block; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use cb_common::config::load_pbs_config; | ||
use tracing::warn; | ||
|
||
use crate::{BuilderApiState, PbsState}; | ||
|
||
/// Reload the PBS state with the latest configuration in the config file | ||
/// Returns 200 if successful or 500 if failed | ||
pub async fn reload<S: BuilderApiState>(state: PbsState<S>) -> eyre::Result<PbsState<S>> { | ||
let pbs_config = load_pbs_config().await?; | ||
let new_state = PbsState::new(pbs_config).with_data(state.data); | ||
|
||
if state.config.pbs_config.host != new_state.config.pbs_config.host { | ||
warn!( | ||
"Host change for PBS module require a full restart. Old: {}, New: {}", | ||
state.config.pbs_config.host, new_state.config.pbs_config.host | ||
); | ||
} | ||
|
||
if state.config.pbs_config.port != new_state.config.pbs_config.port { | ||
warn!( | ||
"Port change for PBS module require a full restart. Old: {}, New: {}", | ||
state.config.pbs_config.port, new_state.config.pbs_config.port | ||
); | ||
} | ||
|
||
Ok(new_state) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod get_header; | ||
mod register_validator; | ||
mod reload; | ||
mod router; | ||
mod status; | ||
mod submit_block; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use axum::{extract::State, http::HeaderMap, response::IntoResponse}; | ||
use cb_common::{pbs::BuilderEvent, utils::get_user_agent}; | ||
use reqwest::StatusCode; | ||
use tracing::{error, info}; | ||
use uuid::Uuid; | ||
|
||
use crate::{ | ||
error::PbsClientError, | ||
metrics::BEACON_NODE_STATUS, | ||
state::{BuilderApiState, PbsStateGuard}, | ||
BuilderApi, RELOAD_ENDPOINT_TAG, | ||
}; | ||
|
||
#[tracing::instrument(skip_all, name = "reload", fields(req_id = %Uuid::new_v4()))] | ||
pub async fn handle_reload<S: BuilderApiState, A: BuilderApi<S>>( | ||
req_headers: HeaderMap, | ||
State(state): State<PbsStateGuard<S>>, | ||
) -> Result<impl IntoResponse, PbsClientError> { | ||
let prev_state = state.read().clone(); | ||
|
||
prev_state.publish_event(BuilderEvent::ReloadEvent); | ||
|
||
let ua = get_user_agent(&req_headers); | ||
|
||
info!(ua, relay_check = prev_state.config.pbs_config.relay_check); | ||
|
||
match A::reload(prev_state.clone()).await { | ||
Ok(new_state) => { | ||
prev_state.publish_event(BuilderEvent::ReloadResponse); | ||
info!("config reload successful"); | ||
|
||
*state.write() = new_state; | ||
|
||
BEACON_NODE_STATUS.with_label_values(&["200", RELOAD_ENDPOINT_TAG]).inc(); | ||
Ok((StatusCode::OK, "OK")) | ||
} | ||
Err(err) => { | ||
error!(%err, "config reload failed"); | ||
|
||
let err = PbsClientError::Internal; | ||
BEACON_NODE_STATUS | ||
.with_label_values(&[err.status_code().as_str(), RELOAD_ENDPOINT_TAG]) | ||
.inc(); | ||
Err(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.