From e7437cc5519cd64dfb66878a9f2345b2fe16b185 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 28 Jul 2020 14:35:07 +1000 Subject: [PATCH] feature: Get endpoint addresses from config --- zebrad/src/application.rs | 1 + zebrad/src/components/metrics.rs | 9 +++------ zebrad/src/components/tracing.rs | 5 +---- zebrad/src/config.rs | 13 ++++++++++++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/zebrad/src/application.rs b/zebrad/src/application.rs index 50e97a495..b4e219913 100644 --- a/zebrad/src/application.rs +++ b/zebrad/src/application.rs @@ -172,6 +172,7 @@ impl ZebradApp { tracing: crate::config::TracingSection { filter: Some(filter), + endpoint_addr: _, }, .. }) = &self.config diff --git a/zebrad/src/components/metrics.rs b/zebrad/src/components/metrics.rs index 84526af9f..85d63bf07 100644 --- a/zebrad/src/components/metrics.rs +++ b/zebrad/src/components/metrics.rs @@ -1,10 +1,10 @@ //! An HTTP endpoint for metrics collection. -use metrics_runtime::{exporters::HttpExporter, observers::PrometheusBuilder, Receiver}; +use crate::{components::tokio::TokioComponent, prelude::*}; use abscissa_core::{Component, FrameworkError}; -use crate::components::tokio::TokioComponent; +use metrics_runtime::{exporters::HttpExporter, observers::PrometheusBuilder, Receiver}; /// Abscissa component which runs a metrics endpoint. #[derive(Debug, Component)] @@ -21,10 +21,7 @@ impl MetricsEndpoint { pub fn init_tokio(&mut self, tokio_component: &TokioComponent) -> Result<(), FrameworkError> { info!("Initializing metrics endpoint"); - // XXX load metrics addr from config - let addr = "0.0.0.0:9999" - .parse() - .expect("Hardcoded address should be parseable"); + let addr = app_config().metrics.endpoint_addr; // XXX do we need to hold on to the receiver? let receiver = Receiver::builder() diff --git a/zebrad/src/components/tracing.rs b/zebrad/src/components/tracing.rs index fabd7db0e..703dca2ab 100644 --- a/zebrad/src/components/tracing.rs +++ b/zebrad/src/components/tracing.rs @@ -35,10 +35,7 @@ impl TracingEndpoint { let service = make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(request_handler)) }); - // XXX load tracing addr from config - let addr = "0.0.0.0:3000" - .parse() - .expect("Hardcoded address should be parseable"); + let addr = app_config().tracing.endpoint_addr; tokio_component .rt diff --git a/zebrad/src/config.rs b/zebrad/src/config.rs index 01b812a1c..6e7420ea4 100644 --- a/zebrad/src/config.rs +++ b/zebrad/src/config.rs @@ -33,17 +33,27 @@ pub struct ZebradConfig { } /// Tracing configuration section. -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] #[serde(deny_unknown_fields, default)] pub struct TracingSection { /// The filter used for tracing events. pub filter: Option, + + /// The endpoint address used for tracing. + pub endpoint_addr: SocketAddr, +} + +impl Default for TracingSection { + fn default() -> Self { + Self::populated() + } } impl TracingSection { pub fn populated() -> Self { Self { filter: Some("info".to_owned()), + endpoint_addr: "0.0.0.0:3000".parse().unwrap(), } } } @@ -52,6 +62,7 @@ impl TracingSection { #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(deny_unknown_fields, default)] pub struct MetricsSection { + /// The endpoint address used for metrics. pub endpoint_addr: SocketAddr, }