Unverified Commit fed53137 authored by Keiven C's avatar Keiven C Committed by GitHub
Browse files

fix: metrics test to match actual namespace sanitization behavior (#2868)


Signed-off-by: default avatarKeiven Chang <keivenchang@users.noreply.github.com>
parent 8543d0d3
...@@ -879,12 +879,21 @@ mod test_metricsregistry_prefixes { ...@@ -879,12 +879,21 @@ mod test_metricsregistry_prefixes {
assert_eq!(component.parent_hierarchy().len(), 2); assert_eq!(component.parent_hierarchy().len(), 2);
assert_eq!(endpoint.parent_hierarchy().len(), 3); assert_eq!(endpoint.parent_hierarchy().len(), 3);
// Invalid namespace behavior (sanitization should still error after becoming "123") // Invalid namespace behavior - sanitizes to "_123" and succeeds
// @ryanolson intended to enable validation (see TODO comment in component.rs) but didn't turn it on,
// so invalid characters are sanitized in MetricsRegistry rather than rejected.
let invalid_namespace = drt.namespace("@@123").unwrap(); let invalid_namespace = drt.namespace("@@123").unwrap();
let result = invalid_namespace.create_counter("test_counter", "A test counter", &[]); let result = invalid_namespace.create_counter("test_counter", "A test counter", &[]);
assert!(result.is_err()); assert!(result.is_ok());
if let Err(e) = &result { if let Ok(counter) = &result {
assert!(e.to_string().contains("123")); // Verify the namespace was sanitized to "_123" in the label
let desc = counter.desc();
let namespace_label = desc[0]
.const_label_pairs
.iter()
.find(|l| l.name() == "dynamo_namespace")
.expect("Should have dynamo_namespace label");
assert_eq!(namespace_label.value(), "_123");
} }
// Valid namespace works // Valid namespace works
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment