Skip to content

Commit

Permalink
Use hostname as default proxy id (#391)
Browse files Browse the repository at this point in the history
* Use hostname as default proxy id

If we don't provide a default proxy id this falls back to using the
hostname instead of uuid (and if that fails, then we use a uuid).

For environments like kubernetes, we would like the proxy's id to match
the pod id so that the management server can easily find pod information
for the proxy that is connected to it (the proxy passes its ID when it
connects to the server)

* use hostname only on linux

Co-authored-by: Mark Mandel <[email protected]>
  • Loading branch information
iffyio and markmandel authored Sep 8, 2021
1 parent 398db56 commit 418041f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ tonic = "0.5.0"
uuid = {version = "0.8.1", default-features = false, features = ["v4"]}
thiserror = "1.0.25"

[target.'cfg(target_os = "linux")'.dependencies]
sys-info = "0.9.0"

[dev-dependencies]
reqwest = "0.11.0"
regex = "1.3.9"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/proxy-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ properties:
type: string
description: |
An identifier for the proxy instance.
default: <uuid> A unique ID is generated for the proxy.
default: On linux, the machine hostname is used as default. On all other platforms a UUID is generated for the proxy.
port:
type: integer
description: |
Expand Down
8 changes: 7 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,16 @@ pub struct Proxy {
pub port: u16,
}

#[cfg(not(target_os = "linux"))]
fn default_proxy_id() -> String {
Uuid::new_v4().to_hyphenated().to_string()
}

#[cfg(target_os = "linux")]
fn default_proxy_id() -> String {
sys_info::hostname().unwrap_or_else(|_| Uuid::new_v4().to_hyphenated().to_string())
}

fn default_proxy_port() -> u16 {
7000
}
Expand Down Expand Up @@ -258,7 +264,7 @@ static:
let config = parse_config(yaml);

assert_eq!(config.proxy.port, 7000);
assert_eq!(config.proxy.id.len(), 36);
assert!(config.proxy.id.len() > 1);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/proxy/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ impl Server {

/// log_config outputs a log of what is configured
fn log_config(&self) {
info!(self.log, "Starting"; "port" => self.config.proxy.port);
info!(self.log, "Starting"; "port" => self.config.proxy.port, "proxy_id" => &self.config.proxy.id);
}

/// bind binds the local configured port
Expand Down

0 comments on commit 418041f

Please sign in to comment.