-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Extract normalized dist as metric [INGEST-335] #1158
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,22 @@ fn is_valid_platform(platform: &str) -> bool { | |
VALID_PLATFORMS.contains(&platform) | ||
} | ||
|
||
pub fn normalize_dist(dist: &mut Option<String>) { | ||
let mut erase = false; | ||
if let Some(val) = dist { | ||
if val.is_empty() { | ||
erase = true; | ||
} | ||
let trimmed = val.trim(); | ||
if trimmed != val { | ||
*val = trimmed.to_string() | ||
} | ||
} | ||
if erase { | ||
*dist = None; | ||
} | ||
} | ||
|
||
/// The processor that normalizes events for store. | ||
pub struct NormalizeProcessor<'a> { | ||
config: Arc<StoreConfig>, | ||
|
@@ -120,15 +136,7 @@ impl<'a> NormalizeProcessor<'a> { | |
|
||
/// Ensures that the `release` and `dist` fields match up. | ||
fn normalize_release_dist(&self, event: &mut Event) { | ||
if event.dist.value().is_some() && event.release.value().is_empty() { | ||
event.dist.set_value(None); | ||
} | ||
|
||
if let Some(dist) = event.dist.value_mut() { | ||
if dist.trim() != dist { | ||
*dist = dist.trim().to_string(); | ||
} | ||
} | ||
normalize_dist(event.dist.value_mut()); | ||
} | ||
|
||
/// Validates the timestamp range and sets a default value. | ||
|
@@ -1600,3 +1608,31 @@ fn test_past_timestamp() { | |
} | ||
"###); | ||
} | ||
|
||
#[test] | ||
fn test_normalize_dist_none() { | ||
let mut dist = None; | ||
normalize_dist(&mut dist); | ||
assert_eq!(dist, None); | ||
} | ||
|
||
#[test] | ||
fn test_normalize_dist_empty() { | ||
let mut dist = Option::Some("".to_owned()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my prev code suggestion goes for all testcases here fwiw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I did the lazy thing and pressed "Commit suggestion". Will change other instances as well. |
||
normalize_dist(&mut dist); | ||
assert_eq!(dist, None); | ||
} | ||
|
||
#[test] | ||
fn test_normalize_dist_trim() { | ||
let mut dist = Option::Some(" foo ".to_owned()); | ||
normalize_dist(&mut dist); | ||
assert_eq!(dist.unwrap(), "foo"); | ||
} | ||
|
||
#[test] | ||
fn test_normalize_dist_whitespace() { | ||
let mut dist = Option::Some(" ".to_owned()); | ||
normalize_dist(&mut dist); | ||
assert_eq!(dist.unwrap(), ""); // Not sure if this is what we want | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the erase flag here because I cannot set
dist
while checking its contents. I don't like it though - any suggestions welcome.