From e16410d407421859d21bb725de4edb66d1cbac6a Mon Sep 17 00:00:00 2001 From: rozetko Date: Fri, 16 Sep 2022 20:29:40 +0300 Subject: [PATCH 1/4] make influx work in docker --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 010294e..e4592a3 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ all: server client cp server/target/x86_64-unknown-linux-musl/release/hastic release mkdir release/public cp -r client/dist/* release/public/ - cp server/config.example.toml release/config.toml + test -f server/config.toml && cp server/config.toml release/config.toml server: From 57854909f9625475da57cf68f8eb0941913a3803 Mon Sep 17 00:00:00 2001 From: rozetko Date: Fri, 16 Sep 2022 20:32:36 +0300 Subject: [PATCH 2/4] print config on start --- server/src/config.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) 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)?, From f4226a5245cd53a3c3eed92625b2c839f9d9a268 Mon Sep 17 00:00:00 2001 From: rozetko Date: Fri, 16 Sep 2022 20:42:04 +0300 Subject: [PATCH 3/4] upd config example --- Makefile | 2 +- server/config.example.toml | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index e4592a3..010294e 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ all: server client cp server/target/x86_64-unknown-linux-musl/release/hastic release mkdir release/public cp -r client/dist/* release/public/ - test -f server/config.toml && cp server/config.toml release/config.toml + cp server/config.example.toml release/config.toml server: 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" From fce0f30e9eebed4c5c43b8ab3320c111d5ee1288 Mon Sep 17 00:00:00 2001 From: rozetko Date: Fri, 16 Sep 2022 20:51:33 +0300 Subject: [PATCH 4/4] docker-compose: rm "network-mode: host" option --- docker-compose.yml | 1 - 1 file changed, 1 deletion(-) 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"