From 289687928a0bea04df31f76db783548b62cd8af6 Mon Sep 17 00:00:00 2001 From: Kevin Guthrie Date: Thu, 26 Sep 2024 16:49:09 -0400 Subject: Add a warning log if the dictionary for `HeaderSerde` is `None` --- .bleep | 2 +- pingora-cache/src/meta.rs | 15 +++++++++++++-- pingora-header-serde/src/dict.rs | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/.bleep b/.bleep index fccd5bf..7696a90 100644 --- a/.bleep +++ b/.bleep @@ -1 +1 @@ -735c778b671dcfcbe0b561cc0bbbf0f000e457f6 \ No newline at end of file +aa7c01c0f1c7a33d4ec55cf3531997e4cb2542ab \ No newline at end of file diff --git a/pingora-cache/src/meta.rs b/pingora-cache/src/meta.rs index 206b320..8ed034e 100644 --- a/pingora-cache/src/meta.rs +++ b/pingora-cache/src/meta.rs @@ -595,8 +595,19 @@ fn load_file(path: &String) -> Option> { } static HEADER_SERDE: Lazy = Lazy::new(|| { - let dict = COMPRESSION_DICT_PATH.get().and_then(load_file); - HeaderSerde::new(dict) + let dict_path_opt = COMPRESSION_DICT_PATH.get(); + + if dict_path_opt.is_none() { + warn!("COMPRESSION_DICT_PATH is not set"); + } + + let result = dict_path_opt.and_then(load_file); + + if result.is_none() { + warn!("HeaderSerde not loaded from file"); + } + + HeaderSerde::new(result) }); pub(crate) fn header_serialize(header: &ResponseHeader) -> Result> { diff --git a/pingora-header-serde/src/dict.rs b/pingora-header-serde/src/dict.rs index bc50ada..71a85b6 100644 --- a/pingora-header-serde/src/dict.rs +++ b/pingora-header-serde/src/dict.rs @@ -73,6 +73,23 @@ mod test { assert!(compressed.len() < compressed_no_dict.len()); } + #[test] + fn test_deserialize_with_dict() { + let dict = gen_test_dict(); + let serde = crate::HeaderSerde::new(Some(dict)); + let serde_no_dict = crate::HeaderSerde::new(None); + let header = gen_test_header(); + + let compressed = serde.serialize(&header).unwrap(); + let compressed_no_dict = serde_no_dict.serialize(&header).unwrap(); + + let from_dict_header = serde.deserialize(&compressed).unwrap(); + let from_no_dict_header = serde_no_dict.deserialize(&compressed_no_dict).unwrap(); + + assert_eq!(from_dict_header.status, from_no_dict_header.status); + assert_eq!(from_dict_header.headers, from_no_dict_header.headers); + } + #[test] fn test_ser_de_with_dict() { let dict = gen_test_dict(); -- cgit v1.2.3