Skip to content

Commit

Permalink
Fix Admin Config model and documentation (#218)
Browse files Browse the repository at this point in the history
Update the model and documentation for the Admin interface to match, and
provide defaulting.

Next will be the implementation of the `Admin` functionality, and pulling
it out of `Metrics`.

Work on #101
  • Loading branch information
markmandel authored Mar 22, 2021
1 parent 3c99ddf commit 826abf9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
15 changes: 5 additions & 10 deletions docs/proxy-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ properties:
admin:
type: object
description: |
Configuration of operational proxy behavior.
Configuration of proxy admin HTTP interface.
properties:
metrics:
type: object
address:
type: string
description: |
Metrics related configuration.
properties:
port:
type: integer
description: |
Port on which to expose metrics.
default: 9091
Socket Address and port to bind the administration interface to.
default: [::]:9091
static:
type: object
description: |
Expand Down
6 changes: 4 additions & 2 deletions src/config/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@
*/

use super::{Config, Filter};
use crate::config::{EndPoint, Proxy, Source, Version};
use crate::config::{Admin, EndPoint, Proxy, Source, Version};

/// Builder for a [`Config`]
#[derive(Debug)]
pub struct Builder {
pub port: u16,
pub source: Source,
pub admin: Admin,
}

impl Builder {
/// Returns a [`Builder`] with empty values.
pub fn empty() -> Self {
Builder {
port: 0,
admin: Admin::default(),
source: Source::Static {
filters: vec![],
endpoints: vec![],
Expand All @@ -52,7 +54,7 @@ impl Builder {
id: "test".into(),
port: self.port,
},
admin: None,
admin: self.admin,
source: self.source,
phantom: None,
}
Expand Down
16 changes: 10 additions & 6 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ impl Default for Proxy {
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AdminAddress {
port: u16,
pub struct Admin {
pub address: SocketAddr,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Admin {
address: Option<AdminAddress>,
impl Default for Admin {
fn default() -> Self {
Admin {
address: "[::]:9091".parse().unwrap(),
}
}
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
Expand Down Expand Up @@ -106,7 +109,8 @@ pub struct Config {
#[serde(default)]
pub proxy: Proxy,

pub admin: Option<Admin>,
#[serde(default)]
pub admin: Admin,

#[serde(flatten)]
pub source: Source,
Expand Down
2 changes: 1 addition & 1 deletion src/proxy/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(super) enum ValidatedSource {
pub(super) struct ValidatedConfig {
pub version: Version,
pub proxy: Proxy,
pub admin: Option<Admin>,
pub admin: Admin,
pub source: ValidatedSource,
// Limit struct creation to the builder.
pub phantom: PhantomData<()>,
Expand Down

0 comments on commit 826abf9

Please sign in to comment.