-
Notifications
You must be signed in to change notification settings - Fork 108
feat(filter): Add a health check filter #2118
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
Merged
Merged
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
737af28
Add skeleton for Healthcheck inbound filter
RaduW 08c7676
Call healthcheck filter
RaduW 5846bbc
fix test build
RaduW 38a052e
fix tests
RaduW 65e048b
add matching logic & tests
RaduW 5181a70
Merge branch 'master' into feat/inbound-filters/health-check
RaduW 81acec2
Update relay-filter/src/health_check.rs
RaduW 9ce6902
Update relay-filter/src/health_check.rs
RaduW d05dd62
Update relay-filter/src/common.rs
RaduW 671dd49
Update relay-filter/src/health_check.rs
RaduW 1ef915b
fixes from code review
RaduW 49ee9e5
Make healthcheck patterns configurable
RaduW 2cdb14f
Merge branch 'master' into feat/inbound-filters/health-check
RaduW 822d6aa
fix changelog
RaduW 0710241
minor cleanup
RaduW 304a637
Merge branch 'master' into feat/inbound-filters/health-check
RaduW 5d589ad
minor, fix comment
RaduW 3282ffe
minor, formatting
RaduW 47b7283
Merge branch 'master' into feat/inbound-filters/health-check
RaduW 3bb58e5
change from health check to transaction name
RaduW 854020c
change from health check to transaction name (rename file)
RaduW de6c9aa
add integration test
RaduW cda65b1
more renaming
RaduW 8376ddd
fix naming on changelog
RaduW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| //! Implements event filtering based on whether the endpoint called is a healthcheck endpoint. | ||
| //! | ||
| //! If this filter is enabled transactions from healthcheck endpoints will be filtered out. | ||
|
|
||
| use relay_general::protocol::Event; | ||
|
|
||
| use crate::{FilterStatKey, GlobPatterns, HealthCheckEndpointsFilterConfig}; | ||
|
|
||
| fn matches(event: &Event, patterns: &GlobPatterns) -> bool { | ||
| event | ||
| .transaction | ||
| .value() | ||
| .map_or(false, |transaction| patterns.is_match(transaction)) | ||
| } | ||
|
|
||
| /// Filters transaction events for calls to healthcheck endpoints | ||
| pub fn should_filter( | ||
| event: &Event, | ||
| config: &HealthCheckEndpointsFilterConfig, | ||
| ) -> Result<(), FilterStatKey> { | ||
| if matches(event, &config.patterns) { | ||
| return Err(FilterStatKey::HealthCheck); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use relay_general::protocol::Event; | ||
| use relay_general::types::Annotated; | ||
|
|
||
| fn _get_patterns() -> GlobPatterns { | ||
| let patterns_raw = vec!["*healthcheck*".into(), "*/health".into()]; | ||
| GlobPatterns::new(patterns_raw) | ||
| } | ||
|
|
||
| /// tests matching for various transactions | ||
| #[test] | ||
| fn test_matches() { | ||
| let patterns = _get_patterns(); | ||
|
|
||
| let transaction_names = [ | ||
| "a/b/healthcheck/c", | ||
| "a_HEALTHCHECK_b", | ||
| "healthcheck", | ||
| "/health", | ||
| "a/HEALTH", | ||
| "/health", | ||
| "a/HEALTH", | ||
| ]; | ||
|
|
||
| for name in transaction_names { | ||
| let event = Event { | ||
| transaction: Annotated::new(name.into()), | ||
| ..Event::default() | ||
| }; | ||
| assert!(matches(&event, &patterns), "Did not match `{name}`") | ||
| } | ||
| } | ||
| /// tests non matching transactions transactions | ||
| #[test] | ||
| fn test_does_not_match() { | ||
| let transaction_names = [ | ||
| "bad", | ||
| "/bad", | ||
| "a/b/c", | ||
| "health", | ||
| "healthz", | ||
| "/health/", | ||
| "/healthz/", | ||
| "/healthx", | ||
| "/healthzx", | ||
| ]; | ||
| let patterns = _get_patterns(); | ||
|
|
||
| for name in transaction_names { | ||
| let event = Event { | ||
| transaction: Annotated::new(name.into()), | ||
| ..Event::default() | ||
| }; | ||
| assert!( | ||
| !matches(&event, &patterns), | ||
| "Did match `{name}` but it shouldn't have." | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // test it doesn't match when the transaction name is missing | ||
| #[test] | ||
| fn test_does_not_match_missing_transaction() { | ||
| let event = Event { ..Event::default() }; | ||
| let patterns = _get_patterns(); | ||
| assert!( | ||
| !matches(&event, &patterns), | ||
| "Did match with empty transaction but it shouldn't have." | ||
| ) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_filters_when_matching() { | ||
| let event = Event { | ||
| transaction: Annotated::new("/health".into()), | ||
| ..Event::default() | ||
| }; | ||
| let config = HealthCheckEndpointsFilterConfig { | ||
| patterns: _get_patterns(), | ||
| }; | ||
|
|
||
| let filter_result = should_filter(&event, &config); | ||
| assert_eq!( | ||
| filter_result, | ||
| Err(FilterStatKey::HealthCheck), | ||
| "Event did not filter health check event" | ||
| ) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_does_not_filter_when_disabled() { | ||
| let event = Event { | ||
| transaction: Annotated::new("/health".into()), | ||
| ..Event::default() | ||
| }; | ||
| let filter_result = should_filter( | ||
| &event, | ||
| &HealthCheckEndpointsFilterConfig { | ||
| patterns: GlobPatterns::new(vec![]), | ||
| }, | ||
| ); | ||
| assert_eq!( | ||
| filter_result, | ||
| Ok(()), | ||
| "Event filtered although filter should have been disabled" | ||
| ) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_does_not_filter_when_not_matching() { | ||
| let event = Event { | ||
| transaction: Annotated::new("/a/b/c".into()), | ||
| ..Event::default() | ||
| }; | ||
| let filter_result = should_filter( | ||
| &event, | ||
| &HealthCheckEndpointsFilterConfig { | ||
| patterns: _get_patterns(), | ||
| }, | ||
| ); | ||
| assert_eq!( | ||
| filter_result, | ||
| Ok(()), | ||
| "Event filtered although filter should have not matched" | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This filter works for any pattern, not just health checks. Could we rename it to reflect it (e.g.
transaction_names)? It's ok if we just use it for health checks, but once we introducehealth_checkwe should keep it for backward compatibility.