in nfm-controller/src/reports/publisher_endpoint.rs [519:565]
fn run_compression_test(num_flows: usize, address_family: i32, include_k8s: bool) {
let publisher_with_compression = build_publisher(ReportCompression::Gzip);
let publisher_no_compression = build_publisher(ReportCompression::None);
let report = build_report(num_flows, address_family, include_k8s);
let body_no_compression = publisher_no_compression.build_report_body(&report);
let body_with_compression = publisher_with_compression.build_report_body(&report);
// Aiming for a min 50% compression ratio.
assert!((body_no_compression.len() / 2) > body_with_compression.len());
assert_eq!(
body_no_compression,
decompress(ReportCompression::Gzip, &body_with_compression)
);
// Store files for external validation.
let addr_type = match address_family {
AF_INET => "ipv4",
AF_INET6 => "ipv6",
_ => panic!("Unknown addr family: {}", address_family),
};
let compute_type = if include_k8s { "k8s" } else { "ec2" };
let json_string = serde_json::to_string(&report).unwrap();
std::fs::create_dir_all("../target/report-samples/").unwrap();
store_sample_file(
format!(
"report-{}-{}-{}-flows.json",
num_flows, addr_type, compute_type
),
json_string.as_bytes(),
);
store_sample_file(
format!(
"report-{}-{}-{}-flows.bin",
num_flows, addr_type, compute_type
),
&body_no_compression,
);
store_sample_file(
format!(
"report-{}-{}-{}-flows.bin.gz",
num_flows, addr_type, compute_type
),
&body_with_compression,
);
}