Skip to content

Commit

Permalink
Update user-agent on express cache usage (#1122)
Browse files Browse the repository at this point in the history
## Description of change

Add `mp-cache-express` to the user agent when caching in express is
enabled.

Relevant issues: N/A

## Does this change impact existing behavior?

No.

## Does this change need a changelog entry in any of the crates?

No.

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and I agree to the terms of
the [Developer Certificate of Origin
(DCO)](https://developercertificate.org/).

---------

Signed-off-by: Vlad Volodkin <[email protected]>
Co-authored-by: Vlad Volodkin <[email protected]>
  • Loading branch information
vladem and Vlad Volodkin authored Nov 18, 2024
1 parent 7198bc8 commit 1e30bff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
16 changes: 16 additions & 0 deletions mountpoint-s3-client/src/user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ impl UserAgent {
self
}

/// Add a key-value metadata field to the header with multiple values
pub fn key_values(&mut self, key: &str, values: &[&str]) -> &mut Self {
let value = values.join("+");
self.fields
.push(format!("md/{}#{}", sanitize_string(key), sanitize_string(value)));
self
}

/// Add a value-only metadata field to the header
pub fn value(&mut self, value: &str) -> &mut Self {
self.fields.push(format!("md/{}", sanitize_string(value)));
Expand Down Expand Up @@ -164,4 +172,12 @@ mod tests {
"Java_HotSpot_-TM-_64-Bit_Server_VM"
);
}

#[test]
fn test_multiple_values() {
let mut user_agent = UserAgent::new(None);
user_agent.key_values("mp-cache", &["shared", "local"]);
let user_agent_string = user_agent.build();
assert!(user_agent_string.contains("md/mp-cache#shared+local"));
}
}
13 changes: 11 additions & 2 deletions mountpoint-s3/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,17 @@ pub fn create_s3_client(args: &CliArgs) -> anyhow::Result<(S3CrtClient, EventLoo
user_agent.value("mp-readonly");
}

if args.cache.is_some() {
user_agent.value("mp-cache");
match (&args.cache, args.cache_express_bucket_name()) {
(None, None) => (),
(None, Some(_)) => {
user_agent.key_value("mp-cache", "shared");
}
(Some(_), None) => {
user_agent.key_value("mp-cache", "local");
}
(Some(_), Some(_)) => {
user_agent.key_values("mp-cache", &["shared", "local"]);
}
}
if let Some(ttl) = args.metadata_ttl {
user_agent.key_value("mp-cache-ttl", &ttl.to_string());
Expand Down

0 comments on commit 1e30bff

Please sign in to comment.