Skip to content
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(server): Add inbound filters functionality to dynamic sampling #920

Merged
merged 28 commits into from
Feb 26, 2021

Conversation

RaduW
Copy link
Contributor

@RaduW RaduW commented Feb 5, 2021

Adds dynamic sampling rules to support inbound filters functionality.

Covering the inbound filters functionality with dynamic sampling rules allows us to remove
inbound filters and present the user with only one concept and one configuration interface.

@RaduW RaduW requested a review from a team February 5, 2021 09:19
@RaduW RaduW marked this pull request as draft February 5, 2021 09:19
@RaduW RaduW requested a review from jan-auer February 8, 2021 10:15
beezz and others added 3 commits February 9, 2021 13:28
`parsed.sequence - default_sequence()` is always <= 0
when it is < 0 we get a panic since the value is unsigned (u64)
@RaduW RaduW marked this pull request as ready for review February 11, 2021 12:33
Copy link
Member

@jan-auer jan-auer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review of just the filter changes.

CHANGELOG.md Outdated Show resolved Hide resolved
relay-filter/src/browser_extensions.rs Outdated Show resolved Hide resolved
relay-filter/src/browser_extensions.rs Outdated Show resolved Hide resolved
relay-filter/src/client_ips.rs Outdated Show resolved Hide resolved
relay-filter/src/config.rs Outdated Show resolved Hide resolved
relay-filter/src/csp.rs Outdated Show resolved Hide resolved
relay-general/src/protocol/session.rs Outdated Show resolved Hide resolved
@getsentry getsentry deleted a comment from RaduW Feb 25, 2021
relay-server/src/utils/dynamic_sampling.rs Outdated Show resolved Hide resolved
@@ -127,8 +201,11 @@ impl NotCondition {
fn supported(&self) -> bool {
self.inner.supported()
}
fn matches<T: FieldValueProvider>(&self, value_provider: &T) -> bool {
!self.inner.matches(value_provider)
fn matches_event(&self, event: &Event, ip_addr: Option<IpAddr>) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow-up, let's replace all these ip_addr with RequestMeta:

  • It's to be expected that we require more information about the request
  • ip_addr doesn't specify which IP we want: the socket, the client, how to handle x-forwarded-for? This is what RequestMeta already solves for us.

pub struct CustomCondition {
pub name: String,
#[serde(default)]
pub value: Value,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have generic options, why do we need value here?

For a follow-up: It would be interesting to type out the custom conditions, since they are statically known in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to have a consistent structure that matches with the non custom operators.
For example:

{ "name": "event.releases", "op": "glob", "value": ["v1.1", "v2.*"]},
{ "name": "event.legacy_browsers", "op":"custom", "value":["ie8", "ie9"]},

The options are supposed to be used for configuring the operator (something like the ignore_case from operator eq ).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. Once these are typed out it certainly looks better again. Let's keep like this, then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On another thought: It seems odd that we have options but name and value special cased on the top, once everything is typed out. We can address this when typing out, though.

/// returns a match result
fn get_custom_operator(
name: &str,
) -> fn(condition: &CustomCondition, slf: &Self, ip_addr: Option<IpAddr>) -> bool;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably also for a follow-up: Can we make it so that the Field provider inherently has access to the ip_addr (or, better, the entire RequestMeta)? We could implement the trait on a type like this:

struct EventValueProvider<'a> {
  event: &'a Annotated<Event>,
  meta: &'a RequestMeta,
}

/// returns a match result
fn get_custom_operator(
name: &str,
) -> fn(condition: &CustomCondition, slf: &Self, ip_addr: Option<IpAddr>) -> bool;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Why not just run the custom condition inside the function?

fn match_custom(&self, condition: &CustomCondition, ip_addr: Option<IpAddr>) -> bool;

For a follow-up: Later down the road we need to refactor the value provider so that it can expose all fields needed by the custom rules via its get_value interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that, it seemed wrong though.
The ValueProvider gives you information from the Event or Trace but doesn't also run
rules, anyway not feeling too strongly either way.
The presence of the custom operation in ValueProvider makes it quite a messy abstraction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate from this PR, could you compile a list of all attributes that we need access to for running the custom matchers?

@RaduW RaduW requested a review from jan-auer February 25, 2021 16:00
relay-server/src/utils/dynamic_sampling.rs Outdated Show resolved Hide resolved
}
}

#[test]
/// test matching for various rules
fn test_matches_events() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow-up, I would like to move all these tests to macro-based expansion. That way, each test runs in its own test function and we can see individual failures more easily.

We could also start adopting a test parameterization framework, but I'm still not convinced of that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I like the idea in principle it would make debugging difficult/impossible and I like to have this option open.
I've been looking, a while back now, for a clean way to do parameterization of unit tests in Rust but all I found were frameworks that either used nightly builds or used some ugly macros.

If we can find a relatively clean way to do it while still being able to run a debugger I all for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can run and debug tests defined in macros just like any other test. Rust Analyzer even provides code lenses for debugging individual tests, for example as we do in relay-general/tests/test_fixtures.rs:

image

@RaduW RaduW merged commit 4b32791 into master Feb 26, 2021
@RaduW RaduW deleted the feat/dyn-sampling-filters branch February 26, 2021 09:41
jan-auer added a commit that referenced this pull request Feb 26, 2021
* master: (23 commits)
  feat(server): Add inbound filters functionality to dynamic sampling (#920)
  fix rule generation to new format (in tests) (#939)
  ref: Remove actix-web client, make reqwest the new http client (#938)
  fix(server): Reject empty envelopes with an explicit error (#937)
  fix(server): Ensure outcome data categories are numeric (#936)
  feat(stats): Add data category to TrackOutcome (#931)
  fix(pii): Make username pii-strippable (#935)
  build: Bump symbolic to 8.0.4 (#899)
  fix: Update to tokio 1.0 (#909)
  fix(pii): Make and/or work correctly with pii=maybe (#932)
  release: 21.2.0
  release: 0.8.3
  fix(build): Fix path to 3.7 (#930)
  build: drop python 2.7 support (#929)
  feat(protocol): Add snapshot to the stack trace interface (#927)
  test: Improve integration tests to reduce flakyness (#928)
  fix: Ignore false-positive lints from Clippy 1.50 (#926)
  feat(protocol): Add NSError to mechanism (#925)
  meta: Fix changelog
  meta(readme): Document development config for processing mode (#921)
  ...
jan-auer added a commit that referenced this pull request Feb 26, 2021
* master: (42 commits)
  build: Switch to vendored openssl build (#914)
  feat(server): Add inbound filters functionality to dynamic sampling (#920)
  fix rule generation to new format (in tests) (#939)
  ref: Remove actix-web client, make reqwest the new http client (#938)
  fix(server): Reject empty envelopes with an explicit error (#937)
  fix(server): Ensure outcome data categories are numeric (#936)
  feat(stats): Add data category to TrackOutcome (#931)
  fix(pii): Make username pii-strippable (#935)
  build: Bump symbolic to 8.0.4 (#899)
  fix: Update to tokio 1.0 (#909)
  fix(pii): Make and/or work correctly with pii=maybe (#932)
  release: 21.2.0
  release: 0.8.3
  fix(build): Fix path to 3.7 (#930)
  build: drop python 2.7 support (#929)
  feat(protocol): Add snapshot to the stack trace interface (#927)
  test: Improve integration tests to reduce flakyness (#928)
  fix: Ignore false-positive lints from Clippy 1.50 (#926)
  feat(protocol): Add NSError to mechanism (#925)
  meta: Fix changelog
  ...
jan-auer added a commit that referenced this pull request Feb 26, 2021
* master: (120 commits)
  fix(protocol): Deny backslashes in release names (#904)
  ref(server): Extract dynamic sampling functionality into own crate (#940)
  build: Switch to vendored openssl build (#914)
  feat(server): Add inbound filters functionality to dynamic sampling (#920)
  fix rule generation to new format (in tests) (#939)
  ref: Remove actix-web client, make reqwest the new http client (#938)
  fix(server): Reject empty envelopes with an explicit error (#937)
  fix(server): Ensure outcome data categories are numeric (#936)
  feat(stats): Add data category to TrackOutcome (#931)
  fix(pii): Make username pii-strippable (#935)
  build: Bump symbolic to 8.0.4 (#899)
  fix: Update to tokio 1.0 (#909)
  fix(pii): Make and/or work correctly with pii=maybe (#932)
  release: 21.2.0
  release: 0.8.3
  fix(build): Fix path to 3.7 (#930)
  build: drop python 2.7 support (#929)
  feat(protocol): Add snapshot to the stack trace interface (#927)
  test: Improve integration tests to reduce flakyness (#928)
  fix: Ignore false-positive lints from Clippy 1.50 (#926)
  ...
jan-auer added a commit that referenced this pull request Feb 26, 2021
* master:
  test(general): Introduce macros for traversing Annotated (#826)
  fix(protocol): Deny backslashes in release names (#904)
  ref(server): Extract dynamic sampling functionality into own crate (#940)
  build: Switch to vendored openssl build (#914)
  feat(server): Add inbound filters functionality to dynamic sampling (#920)
  fix rule generation to new format (in tests) (#939)
  ref: Remove actix-web client, make reqwest the new http client (#938)
  fix(server): Reject empty envelopes with an explicit error (#937)
  fix(server): Ensure outcome data categories are numeric (#936)
  feat(stats): Add data category to TrackOutcome (#931)
  fix(pii): Make username pii-strippable (#935)
  build: Bump symbolic to 8.0.4 (#899)
  fix: Update to tokio 1.0 (#909)
  fix(pii): Make and/or work correctly with pii=maybe (#932)
  release: 21.2.0
  release: 0.8.3
  fix(build): Fix path to 3.7 (#930)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants