-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix] #4063: update configuration endpoints #4076
Closed
0x009922
wants to merge
4
commits into
hyperledger-iroha:iroha2-dev
from
0x009922:4063-config-endpoints
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,27 +1,35 @@ | ||
use iroha_data_model::Level; | ||
use test_network::*; | ||
|
||
use super::{Builder, Configuration, ConfigurationProxy}; | ||
use super::Configuration; | ||
|
||
#[test] | ||
fn get_config() { | ||
fn config_endpoints() { | ||
// The underscored variables must not be dropped until end of closure. | ||
let (_dont_drop, _dont_drop_either, test_client) = | ||
<PeerBuilder>::new().with_port(10_685).start_with_runtime(); | ||
wait_for_genesis_committed(&vec![test_client.clone()], 0); | ||
let test_cfg = Configuration::test(); | ||
const NEW_LOG_LEVEL: Level = Level::TRACE; | ||
|
||
let field = test_client.get_config_docs(&["torii"]).unwrap().unwrap(); | ||
assert!(field.contains("IROHA_TORII")); | ||
// Just to be sure this test suite is not useless | ||
assert_ne!(test_cfg.logger.max_log_level.value(), NEW_LOG_LEVEL); | ||
|
||
let test = Configuration::test(); | ||
let cfg_proxy: ConfigurationProxy = | ||
serde_json::from_value(test_client.get_config_value().unwrap()).unwrap(); | ||
// Retrieving through API | ||
let mut dto = test_client.get_config().unwrap(); | ||
assert_eq!( | ||
cfg_proxy.block_sync.unwrap().build().unwrap(), | ||
test.block_sync | ||
); | ||
assert_eq!(cfg_proxy.network.unwrap().build().unwrap(), test.network); | ||
assert_eq!( | ||
cfg_proxy.telemetry.unwrap().build().unwrap(), | ||
*test.telemetry | ||
dto.logger.max_log_level, | ||
test_cfg.logger.max_log_level.value() | ||
); | ||
|
||
// Updating the log level | ||
dto.logger.max_log_level = NEW_LOG_LEVEL; | ||
test_client.set_config(dto).unwrap(); | ||
|
||
// FIXME: The updated value is not reflected | ||
// https://github.com/hyperledger/iroha/issues/4079 | ||
|
||
// // Checking the updated value | ||
// let dto = test_client.get_config().unwrap(); | ||
// assert_eq!(dto.logger.max_log_level, NEW_LOG_LEVEL); | ||
} |
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,83 @@ | ||
//! Functionality related to working with the configuration through client API. | ||
//! | ||
//! Intended usage: | ||
//! | ||
//! - Create [`ConfigurationDTO`] from [`crate::iroha::Configuration`] and serialize it for the client | ||
//! - Deserialize [`ConfigurationDTO`] from the client and use [`ConfigurationDTO::apply_update()`] to update the configuration | ||
// TODO: Currently logic here is not generalised and handles only `logger.max_log_level` parameter. In future, when | ||
// other parts of configuration are refactored and there is a solid foundation e.g. as a general | ||
// configuration-related crate, this part should be re-written in a clean way. | ||
// Track configuration refactoring here: https://github.com/hyperledger/iroha/issues/2585 | ||
|
||
use iroha_config_base::runtime_upgrades::{Reload, ReloadError}; | ||
use iroha_data_model::Level; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::{iroha::Configuration as BaseConfiguration, logger::Configuration as BaseLogger}; | ||
|
||
/// Subset of [`super::iroha`] configuration. | ||
#[derive(Debug, Serialize, Deserialize, Clone, Copy)] | ||
pub struct ConfigurationDTO { | ||
#[allow(missing_docs)] | ||
pub logger: Logger, | ||
} | ||
|
||
impl From<&'_ BaseConfiguration> for ConfigurationDTO { | ||
fn from(value: &'_ BaseConfiguration) -> Self { | ||
Self { | ||
logger: value.logger.as_ref().into(), | ||
} | ||
} | ||
} | ||
|
||
impl ConfigurationDTO { | ||
/// Update the base configuration with the values stored in [`Self`]. | ||
pub fn update_base(&self, target: &BaseConfiguration) -> Result<(), ReloadError> { | ||
target | ||
.logger | ||
.max_log_level | ||
.reload(self.logger.max_log_level) | ||
} | ||
} | ||
|
||
/// Subset of [`super::logger`] configuration. | ||
#[derive(Debug, Serialize, Deserialize, Clone, Copy)] | ||
pub struct Logger { | ||
#[allow(missing_docs)] | ||
pub max_log_level: Level, | ||
} | ||
|
||
impl From<&'_ BaseLogger> for Logger { | ||
fn from(value: &'_ BaseLogger) -> Self { | ||
Self { | ||
max_log_level: value.max_log_level.value(), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn snapshot_serialized_form() { | ||
let value = ConfigurationDTO { | ||
logger: Logger { | ||
max_log_level: Level::TRACE, | ||
}, | ||
}; | ||
|
||
let actual = serde_json::to_string_pretty(&value).expect("The value is a valid JSON"); | ||
|
||
// NOTE: whenever this is updated, make sure to update the documentation accordingly: | ||
// https://hyperledger.github.io/iroha-2-docs/reference/torii-endpoints.html | ||
// -> Configuration endpoints | ||
let expected = expect_test::expect![[r#" | ||
{ | ||
"logger": { | ||
"max_log_level": "TRACE" | ||
} | ||
}"#]]; | ||
expected.assert_eq(&actual); | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call it
PartialConfiguration
orDynamicConfiguration
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that
DTO
suffix emphasizes the purpose to use this structure to interact with the client side.Partial
seems to be too general here (likeProxy
s we have already), whileDynamic
might semantically fit.