Module global

Module global 

Source
Expand description

Global layered configuration for Hyperactor.

This module provides the process-wide configuration store and APIs to access it. Configuration values are resolved via a layered model: TestOverride → Env → Runtime → File → ClientOverride → Default.

  • Reads (get, get_cloned) consult layers in that order, falling back to defaults if no explicit value is set.
  • attrs() returns a complete snapshot of all CONFIG-marked keys at call time: it materializes defaults for keys not set in any layer. Keys without @meta(CONFIG = …) are excluded.
  • In tests, lock() and override_key allow temporary overrides that are removed automatically when the guard drops.
  • In normal operation, a parent process can capture its effective config via attrs() and pass that snapshot to a child during bootstrap. The child installs it as a ClientOverride layer. Note that Env and Runtime layers will take precedence over this inherited configuration.

This design provides flexibility (easy test overrides, runtime updates, YAML/Env baselines) while ensuring type safety and predictable resolution order.

§Testing

Tests can override global configuration using lock. This ensures such tests are serialized (and cannot clobber each other’s overrides).

#[test]
fn test_my_feature() {
    let config = hyperactor::config::global::lock();
    let _guard = config.override_key(SOME_CONFIG_KEY, test_value);
    // ... test logic here ...
}

Structs§

ConfigLock
A guard that holds the global configuration lock and provides override functionality.
ConfigValueGuard
A guard that restores a single configuration value when dropped.

Enums§

Source
Configuration source layers in priority order.

Functions§

attrs
Return a complete, merged snapshot of the effective configuration (only keys marked with @meta(CONFIG = ...)).
clear
Remove the configuration layer for the given Source, if present.
create_or_merge
Insert or update a configuration layer for the given Source.
get
Get a key from the global configuration (Copy types).
get_cloned
Get a key by cloning the value.
init_from_env
Initialize the global configuration from environment variables.
init_from_yaml
Initialize the global configuration from a YAML file.
lock
Acquire the global configuration lock.
override_or_global
Return the override value for key if it is explicitly present in overrides, otherwise fall back to the global value for that key.
reset_to_defaults
Reset the global configuration to only Defaults (for testing).
runtime_attrs
Snapshot the current attributes in the Runtime configuration layer.
set
Insert or replace a configuration layer for the given source.
try_get_cloned
Try to get a key by cloning the value.