Skip to content

Commit

Permalink
feat(config): expose config via http endpoint (#2190)
Browse files Browse the repository at this point in the history
  • Loading branch information
gurinderu committed Mar 27, 2024
1 parent 5d1bcac commit 04862bb
Show file tree
Hide file tree
Showing 11 changed files with 433 additions and 46 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions crates/server-config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::net::IpAddr;
use std::path::{Path, PathBuf};
use std::time::Duration;
Expand All @@ -24,7 +24,7 @@ use libp2p::core::Multiaddr;
use libp2p::identity::ed25519::Keypair;
use libp2p::identity::PublicKey;
use libp2p::PeerId;
use maplit::hashmap;
use maplit::{btreemap, hashmap};

use fluence_libp2p::Transport;

Expand Down Expand Up @@ -288,8 +288,8 @@ pub fn default_effectors() -> HashMap<String, (String, HashMap<String, String>)>
}
}

pub fn default_binaries_mapping() -> HashMap<String, String> {
hashmap! {
pub fn default_binaries_mapping() -> BTreeMap<String, String> {
btreemap! {
"curl".to_string() => default_curl_binary_path(),
"ipfs".to_string() => default_ipfs_binary_path(),
}
Expand Down
30 changes: 18 additions & 12 deletions crates/server-config/src/dir_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ pub struct UnresolvedDirConfig {

impl UnresolvedDirConfig {
pub fn resolve(self) -> eyre::Result<ResolvedDirConfig> {
let base = to_abs_path(self.base_dir);
let base_dir = to_abs_path(self.base_dir);

let ephemeral_base_dir = self.ephemeral_base_dir.unwrap_or(ephemeral_dir(&base));
let persistent_base_dir = self.persistent_base_dir.unwrap_or(persistent_dir(&base));
let ephemeral_base_dir = self.ephemeral_base_dir.unwrap_or(ephemeral_dir(&base_dir));
let persistent_base_dir = self
.persistent_base_dir
.unwrap_or(persistent_dir(&base_dir));

// ephemeral dirs
let services_ephemeral_dir = self
Expand All @@ -82,9 +84,7 @@ impl UnresolvedDirConfig {
let services_persistent_dir = self
.services_persistent_dir
.unwrap_or(services_dir(&persistent_base_dir));
let air_interpreter_path = self
.air_interpreter_path
.unwrap_or(air_interpreter_path(&persistent_base_dir));

let spell_base_dir = self
.spell_base_dir
.unwrap_or(persistent_base_dir.join("spell"));
Expand All @@ -98,13 +98,9 @@ impl UnresolvedDirConfig {
let cc_events_dir = self
.cc_events_dir
.unwrap_or(persistent_base_dir.join("cc_events"));
let core_state_path = self
.core_state_path
.clone()
.unwrap_or(persistent_base_dir.join("cores_state.toml"));

create_dirs(&[
&base,
&base_dir,
// ephemeral dirs
&ephemeral_base_dir,
&services_ephemeral_dir,
Expand All @@ -120,7 +116,9 @@ impl UnresolvedDirConfig {
])
.context("creating configured directories")?;

let base_dir = canonicalize(base)?;
let base_dir = canonicalize(base_dir)?;
let ephemeral_base_dir = canonicalize(ephemeral_base_dir)?;
let persistent_base_dir = canonicalize(persistent_base_dir)?;
// ephemeral dirs
let avm_base_dir = canonicalize(avm_base_dir)?;
let services_ephemeral_dir = canonicalize(services_ephemeral_dir)?;
Expand All @@ -133,6 +131,14 @@ impl UnresolvedDirConfig {

let cc_events_dir = canonicalize(cc_events_dir)?;

let air_interpreter_path = self
.air_interpreter_path
.unwrap_or(air_interpreter_path(&persistent_base_dir));
let core_state_path = self
.core_state_path
.clone()
.unwrap_or(persistent_base_dir.join("cores_state.toml"));

Ok(ResolvedDirConfig {
base_dir,
ephemeral_base_dir,
Expand Down
9 changes: 6 additions & 3 deletions crates/server-config/src/node_config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::net::IpAddr;
use std::ops::Deref;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -319,17 +319,19 @@ impl UnresolvedNodeConfig {
}
}

#[derive(Clone, Derivative)]
#[derive(Clone, Derivative, Serialize)]
#[derivative(Debug)]
pub struct NodeConfig {
pub cpus_range: CoreRange,

pub system_cpu_count: usize,

#[derivative(Debug = "ignore")]
#[serde(skip)]
pub root_key_pair: KeyPair,

#[derivative(Debug = "ignore")]
#[serde(skip)]
pub builtins_key_pair: KeyPair,

pub transport_config: TransportConfig,
Expand Down Expand Up @@ -384,6 +386,7 @@ pub struct NodeConfig {

pub particle_execution_timeout: Duration,

#[serde(serialize_with = "peer_id::serde::serialize")]
pub management_peer_id: PeerId,

pub allowed_effectors: HashMap<Hash, HashMap<String, String>>,
Expand Down Expand Up @@ -623,7 +626,7 @@ pub struct DevModeConfig {
pub enable: bool,
/// Mounted binaries mapping: binary name (used in the effector modules) to binary path
#[serde(default = "default_binaries_mapping")]
pub binaries: HashMap<String, String>,
pub binaries: BTreeMap<String, String>,
}

fn default_dev_mode_config() -> DevModeConfig {
Expand Down
2 changes: 1 addition & 1 deletion crates/server-config/src/resolved_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub enum TracingConfig {
},
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize)]
pub struct ResolvedConfig {
pub dir_config: ResolvedDirConfig,
pub node_config: NodeConfig,
Expand Down
2 changes: 1 addition & 1 deletion crates/server-config/src/system_services_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub struct DeciderConfig {
pub start_block: String,
#[serde(default = "default_decider_worker_gas")]
pub worker_gas: u64,
#[serde(default)]
#[serde(default, skip_serializing)]
pub wallet_key: Option<String>,
}

Expand Down
1 change: 1 addition & 0 deletions nox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ bs58 = { workspace = true }
connected-client = { path = "../crates/connected-client" }
log-utils = { workspace = true }
reqwest = { workspace = true }
tempfile = { workspace = true }


[[bench]]
Expand Down
Loading

0 comments on commit 04862bb

Please sign in to comment.