Unit Tests
It's possible to define unit tests within a Vector configuration file that cover a network of transforms within the topology. The intention of these tests is to improve the maintainability of configs containing larger and more complex combinations of transforms.
Executing tests within a config file can be done with the test subcommand:
vector test /etc/vector/*.toml
Configuration
- Common
- Advanced
[transforms.bar]type = "regex_parser"regex = "^(?P<timestamp>[\\w\\-:\\+]+) (?P<level>\\w+) (?P<message>.*)$"[[tests]]# REQUIRED - Generalname = "foo test" # example# REQUIRED - Outputs[[tests.outputs]]# REQUIRED - Generalextract_from = "foo" # example# REQUIRED - Conditions[[tests.outputs.conditions]]# REQUIREDtype = "check_fields" # example# OPTIONAL"message.eq" = "this is the content to match against" # example"host.exists" = true # example"method.neq" = "POST" # example# REQUIRED - Input[tests.input]# REQUIREDtype = "raw" # example, enuminsert_at = "foo" # example# OPTIONALvalue = "some message contents" # example, no default, relevant when type = "raw"
For more information about unit tests check out this guide.
Options
input
A table that defines a unit test input event.
insert_at
The name of a transform, the input event will be delivered to this transform in order to begin the test.
log_fields
Specifies the log fields when the input type is 'log'.
[field-name]
A key/value pair representing a field to be added to the input event.
metric
Specifies the metric type when the input type is 'metric'.
direction
The direction to increase or decrease the gauge value.
"plus" "minus" name
The name of the metric. Defaults to <field>_total for counter and <field> for gauge.
sample_rate
The bucket/distribution the metric is a part of.
timestamp
Time metric was created/ingested.
type
The metric type.
"counter" "gauge" "histogram" "set" val
Amount to increment/decrement or gauge.
type
The event type.
"raw" "log" "metric" value
Specifies the log message field contents when the input type is 'raw'.
name
A unique identifier for this test.
outputs
A table that defines a unit test expected output.
conditions
A table that defines a collection of conditions to check against the output of a transform. A test is considered to have passed when each condition has resolved true for one or more events extracted from the target transform.
<field_name>.eq
Check whether a fields contents exactly matches the value specified.
<field_name>.exists
Check whether a field exists or does not exist, depending on the provided valuebeing true or false respectively.
<field_name>.neq
Check whether a fields contents does not match the value specified.
type
The type of the condition to execute. Currently only the check_fields type is available.
extract_from
The name of a transform, at the end of the test events extracted from this transform will be checked against a table of conditions.