Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cataphract committed Sep 6, 2024
1 parent 9f96224 commit eed4a67
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
14 changes: 14 additions & 0 deletions remote-config/src/fetch/multitarget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ struct RuntimeInfo<N: NotifyTarget> {
targets: HashMap<Arc<Target>, u32>,
}

type InProcNotifyFn = extern "C" fn(*const u8, usize);
static mut IN_PROC_NOTIFY_FUN: Option<InProcNotifyFn> = None;

#[no_mangle]
pub extern "C" fn ddog_set_rc_notify_fn(notify_fn: Option<InProcNotifyFn>) {
unsafe {
IN_PROC_NOTIFY_FUN = notify_fn;
}
}

impl<N: NotifyTarget + 'static, S: FileStorage + Clone + Sync + Send + 'static>
MultiTargetFetcher<N, S>
where
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions remote-config/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use datadog_live_debugger::LiveDebuggingData;
pub enum RemoteConfigData {
DynamicConfig(DynamicConfigFile),
LiveDebugger(LiveDebuggingData),
Ignored(RemoteConfigProduct),
}

impl RemoteConfigData {
Expand All @@ -24,6 +25,7 @@ impl RemoteConfigData {
let parsed = datadog_live_debugger::parse_json(&String::from_utf8_lossy(data))?;
RemoteConfigData::LiveDebugger(parsed)
}
_ => RemoteConfigData::Ignored(product),
})
}
}
Expand All @@ -33,6 +35,7 @@ impl From<&RemoteConfigData> for RemoteConfigProduct {
match value {
RemoteConfigData::DynamicConfig(_) => RemoteConfigProduct::ApmTracing,
RemoteConfigData::LiveDebugger(_) => RemoteConfigProduct::LiveDebugger,
RemoteConfigData::Ignored(product) => *product,
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions remote-config/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ pub enum RemoteConfigSource {
pub enum RemoteConfigProduct {
ApmTracing,
LiveDebugger,
Asm,
AsmDD,
AsmData,
AsmFeatures,
}

impl Display for RemoteConfigProduct {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
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)
}
Expand Down Expand Up @@ -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],
Expand Down
8 changes: 6 additions & 2 deletions sidecar/src/shm_remote_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -343,7 +347,7 @@ fn read_config(path: &str) -> anyhow::Result<(RemoteConfigValue, u32)> {
pub struct RemoteConfigManager {
invariants: ConfigInvariants,
active_target: Option<Arc<Target>>,
active_reader: Option<RemoteConfigReader>,
pub active_reader: Option<RemoteConfigReader>,
encountered_targets: HashMap<Arc<Target>, (RemoteConfigReader, Vec<String>)>,
unexpired_targets: PriorityQueue<Arc<Target>, Reverse<Instant>>,
active_configs: HashMap<String, RemoteConfigPath>,
Expand Down
8 changes: 4 additions & 4 deletions spawn_worker/src/unix/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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());
})
Expand All @@ -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());
})
Expand All @@ -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)
}
Expand Down

0 comments on commit eed4a67

Please sign in to comment.