Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions vls-util/src/env_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ pub fn deployment_environment() -> String {
}

pub fn otlp_endpoint() -> Option<String> {
env::var("OLTP_ENDPOINT").ok()
env::var("OTLP_ENDPOINT").ok()
}

pub fn otlp_timeout() -> u64 {
env::var("OLTP_TIMEOUT")
env::var("OTLP_TIMEOUT")
.unwrap_or("3".to_string())
.parse()
.expect("OLTP Exporter timeout value needs to be a positive number")
.expect("OTLP exporter timeout value needs to be a positive number")
}

pub fn compare_env_var(key: &str, value: &str) -> bool {
Expand All @@ -21,3 +21,34 @@ pub fn compare_env_var(key: &str, value: &str) -> bool {
Err(_) => false,
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::env;

#[test]
fn test_otlp_env_vars() {
let orig_endpoint = env::var("OTLP_ENDPOINT").ok();
let orig_timeout = env::var("OTLP_TIMEOUT").ok();

env::remove_var("OTLP_ENDPOINT");
env::remove_var("OTLP_TIMEOUT");
assert_eq!(otlp_endpoint(), None);
assert_eq!(otlp_timeout(), 3);

env::set_var("OTLP_ENDPOINT", "http://localhost:4317");
env::set_var("OTLP_TIMEOUT", "5");
assert_eq!(otlp_endpoint(), Some("http://localhost:4317".to_string()));
assert_eq!(otlp_timeout(), 5);

match orig_endpoint {
Some(v) => env::set_var("OTLP_ENDPOINT", v),
None => env::remove_var("OTLP_ENDPOINT"),
}
match orig_timeout {
Some(v) => env::set_var("OTLP_TIMEOUT", v),
None => env::remove_var("OTLP_TIMEOUT"),
}
}
}