From eed4a67db27ffaa302b80786aa08699b2416c7c6 Mon Sep 17 00:00:00 2001 From: Gustavo Lopes Date: Fri, 6 Sep 2024 10:37:02 +0100 Subject: [PATCH] wip --- remote-config/src/fetch/multitarget.rs | 14 ++++++++++++++ remote-config/src/parse.rs | 3 +++ remote-config/src/path.rs | 12 ++++++++++++ sidecar/src/shm_remote_config.rs | 8 ++++++-- spawn_worker/src/unix/spawn.rs | 8 ++++---- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/remote-config/src/fetch/multitarget.rs b/remote-config/src/fetch/multitarget.rs index 81e0a48c2..6e887eab7 100644 --- a/remote-config/src/fetch/multitarget.rs +++ b/remote-config/src/fetch/multitarget.rs @@ -90,6 +90,16 @@ struct RuntimeInfo { targets: HashMap, u32>, } +type InProcNotifyFn = extern "C" fn(*const u8, usize); +static mut IN_PROC_NOTIFY_FUN: Option = None; + +#[no_mangle] +pub extern "C" fn ddog_set_rc_notify_fn(notify_fn: Option) { + unsafe { + IN_PROC_NOTIFY_FUN = notify_fn; + } +} + impl MultiTargetFetcher where @@ -373,6 +383,10 @@ where files, ); + if let Some(in_proc_notify) = unsafe { IN_PROC_NOTIFY_FUN } { + in_proc_notify(runtime_id.as_ptr(), runtime_id.len()); + } + if notify { // notify_targets is Hash + Eq + Clone, allowing us to deduplicate. Also // avoid the lock during notifying diff --git a/remote-config/src/parse.rs b/remote-config/src/parse.rs index c2893867e..06241b54e 100644 --- a/remote-config/src/parse.rs +++ b/remote-config/src/parse.rs @@ -9,6 +9,7 @@ use datadog_live_debugger::LiveDebuggingData; pub enum RemoteConfigData { DynamicConfig(DynamicConfigFile), LiveDebugger(LiveDebuggingData), + Ignored(RemoteConfigProduct), } impl RemoteConfigData { @@ -24,6 +25,7 @@ impl RemoteConfigData { let parsed = datadog_live_debugger::parse_json(&String::from_utf8_lossy(data))?; RemoteConfigData::LiveDebugger(parsed) } + _ => RemoteConfigData::Ignored(product), }) } } @@ -33,6 +35,7 @@ impl From<&RemoteConfigData> for RemoteConfigProduct { match value { RemoteConfigData::DynamicConfig(_) => RemoteConfigProduct::ApmTracing, RemoteConfigData::LiveDebugger(_) => RemoteConfigProduct::LiveDebugger, + RemoteConfigData::Ignored(product) => *product, } } } diff --git a/remote-config/src/path.rs b/remote-config/src/path.rs index 4c1eb2f11..cd263fc15 100644 --- a/remote-config/src/path.rs +++ b/remote-config/src/path.rs @@ -18,6 +18,10 @@ pub enum RemoteConfigSource { pub enum RemoteConfigProduct { ApmTracing, LiveDebugger, + Asm, + AsmDD, + AsmData, + AsmFeatures, } impl Display for RemoteConfigProduct { @@ -25,6 +29,10 @@ impl Display for RemoteConfigProduct { let str = match self { RemoteConfigProduct::ApmTracing => "APM_TRACING", RemoteConfigProduct::LiveDebugger => "LIVE_DEBUGGING", + RemoteConfigProduct::Asm => "ASM", + RemoteConfigProduct::AsmDD => "ASM_DD", + RemoteConfigProduct::AsmData => "ASM_DATA", + RemoteConfigProduct::AsmFeatures => "ASM_FEATURES", }; write!(f, "{}", str) } @@ -68,6 +76,10 @@ impl RemoteConfigPath { product: match parts[parts.len() - 3] { "APM_TRACING" => RemoteConfigProduct::ApmTracing, "LIVE_DEBUGGING" => RemoteConfigProduct::LiveDebugger, + "ASM" => RemoteConfigProduct::Asm, + "ASM_DD" => RemoteConfigProduct::AsmDD, + "ASM_DATA" => RemoteConfigProduct::AsmData, + "ASM_FEATURES" => RemoteConfigProduct::AsmFeatures, product => anyhow::bail!("Unknown product {}", product), }, config_id: parts[parts.len() - 2], diff --git a/sidecar/src/shm_remote_config.rs b/sidecar/src/shm_remote_config.rs index 7ee4cd2ad..aa6dfc6aa 100644 --- a/sidecar/src/shm_remote_config.rs +++ b/sidecar/src/shm_remote_config.rs @@ -21,7 +21,7 @@ use std::cmp::Reverse; use std::collections::hash_map::Entry; use std::collections::HashMap; use std::default::Default; -use std::ffi::CString; +use std::ffi::{CStr, CString}; use std::hash::{Hash, Hasher}; use std::io; use std::io::Write; @@ -56,6 +56,10 @@ impl RemoteConfigReader { RemoteConfigReader(OneWayShmReader::new(open_named_shm(&path).ok(), path)) } + pub fn get_path(&self) -> &CStr { + &self.0.extra + } + pub fn read(&mut self) -> (bool, &[u8]) { self.0.read() } @@ -343,7 +347,7 @@ fn read_config(path: &str) -> anyhow::Result<(RemoteConfigValue, u32)> { pub struct RemoteConfigManager { invariants: ConfigInvariants, active_target: Option>, - active_reader: Option, + pub active_reader: Option, encountered_targets: HashMap, (RemoteConfigReader, Vec)>, unexpired_targets: PriorityQueue, Reverse>, active_configs: HashMap, diff --git a/spawn_worker/src/unix/spawn.rs b/spawn_worker/src/unix/spawn.rs index f7fc0f7eb..8d3c13607 100644 --- a/spawn_worker/src/unix/spawn.rs +++ b/spawn_worker/src/unix/spawn.rs @@ -501,7 +501,7 @@ impl SpawnWorker { libc::execve(path_ptr, argv.as_ptr(), envp.as_ptr()); - libc::unlink(temp_path.as_ptr() as *const libc::c_char); + // libc::unlink(temp_path.as_ptr() as *const libc::c_char); } } @@ -535,7 +535,7 @@ impl SpawnWorker { libc::execve(path.as_ptr(), argv.as_ptr(), envp.as_ptr()); // if we're here then exec has failed for temp_file in ref_temp_files { - libc::unlink(temp_file.as_ptr()); + // libc::unlink(temp_file.as_ptr()); } panic!("{}", std::io::Error::last_os_error()); }) @@ -559,7 +559,7 @@ impl SpawnWorker { libc::execve(path.as_ptr(), argv.as_ptr(), envp.as_ptr()); // if we're here then exec has failed for temp_file in ref_temp_files { - libc::unlink(temp_file.as_ptr()); + // libc::unlink(temp_file.as_ptr()); } panic!("{}", std::io::Error::last_os_error()); }) @@ -575,7 +575,7 @@ impl SpawnWorker { Ok(fork) => Ok(fork), Err(e) => { for temp_file in ref_temp_files { - libc::unlink(temp_file.as_ptr()); + // libc::unlink(temp_file.as_ptr()); } Err(e) }