feature: Get endpoint addresses from config

This commit is contained in:
teor 2020-07-28 14:35:07 +10:00
parent 11090dbf91
commit e7437cc551
4 changed files with 17 additions and 11 deletions

View File

@ -172,6 +172,7 @@ impl ZebradApp {
tracing: tracing:
crate::config::TracingSection { crate::config::TracingSection {
filter: Some(filter), filter: Some(filter),
endpoint_addr: _,
}, },
.. ..
}) = &self.config }) = &self.config

View File

@ -1,10 +1,10 @@
//! An HTTP endpoint for metrics collection. //! 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 abscissa_core::{Component, FrameworkError};
use crate::components::tokio::TokioComponent; use metrics_runtime::{exporters::HttpExporter, observers::PrometheusBuilder, Receiver};
/// Abscissa component which runs a metrics endpoint. /// Abscissa component which runs a metrics endpoint.
#[derive(Debug, Component)] #[derive(Debug, Component)]
@ -21,10 +21,7 @@ impl MetricsEndpoint {
pub fn init_tokio(&mut self, tokio_component: &TokioComponent) -> Result<(), FrameworkError> { pub fn init_tokio(&mut self, tokio_component: &TokioComponent) -> Result<(), FrameworkError> {
info!("Initializing metrics endpoint"); info!("Initializing metrics endpoint");
// XXX load metrics addr from config let addr = app_config().metrics.endpoint_addr;
let addr = "0.0.0.0:9999"
.parse()
.expect("Hardcoded address should be parseable");
// XXX do we need to hold on to the receiver? // XXX do we need to hold on to the receiver?
let receiver = Receiver::builder() let receiver = Receiver::builder()

View File

@ -35,10 +35,7 @@ impl TracingEndpoint {
let service = let service =
make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(request_handler)) }); make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(request_handler)) });
// XXX load tracing addr from config let addr = app_config().tracing.endpoint_addr;
let addr = "0.0.0.0:3000"
.parse()
.expect("Hardcoded address should be parseable");
tokio_component tokio_component
.rt .rt

View File

@ -33,17 +33,27 @@ pub struct ZebradConfig {
} }
/// Tracing configuration section. /// Tracing configuration section.
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields, default)] #[serde(deny_unknown_fields, default)]
pub struct TracingSection { pub struct TracingSection {
/// The filter used for tracing events. /// The filter used for tracing events.
pub filter: Option<String>, pub filter: Option<String>,
/// The endpoint address used for tracing.
pub endpoint_addr: SocketAddr,
}
impl Default for TracingSection {
fn default() -> Self {
Self::populated()
}
} }
impl TracingSection { impl TracingSection {
pub fn populated() -> Self { pub fn populated() -> Self {
Self { Self {
filter: Some("info".to_owned()), 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)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields, default)] #[serde(deny_unknown_fields, default)]
pub struct MetricsSection { pub struct MetricsSection {
/// The endpoint address used for metrics.
pub endpoint_addr: SocketAddr, pub endpoint_addr: SocketAddr,
} }