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 and condition is not. In that case:
    • If is_enabled is true, the filter with a matching ID from global configs is yielded without evaluating its is_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.

§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§

source§

impl GenericFiltersConfig

source

pub fn is_empty(&self) -> bool

Returns true if the filters are not declared.

Trait Implementations§

source§

impl Clone for GenericFiltersConfig

source§

fn clone(&self) -> GenericFiltersConfig

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for GenericFiltersConfig

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for GenericFiltersConfig

source§

fn default() -> GenericFiltersConfig

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for GenericFiltersConfig

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for GenericFiltersConfig

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,