Skip to content

new module 'config' for mesh attributes #774

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions hyperactor_mesh/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

use hyperactor::attrs::declare_attrs;

declare_attrs! {
pub attr ROUTER_CONFIG_NO_GLOBAL_FALLBACK: bool = false;
}

/// Extend hyperactor global config with mesh-specific settings.
pub fn init_global_from_env() {
hyperactor::config::global::init_from_env();

let config_lock = hyperactor::config::global::lock();

if std::env::var("HYPERACTOR_ROUTER_CONFIG_NO_GLOBAL_FALLBACK").is_ok() {
let guard = config_lock.override_key(ROUTER_CONFIG_NO_GLOBAL_FALLBACK, true);
std::mem::forget(guard);
}
}

#[cfg(test)]
mod tests {
use hyperactor::config;

use super::*;

#[test]
fn test_init_global_from_env() {
config::global::reset_to_defaults();
assert_eq!(
config::global::get(hyperactor::config::MESSAGE_DELIVERY_TIMEOUT),
std::time::Duration::from_secs(30)
);
assert!(!config::global::get(ROUTER_CONFIG_NO_GLOBAL_FALLBACK));

// SAFETY: We rely on no concurrent access here.
unsafe {
std::env::set_var("HYPERACTOR_ROUTER_CONFIG_NO_GLOBAL_FALLBACK", "1");
}
init_global_from_env();
assert!(config::global::get(ROUTER_CONFIG_NO_GLOBAL_FALLBACK));

// SAFETY: We rely on no concurrent access here.
unsafe {
std::env::remove_var("HYPERACTOR_ROUTER_CONFIG_NO_GLOBAL_FALLBACK");
}
config::global::reset_to_defaults();
}
}
1 change: 1 addition & 0 deletions hyperactor_mesh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod alloc;
mod assign;
pub mod bootstrap;
pub mod comm;
pub mod config;
pub mod connect;
pub mod logging;
pub mod mesh;
Expand Down
3 changes: 3 additions & 0 deletions hyperactor_mesh/test/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ async fn main() {
.finish();
tracing::subscriber::set_global_default(subscriber).expect("failed to set subscriber");

// Load hyperactor and mesh settings from env into global config.
hyperactor_mesh::config::init_global_from_env();

hyperactor_mesh::bootstrap_or_die().await;
}