Match

The Match filter's job is to provide a mechanism to change behaviour based on dynamic metadata. This filter behaves similarly to the match expression in Rust or switch statements in other languages.

Filter name

quilkin.filters.match.v1alpha1.Match

Configuration Examples


#![allow(unused)]
fn main() {
let yaml = "
version: v1alpha1
static:
  endpoints:
    - address: 127.0.0.1:26000
    - address: 127.0.0.1:26001
  filters:
    - name: quilkin.filters.capture_bytes.v1alpha1.CaptureBytes
      config:
          strategy: PREFIX
          metadataKey: myapp.com/token
          size: 3
          remove: false
    - name: quilkin.filters.match.v1alpha1.Match
      config:
          on_read:
            metadataKey: myapp.com/token
            branches:
                - value: abc
                  filter: quilkin.filters.pass.v1alpha1.Pass
            fallthrough: quilkin.filters.drop.v1alpha1.Drop
";
let config = quilkin::config::Config::from_reader(yaml.as_bytes()).unwrap();
assert_eq!(config.source.get_static_filters().unwrap().len(), 2);
quilkin::Builder::from(std::sync::Arc::new(config)).validate().unwrap();
}

Configuration Options (Rust Doc)

---
$schema: "http://json-schema.org/draft-07/schema#"
title: Config
description: "Configuration for the [`factory`][crate::filters::match::factory]."
type: object
properties:
  on_read:
    description: "Configuration for [`Filter::read`][crate::filters::Filter::read]."
    anyOf:
      - $ref: "#/definitions/DirectionalConfig"
      - type: "null"
  on_write:
    description: "Configuration for [`Filter::write`][crate::filters::Filter::write]."
    anyOf:
      - $ref: "#/definitions/DirectionalConfig"
      - type: "null"
additionalProperties: false
definitions:
  Branch:
    description: "A specific match branch. The filter is run when `value` matches the value defined in `metadata_key`."
    type: object
    required:
      - id
      - value
    properties:
      config:
        description: "The configuration for the filter to run, if any."
        anyOf:
          - $ref: "#/definitions/ConfigType"
          - type: "null"
      id:
        description: The identifier for the filter to run.
        type: string
      value:
        description: The value to compare against the dynamic metadata.
        allOf:
          - $ref: "#/definitions/Value"
  ConfigType:
    description: "The configuration of a [`Filter`][crate::filters::Filter] from either a static or dynamic source."
    oneOf:
      - description: Static configuration from YAML.
        type: object
        required:
          - Static
        properties:
          Static: true
        additionalProperties: false
  DirectionalConfig:
    description: Configuration for a specific direction.
    type: object
    required:
      - branches
      - metadataKey
    properties:
      branches:
        description: List of filters to compare and potentially run if any match.
        type: array
        items:
          $ref: "#/definitions/Branch"
      fallthrough:
        description: "The behaviour for when none of the `branches` match."
        default:
          config: ~
          id: quilkin.filters.drop.v1alpha1.Drop
        allOf:
          - $ref: "#/definitions/Filter"
      metadataKey:
        description: The key for the metadata to compare against.
        type: string
  Filter:
    type: object
    required:
      - id
    properties:
      config:
        description: "The configuration for the filter to run, if any."
        anyOf:
          - $ref: "#/definitions/ConfigType"
          - type: "null"
      id:
        description: The identifier for the filter to run.
        type: string
  Value:
    anyOf:
      - type: boolean
      - type: integer
        format: uint64
        minimum: 0.0
      - type: array
        items:
          $ref: "#/definitions/Value"
      - type: string
      - type: array
        items:
          type: integer
          format: uint8
          minimum: 0.0

View the Match filter documentation for more details.