Skip to main content

datadog_agent_commons/platform/
mod.rs

1//! Platform-specific settings.
2
3#[cfg(target_os = "linux")]
4mod linux_impl;
5
6use std::path::{Path, PathBuf};
7
8#[cfg(target_os = "linux")]
9pub use self::linux_impl::*;
10
11#[cfg(target_os = "macos")]
12mod macos_impl;
13
14#[cfg(target_os = "macos")]
15pub use self::macos_impl::*;
16
17#[cfg(windows)]
18mod windows_impl;
19
20#[cfg(windows)]
21pub use self::windows_impl::*;
22
23/// Prefix for all environment variables used by the Datadog Agent.
24pub const DATADOG_AGENT_ENV_VAR_PREFIX: &str = "DD";
25
26/// Platform-specific settings and information.
27pub struct PlatformSettings;
28
29impl PlatformSettings {
30    /// Returns the path to the default Datadog Agent configuration directory.
31    pub fn get_config_dir_path() -> &'static Path {
32        get_config_dir_path()
33    }
34
35    /// Returns the path to the default Datadog Agent configuration file.
36    pub fn get_config_file_path() -> PathBuf {
37        Self::get_config_dir_path().join("datadog.yaml")
38    }
39
40    /// Returns the path to the default Datadog Agent authentication token.
41    pub fn get_auth_token_path() -> PathBuf {
42        Self::get_config_dir_path().join("auth_token")
43    }
44
45    /// Returns the filename of the IPC certificate file.
46    pub fn get_ipc_cert_filename() -> &'static Path {
47        Path::new("ipc_cert.pem")
48    }
49
50    /// Returns the default log file path for the Agent Data Plane.
51    pub fn get_default_log_file_path() -> PathBuf {
52        Self::get_log_dir_path().join("agent-data-plane.log")
53    }
54
55    /// Returns the default DogStatsD debug log file path.
56    pub fn get_default_dogstatsd_log_file_path() -> PathBuf {
57        Self::get_log_dir_path()
58            .join("dogstatsd_info")
59            .join("dogstatsd-stats.log")
60    }
61
62    /// Returns the default local syslog URI used by the Datadog Agent on this platform.
63    pub const fn get_default_syslog_uri() -> &'static str {
64        DATADOG_AGENT_DEFAULT_SYSLOG_URI
65    }
66
67    fn get_log_dir_path() -> &'static Path {
68        get_log_dir_path()
69    }
70
71    /// Returns the prefix for all environment variables used by the Datadog Agent.
72    pub const fn get_env_var_prefix() -> &'static str {
73        DATADOG_AGENT_ENV_VAR_PREFIX
74    }
75}
76
77#[cfg(test)]
78mod tests {
79    use super::PlatformSettings;
80
81    #[test]
82    fn default_log_files_are_derived_from_platform_log_dir() {
83        assert_eq!(
84            PlatformSettings::get_default_log_file_path(),
85            PlatformSettings::get_log_dir_path().join("agent-data-plane.log")
86        );
87        assert_eq!(
88            PlatformSettings::get_default_dogstatsd_log_file_path(),
89            PlatformSettings::get_log_dir_path()
90                .join("dogstatsd_info")
91                .join("dogstatsd-stats.log")
92        );
93    }
94}