forked from near/nearcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dynamic config): Refactor and make several config fields reloada…
…ble at runtime (near#8240) Introduce mutable fields in ClientConfig. Intoruce the infrastructure to reload `config.json` and notify `Client` that certain fields were updated. Refactoring to inline `dyn_config.json` into `config.json`.
- Loading branch information
Showing
30 changed files
with
549 additions
and
219 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use near_chain_configs::UpdateableClientConfig; | ||
use near_dyn_configs::{UpdateableConfigLoaderError, UpdateableConfigs}; | ||
use std::sync::Arc; | ||
use tokio::sync::broadcast::Receiver; | ||
|
||
#[derive(Debug)] | ||
pub enum ClientConfigUpdateError {} | ||
|
||
/// Manages updating the config encapsulating. | ||
pub struct ConfigUpdater { | ||
/// Receives config updates while the node is running. | ||
rx_config_update: Receiver<Result<UpdateableConfigs, Arc<UpdateableConfigLoaderError>>>, | ||
|
||
/// Represents the latest Error of reading the dynamically reloadable configs. | ||
updateable_configs_error: Option<Arc<UpdateableConfigLoaderError>>, | ||
} | ||
|
||
impl ConfigUpdater { | ||
pub fn new( | ||
rx_config_update: Receiver<Result<UpdateableConfigs, Arc<UpdateableConfigLoaderError>>>, | ||
) -> Self { | ||
Self { rx_config_update, updateable_configs_error: None } | ||
} | ||
|
||
/// Check if any of the configs were updated. | ||
/// If they did, the receiver (rx_config_update) will contain a clone of the new configs. | ||
pub fn try_update(&mut self, update_client_config_fn: &dyn Fn(UpdateableClientConfig)) { | ||
while let Ok(maybe_updateable_configs) = self.rx_config_update.try_recv() { | ||
match maybe_updateable_configs { | ||
Ok(updateable_configs) => { | ||
if let Some(client_config) = updateable_configs.client_config { | ||
update_client_config_fn(client_config); | ||
tracing::info!(target: "config", "Updated ClientConfig"); | ||
} | ||
self.updateable_configs_error = None; | ||
} | ||
Err(err) => { | ||
self.updateable_configs_error = Some(err.clone()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Prints an error if it's present. | ||
pub fn report_status(&self) { | ||
if let Some(updateable_configs_error) = &self.updateable_configs_error { | ||
tracing::warn!( | ||
target: "stats", | ||
"Dynamically updateable configs are not valid. Please fix this ASAP otherwise the node will probably crash after restart: {}", | ||
*updateable_configs_error); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -265,6 +265,7 @@ pub fn setup( | |
ctx, | ||
None, | ||
adv, | ||
None, | ||
) | ||
.unwrap(); | ||
(genesis_block, client, view_client_addr) | ||
|
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use near_o11y::metrics::{try_create_int_gauge_vec, IntGaugeVec}; | ||
use once_cell::sync::Lazy; | ||
|
||
pub static CONFIG_MUTABLE_FIELD: Lazy<IntGaugeVec> = Lazy::new(|| { | ||
try_create_int_gauge_vec( | ||
"near_config_mutable_field", | ||
"Timestamp and value of a mutable config field", | ||
&["field_name", "timestamp", "value"], | ||
) | ||
.unwrap() | ||
}); |
Oops, something went wrong.