Route

Split a stream of events into multiple sub-streams based on user-supplied conditions

status: stable egress: stream state: stateless

Splits a stream of events into multiple sub-streams based on a set of conditions.

Also, see the [Exclusive Route](/docs/reference/configuration/transforms/exclusive_route transform for routing an event to a single stream.

Configuration

Example configurations

{
  "transforms": {
    "my_transform_id": {
      "type": "route",
      "inputs": [
        "my-source-or-transform-id"
      ]
    }
  }
}
[transforms.my_transform_id]
type = "route"
inputs = [ "my-source-or-transform-id" ]
transforms:
  my_transform_id:
    type: route
    inputs:
      - my-source-or-transform-id
{
  "transforms": {
    "my_transform_id": {
      "type": "route",
      "inputs": [
        "my-source-or-transform-id"
      ],
      "reroute_unmatched": true,
      "route": {
        "foo-does-not-exist": {
          "source": "!exists(.foo)",
          "type": "vrl"
        },
        "foo-exists": {
          "source": "exists(.foo)",
          "type": "vrl"
        }
      }
    }
  }
}
[transforms.my_transform_id]
type = "route"
inputs = [ "my-source-or-transform-id" ]
reroute_unmatched = true

[transforms.my_transform_id.route.foo-does-not-exist]
source = "!exists(.foo)"
type = "vrl"

[transforms.my_transform_id.route.foo-exists]
source = "exists(.foo)"
type = "vrl"
transforms:
  my_transform_id:
    type: route
    inputs:
      - my-source-or-transform-id
    reroute_unmatched: true
    route:
      foo-does-not-exist:
        source: "!exists(.foo)"
        type: vrl
      foo-exists:
        source: exists(.foo)
        type: vrl

graph

optional object

Extra graph configuration

Configure output for component when generated with graph command

graph.node_attributes

optional object

Node attributes to add to this component’s node in resulting graph

They are added to the node as provided

graph.node_attributes.*
required string literal
A single graph node attribute in graphviz DOT language.
Examples
{
  "color": "red",
  "name": "Example Node",
  "width": "5.0"
}

inputs

required [string]

A list of upstream source or transform IDs.

Wildcards (*) are supported.

See configuration for more info.

Array string literal
Examples
[
  "my-source-or-transform-id",
  "prefix-*"
]

reroute_unmatched

optional bool

Reroutes unmatched events to a named output instead of silently discarding them.

Normally, if an event doesn’t match any defined route, it is sent to the <transform_name>._unmatched output for further processing. In some cases, you may want to simply discard unmatched events and not process them any further.

In these cases, reroute_unmatched can be set to false to disable the <transform_name>._unmatched output and instead silently discard any unmatched events.

default: true

route

optional object

A map from route identifiers to logical conditions. Each condition represents a filter which is applied to each event.

The following identifiers are reserved output names and thus cannot be used as route IDs:

  • _unmatched
  • _default

Each route can then be referenced as an input by other components with the name <transform_name>.<route_id>. If an event doesn’t match any route, and if reroute_unmatched is set to true (the default), it is sent to the <transform_name>._unmatched output. Otherwise, the unmatched event is instead silently discarded.

route.*

required condition
An individual route.

*.source

The text of the condition. The syntax of the condition depends on the value of type.

*.type

The type of condition to supply. See Available syntaxes below for a list of available types for this transform.

Available syntaxes

SyntaxDescriptionExample
vrlA Vector Remap Language (VRL) Boolean expression..status_code != 200 && !includes(["info", "debug"], .severity)
datadog_searchA Datadog Search query string.*stack
is_logWhether the incoming event is a log.
is_metricWhether the incoming event is a metric.
is_traceWhether the incoming event is a trace.

Shorthand for VRL

If you opt for the vrl syntax for this condition, you can set the condition as a string via the condition parameter, without needing to specify both a source and a type. The table below shows some examples:

Config formatExample
YAMLcondition: .status == 200
TOMLcondition = ".status == 200"
JSON"condition": ".status == 200"

Condition config examples

Standard VRL

*:
  type: "vrl"
  source: ".status == 500"
* = { type = "vrl", source = ".status == 500" }
"*": {
  "type": "vrl",
  "source": ".status == 500"
}
*:
  type: "datadog_search"
  source: "*stack"
* = { type = "datadog_search", source = "*stack" }
"*": {
  "type": "datadog_search",
  "source": "*stack"
}

VRL shorthand

*: ".status == 500"
* = ".status == 500"
"*": ".status == 500"

Outputs

<route_id>

Each route can be referenced as an input by other components with the name <transform_name>.<route_id>.

Telemetry

Metrics

link

component_discarded_events_total

counter
The number of events dropped by this component.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
host optional
The hostname of the system Vector is running on.
intentional
True if the events were discarded intentionally, like a filter transform, or false if due to an error.
pid optional
The process ID of the Vector instance.

component_errors_total

counter
The total number of errors encountered by this component.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
error_type
The type of the error
host optional
The hostname of the system Vector is running on.
pid optional
The process ID of the Vector instance.
stage
The stage within the component at which the error occurred.

component_received_event_bytes_total

counter
The number of event bytes accepted by this component either from tagged origins like file and uri, or cumulatively from other origins.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
container_name optional
The name of the container from which the data originated.
file optional
The file from which the data originated.
host optional
The hostname of the system Vector is running on.
mode optional
The connection mode used by the component.
peer_addr optional
The IP from which the data originated.
peer_path optional
The pathname from which the data originated.
pid optional
The process ID of the Vector instance.
pod_name optional
The name of the pod from which the data originated.
uri optional
The sanitized URI from which the data originated.

component_received_events_count

histogram

A histogram of the number of events passed in each internal batch in Vector’s internal topology.

Note that this is separate than sink-level batching. It is mostly useful for low level debugging performance issues in Vector due to small internal batches.

component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
container_name optional
The name of the container from which the data originated.
file optional
The file from which the data originated.
host optional
The hostname of the system Vector is running on.
mode optional
The connection mode used by the component.
peer_addr optional
The IP from which the data originated.
peer_path optional
The pathname from which the data originated.
pid optional
The process ID of the Vector instance.
pod_name optional
The name of the pod from which the data originated.
uri optional
The sanitized URI from which the data originated.

component_received_events_total

counter
The number of events accepted by this component either from tagged origins like file and uri, or cumulatively from other origins.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
container_name optional
The name of the container from which the data originated.
file optional
The file from which the data originated.
host optional
The hostname of the system Vector is running on.
mode optional
The connection mode used by the component.
peer_addr optional
The IP from which the data originated.
peer_path optional
The pathname from which the data originated.
pid optional
The process ID of the Vector instance.
pod_name optional
The name of the pod from which the data originated.
uri optional
The sanitized URI from which the data originated.

component_sent_event_bytes_total

counter
The total number of event bytes emitted by this component.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
host optional
The hostname of the system Vector is running on.
output optional
The specific output of the component.
pid optional
The process ID of the Vector instance.

component_sent_events_total

counter
The total number of events emitted by this component.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
host optional
The hostname of the system Vector is running on.
output optional
The specific output of the component.
pid optional
The process ID of the Vector instance.

utilization

gauge
A ratio from 0 to 1 of the load on a component. A value of 0 would indicate a completely idle component that is simply waiting for input. A value of 1 would indicate a that is never idle. This value is updated every 5 seconds.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
host optional
The hostname of the system Vector is running on.
pid optional
The process ID of the Vector instance.

Examples

Split by log level

Given this event...
{
  "log": {
    "level": "info"
  }
}
...and this configuration...
transforms:
  my_transform_id:
    type: route
    inputs:
      - my-source-or-transform-id
    route:
      debug: .level == "debug"
      info: .level == "info"
      warn: .level == "warn"
      error: .level == "error"
[transforms.my_transform_id]
type = "route"
inputs = [ "my-source-or-transform-id" ]

  [transforms.my_transform_id.route]
  debug = '.level == "debug"'
  info = '.level == "info"'
  warn = '.level == "warn"'
  error = '.level == "error"'
{
  "transforms": {
    "my_transform_id": {
      "type": "route",
      "inputs": [
        "my-source-or-transform-id"
      ],
      "route": {
        "debug": ".level == \"debug\"",
        "info": ".level == \"info\"",
        "warn": ".level == \"warn\"",
        "error": ".level == \"error\""
      }
    }
  }
}
...this Vector event is produced:
{
  "level": "info"
}

Split by metric namespace

Given this event...
{
  "metric": {
    "counter": {
      "value": 10000
    },
    "kind": "absolute",
    "name": "memory_available_bytes",
    "namespace": "host",
    "tags": {}
  }
}
...and this configuration...
transforms:
  my_transform_id:
    type: route
    inputs:
      - my-source-or-transform-id
    route:
      app: .namespace == "app"
      host: .namespace == "host"
[transforms.my_transform_id]
type = "route"
inputs = [ "my-source-or-transform-id" ]

  [transforms.my_transform_id.route]
  app = '.namespace == "app"'
  host = '.namespace == "host"'
{
  "transforms": {
    "my_transform_id": {
      "type": "route",
      "inputs": [
        "my-source-or-transform-id"
      ],
      "route": {
        "app": ".namespace == \"app\"",
        "host": ".namespace == \"host\""
      }
    }
  }
}
...this Vector event is produced:
{
  "counter": {
    "value": 10000
  },
  "kind": "absolute",
  "name": "memory_available_bytes",
  "namespace": "host",
  "tags": {}
}

How it works

Routing to multiple components

The following is an example of how you can create two routes that feed three downstream components.

It is worth noting that a single route can feed multiple downstream components.

transforms:
	my-routes:
		inputs: [ some_source ]
		type: route
		route:
			foo-exists: 'exists(.foo)'
			foo-doesnt-exist: '!exists(.foo)'
	remap-route-1:
		type: remap
		inputs:
			- my-routes.foo-exists
		source: |
			.route = "route 1"
	remap-route-2:
		type: remap
		inputs:
			- my-routes.foo-doesnt-exist
		source: |
			.route = "route 2"
	remap-route-3:
		type: remap
		inputs:
			- my-routes.foo-exists
		source: |
			.route = "route 3"

tests:
	- name: case-1
		inputs:
			- type: log
				insert_at: my-routes
				log_fields:
					foo: X
		outputs:
			- extract_from: remap-route-1
				conditions:
					- type: vrl
						source: |
							assert!(exists(.foo))
							assert_eq!(.route, "route 1")
			- extract_from: remap-route-3
				conditions:
					- type: vrl
						source: |
							assert!(exists(.foo))
							assert_eq!(.route, "route 3")
	- name: case-2
		inputs:
			- type: log
				insert_at: my-routes
				log_fields:
					bar: X
		outputs:
			- extract_from: remap-route-2
				conditions:
					- type: vrl
						source: |
							assert!(!exists(.foo))
							assert_eq!(.route, "route 2")

State

This component is stateless, meaning its behavior is consistent across each input.