From e4c2713dc6a05babd1794ded8ddd74efb1e5033c Mon Sep 17 00:00:00 2001 From: Alex Chi Date: Thu, 1 Jun 2023 13:56:44 -0400 Subject: [PATCH] fix eviction policy parsing Signed-off-by: Alex Chi --- libs/pageserver_api/src/models.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libs/pageserver_api/src/models.rs b/libs/pageserver_api/src/models.rs index 227525bf4d..dc74cecea7 100644 --- a/libs/pageserver_api/src/models.rs +++ b/libs/pageserver_api/src/models.rs @@ -235,7 +235,7 @@ pub struct TenantConfig { // Otherwise we'd have to move the types for eviction policy into this package. // We might do that once the eviction feature has stabilizied. // For now, this field is not even documented in the openapi_spec.yml. - #[clap(long, value_parser = clap::value_parser!(serde_json::Value))] + #[clap(long, value_parser = parse_json)] pub eviction_policy: Option, #[clap(long)] pub min_resident_size_override: Option, @@ -244,6 +244,10 @@ pub struct TenantConfig { pub gc_feedback: Option, } +fn parse_json(s: &str) -> Result { + serde_json::from_str(s) +} + impl TenantConfig { pub fn deserialize_from_settings(settings: HashMap<&str, &str>) -> Result { let config = TenantConfig::try_parse_from( @@ -928,6 +932,15 @@ mod tests { ); } + #[test] + fn test_parse_json_field() { + let config = vec![( + "eviction_policy", + "eviction_policy:{\"kind\": \"NoEviction\"}", + )]; + TenantConfig::deserialize_from_settings(config.into_iter().collect()).unwrap(); + } + #[test] fn tenantstatus_activating_serde() { let states = [