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(protocol): Support comparisons in rule conditions on strings #2730

Merged
merged 11 commits into from
Nov 16, 2023
Next Next commit
feat(protocol): Support comparisons in rule conditions on strings
  • Loading branch information
jan-auer committed Nov 14, 2023
commit 6aedc4f3b1e864e651ece914cf55f03db2145bc9
17 changes: 10 additions & 7 deletions relay-protocol/src/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use relay_common::glob3::GlobPatterns;
use serde::{Deserialize, Serialize};
use serde_json::{Number, Value};
use serde_json::Value;

use crate::{Getter, Val};

Expand Down Expand Up @@ -106,12 +106,12 @@ macro_rules! impl_cmp_condition {
/// Path of the field that should match the value.
pub name: String,
/// The numeric value to check against.
pub value: Number,
pub value: Value,
}

impl $struct_name {
/// Creates a new condition that comparison condition.
pub fn new(field: impl Into<String>, value: impl Into<Number>) -> Self {
pub fn new(field: impl Into<String>, value: impl Into<Value>) -> Self {
Self {
name: field.into(),
value: value.into(),
Expand All @@ -136,6 +136,8 @@ macro_rules! impl_cmp_condition {
a $operator b
} else if let (Some(a), Some(b)) = (value.as_f64(), self.value.as_f64()) {
a $operator b
} else if let (Some(a), Some(b)) = (value.as_str(), self.value.as_str()) {
a $operator b
} else {
false
}
Expand Down Expand Up @@ -527,7 +529,7 @@ impl RuleCondition {
///
/// let condition = RuleCondition::gt("obj.length", 10);
/// ```
pub fn gt(field: impl Into<String>, value: impl Into<Number>) -> Self {
pub fn gt(field: impl Into<String>, value: impl Into<Value>) -> Self {
Self::Gt(GtCondition::new(field, value))
}

Expand All @@ -540,7 +542,7 @@ impl RuleCondition {
///
/// let condition = RuleCondition::gte("obj.length", 10);
/// ```
pub fn gte(field: impl Into<String>, value: impl Into<Number>) -> Self {
pub fn gte(field: impl Into<String>, value: impl Into<Value>) -> Self {
Self::Gte(GteCondition::new(field, value))
}

Expand All @@ -553,7 +555,7 @@ impl RuleCondition {
///
/// let condition = RuleCondition::lt("obj.length", 10);
/// ```
pub fn lt(field: impl Into<String>, value: impl Into<Number>) -> Self {
pub fn lt(field: impl Into<String>, value: impl Into<Value>) -> Self {
Self::Lt(LtCondition::new(field, value))
}

Expand All @@ -566,7 +568,7 @@ impl RuleCondition {
///
/// let condition = RuleCondition::lte("obj.length", 10);
/// ```
pub fn lte(field: impl Into<String>, value: impl Into<Number>) -> Self {
pub fn lte(field: impl Into<String>, value: impl Into<Value>) -> Self {
Self::Lte(LteCondition::new(field, value))
}

Expand Down Expand Up @@ -934,6 +936,7 @@ mod tests {
& RuleCondition::eq_ignore_case("trace.user.segment", "vip"),
),
("match no conditions", RuleCondition::all()),
("string cmp", RuleCondition::gt("trace.transaction", "t")),
];

let dsc = mock_dsc();
Expand Down
Loading