diff --git a/ddcommon/src/entity_id/fallback.rs b/ddcommon/src/entity_id/fallback.rs deleted file mode 100644 index 415a71245..000000000 --- a/ddcommon/src/entity_id/fallback.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ -// SPDX-License-Identifier: Apache-2.0 - -pub fn set_cgroup_file(_file: String) {} - -pub fn set_cgroup_mount_path(_path: String) {} - -pub fn get_container_id() -> Option<&'static str> { - None -} - -pub fn get_entity_id() -> Option<&'static str> { - None -} diff --git a/ddcommon/src/entity_id/mod.rs b/ddcommon/src/entity_id/mod.rs index e108765ee..48c59aa40 100644 --- a/ddcommon/src/entity_id/mod.rs +++ b/ddcommon/src/entity_id/mod.rs @@ -49,16 +49,50 @@ //! 1:name=systemd:/ecs/8cd79a803caf4d2aa945152e934a5c00/8cd79a803caf4d2aa945152e934a5c00-1053176469 //! ``` -#[cfg(not(unix))] -pub use fallback::{get_container_id, get_entity_id, set_cgroup_file, set_cgroup_mount_path}; - -#[cfg(unix)] -pub use unix::{get_container_id, get_entity_id, set_cgroup_file, set_cgroup_mount_path}; - -/// Fallback module used for non-unix systems -#[cfg(not(unix))] -mod fallback; - /// Unix specific module allowing the use of unix specific functions #[cfg(unix)] mod unix; + +/// Returns the `container_id` if available in the cgroup file, otherwise returns `None` +pub fn get_container_id() -> Option<&'static str> { + #[cfg(unix)] + { + unix::get_container_id() + } + #[cfg(not(unix))] + { + None + } +} + +/// Returns the `entity_id` if available, either `cid-` or `in-` +pub fn get_entity_id() -> Option<&'static str> { + #[cfg(unix)] + { + unix::get_entity_id() + } + #[cfg(not(unix))] + { + None + } +} + +/// Set the path to cgroup file to mock it during tests +/// # Safety +/// Must not be called in multi-threaded contexts +pub unsafe fn set_cgroup_file(file: String) { + #[cfg(unix)] + { + unix::set_cgroup_file(file) + } +} + +/// Set cgroup mount path to mock during tests +/// # Safety +/// Must not be called in multi-threaded contexts +pub unsafe fn set(path: String) { + #[cfg(unix)] + { + unix::set_cgroup_mount_path(path) + } +}