From bc939cae478514a7b4046d6af2b908745d4543dd Mon Sep 17 00:00:00 2001 From: finiteprods Date: Thu, 6 Aug 2020 17:13:31 +0200 Subject: [PATCH 1/7] add metrics settings --- rust/src/settings.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/rust/src/settings.rs b/rust/src/settings.rs index d7969ab85..f331b5030 100644 --- a/rust/src/settings.rs +++ b/rust/src/settings.rs @@ -34,6 +34,7 @@ pub struct Settings { pub mask: MaskSettings, pub log: LoggingSettings, pub model: ModelSettings, + pub metrics: MetricsSettings, } impl Settings { @@ -436,6 +437,42 @@ pub struct ModelSettings { pub size: usize, } +#[derive(Debug, Deserialize)] +/// Metrics settings. +pub struct MetricsSettings { + /// The URL address of the metrics store. + /// + /// # Examples + /// + /// **TOML** + /// ```text + /// [metrics] + /// store_url = "http://localhost:8086" + /// ``` + /// + /// **Environment variable** + /// ```text + /// XAYNET_API__STORE_URL=http://localhost:8086 + /// ``` + pub store_url: String, + + /// The name of the metrics store. + /// + /// # Examples + /// + /// **TOML** + /// ```text + /// [metrics] + /// store_name = "test" + /// ``` + /// + /// **Environment variable** + /// ```text + /// XAYNET_API__STORE_NAME=test + /// ``` + pub store_name: String, +} + #[derive(Debug, Deserialize)] /// Logging settings. pub struct LoggingSettings { From 4ac3aed44dad7d30ced236f528fdd0783baddee9 Mon Sep 17 00:00:00 2001 From: finiteprods Date: Thu, 6 Aug 2020 17:14:12 +0200 Subject: [PATCH 2/7] update main, metrics settings not used for now --- rust/src/bin/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/src/bin/main.rs b/rust/src/bin/main.rs index b8e532704..09c2d54b7 100644 --- a/rust/src/bin/main.rs +++ b/rust/src/bin/main.rs @@ -25,6 +25,7 @@ async fn main() { api: api_settings, log: log_settings, model: model_settings, + metrics: _metrics_settings, } = Settings::new(opt.config_path).unwrap_or_else(|err| { eprintln!("{}", err); process::exit(1); From 7993c7f98e6007fb2dd7103d11b983a24ff63a46 Mon Sep 17 00:00:00 2001 From: finiteprods Date: Thu, 6 Aug 2020 17:14:51 +0200 Subject: [PATCH 3/7] update configs --- configs/config.toml | 4 ++++ configs/docker-dev.toml | 4 ++++ configs/docker-release.toml | 4 ++++ k8s/coordinator/development/config.toml | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/configs/config.toml b/configs/config.toml index aa5f2728a..3c21560ff 100644 --- a/configs/config.toml +++ b/configs/config.toml @@ -23,3 +23,7 @@ model_type = "M3" [model] size = 4 + +[metrics] +store_url = "http://influxdb:8086" +store_name = "metrics" diff --git a/configs/docker-dev.toml b/configs/docker-dev.toml index b0ca9676e..acacb6691 100644 --- a/configs/docker-dev.toml +++ b/configs/docker-dev.toml @@ -23,3 +23,7 @@ model_type = "M3" [model] size = 4 + +[metrics] +store_url = "http://influxdb:8086" +store_name = "metrics" diff --git a/configs/docker-release.toml b/configs/docker-release.toml index df29836cf..1b316015e 100644 --- a/configs/docker-release.toml +++ b/configs/docker-release.toml @@ -23,3 +23,7 @@ model_type = "M3" [model] size = 4 + +[metrics] +store_url = "http://influxdb:8086" +store_name = "metrics" diff --git a/k8s/coordinator/development/config.toml b/k8s/coordinator/development/config.toml index 06898534a..07fc1fdc4 100644 --- a/k8s/coordinator/development/config.toml +++ b/k8s/coordinator/development/config.toml @@ -23,3 +23,7 @@ model_type = "M3" [model] size = 4 + +[metrics] +store_url = "http://influxdb:8086" +store_name = "metrics" From 1f4e86704c46c9ae0b0cb0054aa389f1592bce68 Mon Sep 17 00:00:00 2001 From: finiteprods Date: Fri, 7 Aug 2020 09:30:33 +0200 Subject: [PATCH 4/7] fix typo in doc strings - env var egs --- rust/src/settings.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/src/settings.rs b/rust/src/settings.rs index f331b5030..aede11bb4 100644 --- a/rust/src/settings.rs +++ b/rust/src/settings.rs @@ -452,7 +452,7 @@ pub struct MetricsSettings { /// /// **Environment variable** /// ```text - /// XAYNET_API__STORE_URL=http://localhost:8086 + /// XAYNET_METRICS__STORE_URL=http://localhost:8086 /// ``` pub store_url: String, @@ -468,7 +468,7 @@ pub struct MetricsSettings { /// /// **Environment variable** /// ```text - /// XAYNET_API__STORE_NAME=test + /// XAYNET_METRICS__STORE_NAME=test /// ``` pub store_name: String, } From 4211237e026325896184b652540828b52952f69f Mon Sep 17 00:00:00 2001 From: finiteprods Date: Fri, 7 Aug 2020 10:21:36 +0200 Subject: [PATCH 5/7] make influx settings nested under metrics --- rust/src/settings.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/rust/src/settings.rs b/rust/src/settings.rs index aede11bb4..6eaf65e29 100644 --- a/rust/src/settings.rs +++ b/rust/src/settings.rs @@ -440,37 +440,44 @@ pub struct ModelSettings { #[derive(Debug, Deserialize)] /// Metrics settings. pub struct MetricsSettings { - /// The URL address of the metrics store. + /// Settings for the InfluxDB backend. + pub influxdb: InfluxSettings, +} + +#[derive(Debug, Deserialize)] +/// InfluxDB settings. +pub struct InfluxSettings { + /// The URL where InfluxDB is running. /// /// # Examples /// /// **TOML** /// ```text - /// [metrics] - /// store_url = "http://localhost:8086" + /// [metrics.influxdb] + /// url = "http://localhost:8086" /// ``` /// /// **Environment variable** /// ```text - /// XAYNET_METRICS__STORE_URL=http://localhost:8086 + /// XAYNET_METRICS__INFLUXDB__URL=http://localhost:8086 /// ``` - pub store_url: String, + pub url: String, - /// The name of the metrics store. + /// The InfluxDB database name. /// /// # Examples /// /// **TOML** /// ```text - /// [metrics] - /// store_name = "test" + /// [metrics.influxdb] + /// db = "test" /// ``` /// /// **Environment variable** /// ```text - /// XAYNET_METRICS__STORE_NAME=test + /// XAYNET_METRICS__INFLUXDB__DB=test /// ``` - pub store_name: String, + pub db: String, } #[derive(Debug, Deserialize)] From 9af25e807982eded8c25f63b0758813ae3fe50d8 Mon Sep 17 00:00:00 2001 From: finiteprods Date: Fri, 7 Aug 2020 10:22:20 +0200 Subject: [PATCH 6/7] update configs with nested settings --- configs/config.toml | 6 +++--- configs/docker-dev.toml | 6 +++--- configs/docker-release.toml | 6 +++--- k8s/coordinator/development/config.toml | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/configs/config.toml b/configs/config.toml index 3c21560ff..d7a9cc39b 100644 --- a/configs/config.toml +++ b/configs/config.toml @@ -24,6 +24,6 @@ model_type = "M3" [model] size = 4 -[metrics] -store_url = "http://influxdb:8086" -store_name = "metrics" +[metrics.influxdb] +url = "http://influxdb:8086" +db = "metrics" diff --git a/configs/docker-dev.toml b/configs/docker-dev.toml index acacb6691..d6b81adbf 100644 --- a/configs/docker-dev.toml +++ b/configs/docker-dev.toml @@ -24,6 +24,6 @@ model_type = "M3" [model] size = 4 -[metrics] -store_url = "http://influxdb:8086" -store_name = "metrics" +[metrics.influxdb] +url = "http://influxdb:8086" +db = "metrics" diff --git a/configs/docker-release.toml b/configs/docker-release.toml index 1b316015e..6553b9a33 100644 --- a/configs/docker-release.toml +++ b/configs/docker-release.toml @@ -24,6 +24,6 @@ model_type = "M3" [model] size = 4 -[metrics] -store_url = "http://influxdb:8086" -store_name = "metrics" +[metrics.influxdb] +url = "http://influxdb:8086" +db = "metrics" diff --git a/k8s/coordinator/development/config.toml b/k8s/coordinator/development/config.toml index 07fc1fdc4..0e39096a2 100644 --- a/k8s/coordinator/development/config.toml +++ b/k8s/coordinator/development/config.toml @@ -24,6 +24,6 @@ model_type = "M3" [model] size = 4 -[metrics] -store_url = "http://influxdb:8086" -store_name = "metrics" +[metrics.influxdb] +url = "http://influxdb:8086" +db = "metrics" From 048d7b9b0ce9369d81375694e721d6055737189c Mon Sep 17 00:00:00 2001 From: finiteprods Date: Fri, 7 Aug 2020 11:14:44 +0200 Subject: [PATCH 7/7] validate influx url --- rust/src/settings.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rust/src/settings.rs b/rust/src/settings.rs index 6eaf65e29..1dccd219c 100644 --- a/rust/src/settings.rs +++ b/rust/src/settings.rs @@ -34,6 +34,7 @@ pub struct Settings { pub mask: MaskSettings, pub log: LoggingSettings, pub model: ModelSettings, + #[validate] pub metrics: MetricsSettings, } @@ -437,16 +438,18 @@ pub struct ModelSettings { pub size: usize, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Validate)] /// Metrics settings. pub struct MetricsSettings { + #[validate] /// Settings for the InfluxDB backend. pub influxdb: InfluxSettings, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Validate)] /// InfluxDB settings. pub struct InfluxSettings { + #[validate(url)] /// The URL where InfluxDB is running. /// /// # Examples