Skip to content

Commit

Permalink
balancer: Add Region Configuration (#1138)
Browse files Browse the repository at this point in the history
* Add Region Configuration

Fixes #1126
In Progress

* namespace fix

* specify FLY_REGION

* different approach for picking up fly_region

* store region in BalancerConfig

* update default region to unknown

* debugging

* format

* fix lint

---------

Co-authored-by: Carson McManus <carson.mcmanus1@gmail.com>
  • Loading branch information
cjrkoa and dyc3 authored Nov 14, 2023
1 parent d96bc03 commit 28495bd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/ott-balancer-bin/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ pub struct BalancerConfig {
/// The port to listen on for HTTP requests.
pub port: u16,
pub discovery: DiscoveryConfig,
pub region: String,
}

impl Default for BalancerConfig {
fn default() -> Self {
Self {
port: 8081,
discovery: DiscoveryConfig::default(),
region: "unknown".to_owned(),
}
}
}
Expand All @@ -43,10 +45,14 @@ impl Default for DiscoveryConfig {

impl BalancerConfig {
pub fn load(path: &PathBuf) -> anyhow::Result<()> {
let config = figment::Figment::new()
let mut config: BalancerConfig = figment::Figment::new()
.merge(figment::providers::Toml::file(path))
.merge(figment::providers::Env::prefixed("BALANCER_"))
.extract()?;

if let Some(region) = figment::providers::Env::var("FLY_REGION") {
config.region = region;
}
// SAFETY: CONFIG is only mutated once, and only from this thread. All other accesses are read-only.
CONFIG_INIT.call_once(|| unsafe { *CONFIG.borrow_mut() = Some(config) });
Ok(())
Expand Down

0 comments on commit 28495bd

Please sign in to comment.