Skip to content

Commit

Permalink
ref(pattern): Replace glob3 with typed patterns (#4124)
Browse files Browse the repository at this point in the history
Removes glob3 and replaces all usage with
`TypedPattern<CaseInsensitive>`, except for the metric matchers, those
are now case sensitive, MRIs should be matched specifically. There is no
other change in behaviour, since glob3 already used `relay-pattern`
internally.
  • Loading branch information
Dav1dde authored Oct 9, 2024
1 parent 4b58953 commit 0f88b37
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 256 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

184 changes: 0 additions & 184 deletions relay-common/src/glob3.rs

This file was deleted.

1 change: 0 additions & 1 deletion relay-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
mod macros;

pub mod glob2;
pub mod glob3;
pub mod time;

pub use sentry_types::{Auth, Dsn, ParseAuthError, ParseDsnError, Scheme};
1 change: 1 addition & 0 deletions relay-dynamic-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ relay-common = { workspace = true }
relay-event-normalization = { workspace = true }
relay-filter = { workspace = true }
relay-log = { workspace = true }
relay-pattern = { workspace = true }
relay-pii = { workspace = true }
relay-protocol = { workspace = true }
relay-quotas = { workspace = true }
Expand Down
13 changes: 8 additions & 5 deletions relay-dynamic-config/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::str::FromStr;
use relay_base_schema::data_category::DataCategory;
use relay_cardinality::CardinalityLimit;
use relay_common::glob2::LazyGlob;
use relay_common::glob3::GlobPatterns;
use relay_common::impl_str_serde;
use relay_pattern::{Patterns, TypedPatterns};
use relay_protocol::RuleCondition;
use serde::{Deserialize, Serialize};

Expand All @@ -23,8 +23,8 @@ pub struct Metrics {
#[serde(skip_serializing_if = "Vec::is_empty")]
pub cardinality_limits: Vec<CardinalityLimit>,
/// List of patterns for blocking metrics based on their name.
#[serde(skip_serializing_if = "GlobPatterns::is_empty")]
pub denied_names: GlobPatterns,
#[serde(skip_serializing_if = "Patterns::is_empty")]
pub denied_names: TypedPatterns,
/// Configuration for removing tags from a bucket.
///
/// Note that removing tags does not drop the overall metric bucket.
Expand All @@ -43,11 +43,14 @@ impl Metrics {

/// Configuration for removing tags matching the `tag` pattern on metrics whose name matches the `name` pattern.
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
#[serde(default)]
pub struct TagBlock {
/// Name of metric of which we want to remove certain tags.
pub name: GlobPatterns,
#[serde(skip_serializing_if = "Patterns::is_empty")]
pub name: TypedPatterns,
/// Pattern to match keys of tags that we want to remove.
pub tags: GlobPatterns,
#[serde(skip_serializing_if = "Patterns::is_empty")]
pub tags: TypedPatterns,
}

/// Rule defining when a target tag should be set on a metric.
Expand Down
1 change: 1 addition & 0 deletions relay-filter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ once_cell = { workspace = true }
indexmap = { workspace = true }
regex = { workspace = true }
relay-common = { workspace = true }
relay-pattern = { workspace = true }
relay-event-schema = { workspace = true }
relay-protocol = { workspace = true }
relay-ua = { workspace = true }
Expand Down
16 changes: 8 additions & 8 deletions relay-filter/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::ops::Deref;
use std::str::FromStr;

use indexmap::IndexMap;
use relay_common::glob3::GlobPatterns;
use relay_pattern::{CaseInsensitive, TypedPatterns};
use relay_protocol::RuleCondition;
use serde::ser::SerializeSeq;
use serde::{de, Deserialize, Serialize, Serializer};
Expand Down Expand Up @@ -173,15 +173,15 @@ impl CspFilterConfig {
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct ErrorMessagesFilterConfig {
/// List of error message patterns that will be filtered.
pub patterns: GlobPatterns,
pub patterns: TypedPatterns<CaseInsensitive>,
}

/// Configuration for transaction name filter.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IgnoreTransactionsFilterConfig {
/// List of patterns for ignored transactions that should be filtered.
pub patterns: GlobPatterns,
pub patterns: TypedPatterns<CaseInsensitive>,
/// True if the filter is enabled
#[serde(default)]
pub is_enabled: bool,
Expand All @@ -205,7 +205,7 @@ impl ErrorMessagesFilterConfig {
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct ReleasesFilterConfig {
/// List of release names that will be filtered.
pub releases: GlobPatterns,
pub releases: TypedPatterns<CaseInsensitive>,
}

impl ReleasesFilterConfig {
Expand Down Expand Up @@ -632,7 +632,7 @@ mod tests {
disallowed_sources: vec!["https://*".to_string()],
},
error_messages: ErrorMessagesFilterConfig {
patterns: GlobPatterns::new(vec!["Panic".to_string()]),
patterns: TypedPatterns::from(["Panic".to_owned()]),
},
legacy_browsers: LegacyBrowsersFilterConfig {
is_enabled: false,
Expand All @@ -643,16 +643,16 @@ mod tests {
},
localhost: FilterConfig { is_enabled: true },
releases: ReleasesFilterConfig {
releases: GlobPatterns::new(vec!["1.2.3".to_string()]),
releases: TypedPatterns::from(["1.2.3".to_owned()]),
},
ignore_transactions: IgnoreTransactionsFilterConfig {
patterns: GlobPatterns::new(vec!["*health*".to_string()]),
patterns: TypedPatterns::from(["*health*".to_owned()]),
is_enabled: true,
},
generic: GenericFiltersConfig {
version: 1,
filters: vec![GenericFilterConfig {
id: "hydrationError".to_string(),
id: "hydrationError".to_owned(),
is_enabled: true,
condition: Some(RuleCondition::eq("event.exceptions", "HydrationError")),
}]
Expand Down
Loading

0 comments on commit 0f88b37

Please sign in to comment.