Skip to content

Commit

Permalink
Use the correct format for capability submission
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Weinand <[email protected]>
  • Loading branch information
bwoebi committed Oct 3, 2024
1 parent d01cf11 commit 4b0597e
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions remote-config/src/fetch/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub struct ConfigFetcherState<S> {
target_files_by_path: Mutex<HashMap<Arc<RemoteConfigPath>, StoredTargetFile<S>>>,
pub invariants: ConfigInvariants,
endpoint: Endpoint,
encoded_capabilities: Vec<u8>,
pub expire_unused_files: bool,
}

Expand Down Expand Up @@ -124,10 +125,21 @@ impl<'a, S> ConfigFetcherFilesLock<'a, S> {

impl<S> ConfigFetcherState<S> {
pub fn new(invariants: ConfigInvariants) -> Self {
let capability_len = invariants
.capabilities
.iter()
.map(|c| (*c as usize - 1) / 8 + 1)
.max()
.unwrap_or(0);
let mut encoded_capabilities = vec![0; capability_len];
for capability in invariants.capabilities.iter().map(|c| *c as usize) {
encoded_capabilities[capability_len - (capability >> 3) - 1] |= 1 << (capability & 7);
}
ConfigFetcherState {
target_files_by_path: Default::default(),
endpoint: get_product_endpoint(PROD_INTAKE_SUBDOMAIN, &invariants.endpoint),
invariants,
encoded_capabilities,
expire_unused_files: true,
}
}
Expand Down Expand Up @@ -280,13 +292,7 @@ impl<S: FileStorage> ConfigFetcher<S> {
is_agent: false,
client_agent: None,
last_seen: 0,
capabilities: self
.state
.invariants
.capabilities
.iter()
.map(|c| *c as u8)
.collect(),
capabilities: self.state.encoded_capabilities.clone(),
}),
cached_target_files,
};
Expand Down Expand Up @@ -683,10 +689,7 @@ pub mod tests {
assert!(req.cached_target_files.is_empty());

let client = req.client.as_ref().unwrap();
assert_eq!(
client.capabilities,
&[RemoteConfigCapabilities::ApmTracingCustomTags as u8]
);
assert_eq!(client.capabilities, &[128, 0]);
assert_eq!(client.products, &["APM_TRACING", "LIVE_DEBUGGING"]);
assert!(client.is_tracer);
assert!(!client.is_agent);
Expand Down Expand Up @@ -738,10 +741,7 @@ pub mod tests {
assert_eq!(req.cached_target_files.len(), 1);

let client = req.client.as_ref().unwrap();
assert_eq!(
client.capabilities,
&[RemoteConfigCapabilities::ApmTracingCustomTags as u8]
);
assert_eq!(client.capabilities, &[128, 0]);
assert_eq!(client.products, &["APM_TRACING", "LIVE_DEBUGGING"]);
assert!(client.is_tracer);
assert!(!client.is_agent);
Expand Down Expand Up @@ -832,4 +832,27 @@ pub mod tests {
assert_eq!(storage.files.lock().unwrap().len(), 1);
}
}

#[test]
#[cfg_attr(miri, ignore)]
fn test_capability_encoding() {
let state = ConfigFetcherState::<()>::new(ConfigInvariants {
language: "".to_string(),
tracer_version: "".to_string(),
endpoint: Default::default(),
products: vec![],
capabilities: unsafe {
vec![
transmute::<u32, RemoteConfigCapabilities>(1u32),
transmute::<u32, RemoteConfigCapabilities>(24u32),
transmute::<u32, RemoteConfigCapabilities>(31u32),
]
},
});
assert_eq!(state.encoded_capabilities.len(), 4);
assert_eq!(
state.encoded_capabilities,
(2u32 | 1 << 24 | 1 << 31).to_be_bytes()
);
}
}

0 comments on commit 4b0597e

Please sign in to comment.