# The PromQL test scripting language This package contains two things: * an implementation of a test scripting language for PromQL engines * a predefined set of tests written in that scripting language The predefined set of tests can be run against any PromQL engine implementation by calling `promqltest.RunBuiltinTests()`. Any other test script can be run with `promqltest.RunTest()`. The rest of this document explains the test scripting language. Each test script is written in plain text. Comments can be given by prefixing the comment with a `#`, for example: ``` # This is a comment. ``` Each test file contains a series of commands. There are three kinds of commands: * `load` * `clear` * `eval` Each command is executed in the order given in the file. ## `load` command `load` adds some data to the test environment. The syntax is as follows: ``` load ... ``` * `` is the step between points (eg. `1m` or `30s`) * `` is a Prometheus series name in the usual `metric{label="value"}` syntax * `` is a specification of the points to add for that series, following the same expanding syntax as for `promtool unittest` documented [here](../../docs/configuration/unit_testing_rules.md#series) For example: ``` load 1m my_metric{env="prod"} 5 2+3x2 _ stale {{schema:1 sum:3 count:22 buckets:[5 10 7]}} ``` ...will create a single series with labels `my_metric{env="prod"}`, with the following points: * t=0: value is 5 * t=1m: value is 2 * t=2m: value is 5 * t=3m: value is 7 * t=4m: no point * t=5m: stale marker * t=6m: native histogram with schema 1, sum -3, count 22 and bucket counts 5, 10 and 7 Each `load` command is additive - it does not replace any data loaded in a previous `load` command. Use `clear` to remove all loaded data. ### Native histograms with custom buckets (NHCB) When loading a batch of classic histogram float series, you can optionally append the suffix `_with_nhcb` to convert them to native histograms with custom buckets and load both the original float series and the new histogram series. ## `clear` command `clear` removes all data previously loaded with `load` commands. ## `eval` command `eval` runs a query against the test environment and asserts that the result is as expected. Both instant and range queries are supported. The syntax is as follows: ``` # Instant query eval instant at