Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the correct format for capability submission #665

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 / 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()
);
}
}
Loading