Skip to content

Commit

Permalink
Added env vars to default tag set (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbrowneprima authored Apr 22, 2024
1 parent 87c49d0 commit 1fa6eaa
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Configuration {
to_addr: to_addr.to_string(),
from_addr: DEFAULT_FROM_ADDR.to_string(),
namespace: namespace.to_string(),
tags: vec![],
tags: get_env_tags(),
tracker: TagTrackerConfiguration::new(),
socket_path: None,
batching_options: None,
Expand Down Expand Up @@ -115,6 +115,23 @@ impl From<Configuration> for dogstatsd::Options {
}
}

fn get_env_tags() -> Vec<String> {
let mut tags = vec![];
if let Ok(part_of) = std::env::var("KUBE_APP_PART_OF") {
tags.push(format!("kube_app_part_of:{}", part_of));
}
if let Ok(managed_by) = std::env::var("KUBE_APP_MANAGED_BY") {
tags.push(format!("kube_app_managed_by:{}", managed_by));
}
if let Ok(version) = std::env::var("KUBE_APP_VERSION") {
tags.push(format!("kube_app_version:{}", version));
}
if let Ok(instance) = std::env::var("KUBE_APP_INSTANCE") {
tags.push(format!("kube_app_instance:{}", instance));
}
tags
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 1fa6eaa

Please sign in to comment.