-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] Use figment configuration for chroma-load
This mirrors the compactor and query services (and can even merge with their configs if we so choose).
- Loading branch information
Showing
6 changed files
with
68 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
load_service: | ||
service_name: chroma-load | ||
otel_endpoint: "http://otel-collector:4317" | ||
port: 3000 |
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,47 @@ | ||
use figment::providers::{Env, Format, Yaml}; | ||
use serde::Deserialize; | ||
|
||
const DEFAULT_CONFIG_PATH: &str = "./chroma_config.yaml"; | ||
|
||
#[derive(Deserialize)] | ||
/// Root config for chroma-load service. Can be part of a larger config file. | ||
pub struct RootConfig { | ||
pub load_service: LoadServiceConfig, | ||
} | ||
|
||
impl RootConfig { | ||
pub fn load() -> Self { | ||
Self::load_from_path(DEFAULT_CONFIG_PATH) | ||
} | ||
|
||
// NOTE: Copied from ../worker/src/config.rs. | ||
pub fn load_from_path(path: &str) -> Self { | ||
// Unfortunately, figment doesn't support environment variables with underscores. So we have to map and replace them. | ||
// Excluding our own environment variables, which are prefixed with CHROMA_. | ||
let mut f = figment::Figment::from(Env::prefixed("CHROMA_").map(|k| match k { | ||
k if k == "my_member_id" => k.into(), | ||
k => k.as_str().replace("__", ".").into(), | ||
})); | ||
if std::path::Path::new(path).exists() { | ||
f = figment::Figment::from(Yaml::file(path)).merge(f); | ||
} | ||
// Apply defaults - this seems to be the best way to do it. | ||
// https://github.com/SergioBenitez/Figment/issues/77#issuecomment-1642490298 | ||
// f = f.join(Serialized::default( | ||
// "worker.num_indexing_threads", | ||
// num_cpus::get(), | ||
// )); | ||
let res = f.extract(); | ||
match res { | ||
Ok(config) => config, | ||
Err(e) => panic!("Error loading config: {}", e), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct LoadServiceConfig { | ||
pub service_name: String, | ||
pub otel_endpoint: String, | ||
pub port: u16, | ||
} |
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