diff --git a/docker-compose.yml b/docker-compose.yml index fa30b05..14f99ab 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,6 @@ version: '3' services: app: image: hastic/hastic:latest - network_mode: host restart: always environment: HASTIC_PORT: "4347" diff --git a/server/config.example.toml b/server/config.example.toml index 9a0df60..ac8609d 100644 --- a/server/config.example.toml +++ b/server/config.example.toml @@ -1,8 +1,10 @@ port = 4347 -[prometheus] -url = "http://localhost:9090" -query = "rate(go_memstats_alloc_bytes_total[5m])" +# one of datasource sections (prometheus / influx) should be uncommented and edited corresponding to your environment + +# [prometheus] +# url = "http://localhost:9090" +# query = "rate(go_memstats_alloc_bytes_total[5m])" # [influx] @@ -16,8 +18,7 @@ query = "rate(go_memstats_alloc_bytes_total[5m])" # |> yield(name: "mean") # """ -[alerting] -type = "webhook" -interval = 10 # in seconds -endpoint = "http://localhost:9092" - +# [alerting] +# type = "webhook" +# interval = 10 # in seconds +# endpoint = "http://localhost:9092" diff --git a/server/src/config.rs b/server/src/config.rs index 9172b2e..96655d0 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -27,6 +27,7 @@ pub struct Config { fn resolve_datasource(config: &config::Config) -> anyhow::Result { if config.get::("prometheus.url").is_ok() { + println!("using Prometheus"); return Ok(DatasourceConfig::Prometheus(PrometheusConfig { url: config.get("prometheus.url")?, query: config.get("prometheus.query")?, @@ -34,6 +35,7 @@ fn resolve_datasource(config: &config::Config) -> anyhow::Result("influx.url").is_ok() { + println!("using Influx"); return Ok(DatasourceConfig::Influx(InfluxConfig { url: config.get("influx.url")?, org_id: config.get("influx.org_id")?, @@ -42,7 +44,7 @@ fn resolve_datasource(config: &config::Config) -> anyhow::Result anyhow::Result> { @@ -80,18 +82,32 @@ fn resolve_alerting(config: &config::Config) -> anyhow::Result alerting.type pub fn update_from_env(config: &mut config::Config) { let overrides = env::vars().filter_map(|(key, value)| parse_env(&key).map(|index| (index, value))); for (key, value) in overrides { - println!("{} => {}", key, value); config.set(&key, value).unwrap(); } } +pub fn print_config(config: config::Config) { + // TODO: support any nesting level + let sections = config.to_owned().cache.into_table().unwrap(); + for (section_name, values) in sections { + match values.clone().into_table() { + Err(_) => println!("{} => {}", section_name, values), + Ok(section) => { + for (key, value) in section { + println!("{}.{} => {}", section_name, key, value); + } + } + } + } +} + fn parse_env(key: &str) -> Option { const PREFIX: &str = "HASTIC_"; @@ -117,7 +133,8 @@ impl Config { config.set("port", 4347).unwrap(); } - // TODO: print resulted config (perfectly, it needs adding `derive(Debug)` in `subbeat`'s `DatasourceConfig`) + print_config(config.clone()); + Ok(Config { port: config.get::("port").unwrap(), datasource_config: resolve_datasource(&config)?,