Struct relay_filter::GenericFiltersConfig
source · pub struct GenericFiltersConfig {
pub version: u16,
pub filters: GenericFiltersMap,
}
Expand description
Configuration for generic filters.
§Deserialization
filters
is expected to be a sequence of GenericFilterConfig
.
Only the first occurrence of a filter is kept, and duplicates are removed.
Two filters are considered duplicates if they have the same ID,
independently of the condition.
The list of filters is deserialized into an GenericFiltersMap
, where the
key is the filter’s id and the value is the filter itself. The map is
converted back to a list when serializing it, without the filters that were
discarded as duplicates. See examples below.
§Iterator
Iterates in order through the generic filters in project configs and global configs yielding the filters according to the principles below:
- Filters from project configs are evaluated before filters from global configs.
- No duplicates: once a filter is evaluated (yielded or skipped), no filter with the same id is evaluated again.
- Filters in project configs override filters from global configs, but the opposite is never the case.
- A filter in the project config can be a flag, where only
is_enabled
is defined andcondition
is not. In that case:- If
is_enabled
is true, the filter with a matching ID from global configs is yielded without evaluating itsis_enabled
. Unless the filter in the global config also has an empty condition, in which case the filter is not yielded. - If
is_enabled
is false, no filters with the same IDs are returned, including matching filters from global configs.
- If
§Examples
Deserialization:
let json = r#"{
"version": 1,
"filters": [
{
"id": "filter1",
"isEnabled": false,
"condition": null
},
{
"id": "filter1",
"isEnabled": true,
"condition": {
"op": "eq",
"name": "event.exceptions",
"value": "drop-error"
}
}
]
}"#;
let deserialized = serde_json::from_str::<GenericFiltersConfig>(json).unwrap();
assert_debug_snapshot!(deserialized, @r#"
GenericFiltersConfig {
version: 1,
filters: GenericFiltersMap(
{
"filter1": GenericFilterConfig {
id: "filter1",
is_enabled: false,
condition: None,
},
},
),
}
"#);
Deserialization of no filters defaults to an empty map:
let json = r#"{
"version": 1
}"#;
let deserialized = serde_json::from_str::<GenericFiltersConfig>(json).unwrap();
assert_debug_snapshot!(deserialized, @r#"
GenericFiltersConfig {
version: 1,
filters: GenericFiltersMap(
{},
),
}
"#);
Serialization:
let filter = GenericFiltersConfig {
version: 1,
filters: vec![
GenericFilterConfig {
id: "filter1".to_owned(),
is_enabled: true,
condition: Some(RuleCondition::eq("event.exceptions", "drop-error")),
},
].into(),
};
let serialized = serde_json::to_string_pretty(&filter).unwrap();
assert_display_snapshot!(serialized, @r#"{
"version": 1,
"filters": [
{
"id": "filter1",
"isEnabled": true,
"condition": {
"op": "eq",
"name": "event.exceptions",
"value": "drop-error"
}
}
]
}"#);
Serialization of filters is skipped if there aren’t any:
let filter = GenericFiltersConfig {
version: 1,
filters: GenericFiltersMap::new(),
};
let serialized = serde_json::to_string_pretty(&filter).unwrap();
assert_display_snapshot!(serialized, @r#"{
"version": 1
}"#);
Fields§
§version: u16
Version of the filters configuration.
filters: GenericFiltersMap
Map of generic filters, sorted by the order in the payload from upstream.
The map contains unique filters, meaning there are no two filters with the same id. See struct docs for more details.
Implementations§
Trait Implementations§
source§impl Clone for GenericFiltersConfig
impl Clone for GenericFiltersConfig
source§fn clone(&self) -> GenericFiltersConfig
fn clone(&self) -> GenericFiltersConfig
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for GenericFiltersConfig
impl Debug for GenericFiltersConfig
source§impl Default for GenericFiltersConfig
impl Default for GenericFiltersConfig
source§fn default() -> GenericFiltersConfig
fn default() -> GenericFiltersConfig
source§impl<'de> Deserialize<'de> for GenericFiltersConfig
impl<'de> Deserialize<'de> for GenericFiltersConfig
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for GenericFiltersConfig
impl RefUnwindSafe for GenericFiltersConfig
impl Send for GenericFiltersConfig
impl Sync for GenericFiltersConfig
impl Unpin for GenericFiltersConfig
impl UnwindSafe for GenericFiltersConfig
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)