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

ref(rules): Move rules DSL to relay-protocol #2608

Merged
merged 4 commits into from
Oct 16, 2023

Conversation

iambriccardo
Copy link
Member

@iambriccardo iambriccardo commented Oct 16, 2023

This PR moves the condition module from relay-sampling to relay-protocol. In order to perform the refactor, an adaptation of tests had to be done, in which dependencies from relay-sampling where removed by adding mock structs that implement Getter.

@iambriccardo iambriccardo marked this pull request as ready for review October 16, 2023 06:59
@iambriccardo iambriccardo requested review from a team and jjbayer October 16, 2023 06:59
Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

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

LGTM! @jan-auer there might be a better place to put the rule-matching logic, but I think putting it in relay-protocol is an improvement over importing relay-samping everywhere.

Comment on lines 23 to 24
use relay_protocol::RuleCondition;
use relay_protocol::{Annotated, Remark};
Copy link
Member

Choose a reason for hiding this comment

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

Let's merge these imports.

@iambriccardo iambriccardo merged commit 4ed7d5f into master Oct 16, 2023
@iambriccardo iambriccardo deleted the riccardo/ref/move-condition branch October 16, 2023 11:22
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.

Please excuse the late review. See the comments below for a follow-up PR.

Eventually, we can look for an even better place for these types; relay-protocol is not the intended crate for this, as it is meant to contain foundational types for building our data schemas, which rule conditions are not part of. That said, I also haven't found the right place yet.

mod value;

pub use self::annotated::*;
pub use self::condition::*;
Copy link
Member

Choose a reason for hiding this comment

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

This module contains a lot of types that usually do not need to be imported. By glob-exporting them, we're littering the global crate namespace as can be seen in the docs now.

When you compare the imports with how relay-sampling was structured, there was an explicit re-export of the RuleCondition type, as this is the most commonly used one, but all the other types were left in a pub mod condition instead. I'd prefer if we do this here, too.

That is independent of whether other modules are glob-exported or not.

pub use self::impls::*;
pub use self::macros::*;
pub use self::meta::*;
pub use self::size::*;
pub use self::traits::*;
pub use self::utils::*;
Copy link
Member

Choose a reason for hiding this comment

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

Definitely do not glob-export internal utils to a public namespace. This file contains the function is_default, which shouldn't be part of the public API of relay-protocol. Instead, we should remove that module and just declare the function locally where needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about this, you are right that it's not good. Definitely needs to be re-worked.

use crate::config::{
DecayingFunction, RuleId, RuleType, SamplingRule, SamplingValue, TimeRange,
};
use crate::dsc::TraceUserContext;
use crate::evaluation::MatchedRuleIds;
use crate::DynamicSamplingContext;
use relay_protocol::RuleCondition;
Copy link
Member

Choose a reason for hiding this comment

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

Please move this import into the import group above.

jjbayer added a commit that referenced this pull request Oct 23, 2023
Follow up to #2608:

* Remove `utils` crate from `relay-protocol`.
* Only export `RuleCondition` from the `condition` module`.

I was not able to remove the `relay-sampling` dependency anywhere yet,
because `relay-cabi` and `relay-dynamic-config` import `SamplingConfig`.
But we will be able to change the dependency in
#2595.
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.

4 participants