kapacitor-unit
kapacitor-unit copied to clipboard
batch tests do not support --influxdb parameter consistently
When passing --influxdb
parameter to kapacitor-unit, the test data is created in the target destination, but the queries are executed against localhost.
Using the sample batch test data in this repo:
root@5604febba2a3:/kapacitor# cat ticks/alert_weather_batch.tick
var weather = batch
| query('''
SELECT mean(temperature)
FROM "weather"."default"."temperature"
''')
.period(5m)
.every(10m)
var rain = batch
| query('''
SELECT count(rain)
FROM "weather"."default"."temperature"
''')
.period(5m)
.every(3d)
// simple case with only one batch query
weather
| alert().id('Temperature')
.message('Temperature alert - batch')
.warn(lambda: "mean" > 80)
.crit(lambda: "mean" > 100)
.stateChangesOnly()
.log('/tmp/temperature_batch.tick.log')
root@5604febba2a3:/kapacitor# cat test/sample.yaml
tests:
# batch script
- name: "Alert weather:: batch"
task_name: alert_weather_batch.tick
db: weather
rp: default
type: batch
data:
- temperature,location=us-midwest temperature=110
- temperature,location=us-midwest temperature=91
expects:
ok: 0
warn: 0
crit: 1
The run fails like so:
root@5604febba2a3:/kapacitor# kapacitor-unit --dir /kapacitor/ticks --kapacitor http://localhost:9092 --influxdb http://myinfluxdb1:8086 --tests /kapacitor/test/sample.yaml
_ _ _ _ _
| | (_) | (_) |
| | ____ _ _ __ __ _ ___ _| |_ ___ _ __ ______ _ _ _ __ _| |_
| |/ / _` | '_ \ / _` |/ __| | __/ _ \| '__|______| | | | '_ \| | __|
| < (_| | |_) | (_| | (__| | || (_) | | | |_| | | | | | |_
|_|\_\__,_| .__/ \__,_|\___|_|\__\___/|_| \__,_|_| |_|_|\__|
| |
|_|
The unit test framework for TICK scripts (v0.9)
Processing batch script alert_weather_batch.tick...
ts=2020-02-25T19:09:28.008Z lvl=error msg="error executing query" service=kapacitor task_master=main task=alert_weather_batch.tick node=query1 err="Post http://localhost:8086/query?db=&q=SELECT+mean%28temperature%29+FROM+weather.%22default%22.temperature+WHERE+time+%3E%3D+%272020-02-25T19%3A04%3A28.007892268Z%27+AND+time+%3C+%272020-02-25T19%3A09%3A28.007892268Z%27: dial tcp 127.0.0.1:8086: connect: connection refused"
ts=2020-02-25T19:09:28.008Z lvl=error msg="error executing query" service=kapacitor task_master=main task=alert_weather_batch.tick node=query2 err="Post http://localhost:8086/query?db=&q=SELECT+count%28rain%29+FROM+weather.%22default%22.temperature+WHERE+time+%3E%3D+%272020-02-25T19%3A04%3A28.007889895Z%27+AND+time+%3C+%272020-02-25T19%3A09%3A28.007889895Z%27: dial tcp 127.0.0.1:8086: connect: connection refused"
ts=2020-02-25T19:09:29.008Z lvl=error msg="error executing query" service=kapacitor task_master=main task=alert_weather_batch.tick node=query2 err="Post http://localhost:8086/query?db=&q=SELECT+count%28rain%29+FROM+weather.%22default%22.temperature+WHERE+time+%3E%3D+%272020-02-25T19%3A04%3A29.007402193Z%27+AND+time+%3C+%272020-02-25T19%3A09%3A29.007402193Z%27: dial tcp 127.0.0.1:8086: connect: connection refused"
ts=2020-02-25T19:09:29.008Z lvl=error msg="error executing query" service=kapacitor task_master=main task=alert_weather_batch.tick node=query1 err="Post http://localhost:8086/query?db=&q=SELECT+mean%28temperature%29+FROM+weather.%22default%22.temperature+WHERE+time+%3E%3D+%272020-02-25T19%3A04%3A29.007404716Z%27+AND+time+%3C+%272020-02-25T19%3A09%3A29.007404716Z%27: dial tcp 127.0.0.1:8086: connect: connection refused"
ts=2020-02-25T19:09:30.008Z lvl=error msg="error executing query" service=kapacitor task_master=main task=alert_weather_batch.tick node=query1 err="Post http://localhost:8086/query?db=&q=SELECT+mean%28temperature%29+FROM+weather.%22default%22.temperature+WHERE+time+%3E%3D+%272020-02-25T19%3A04%3A30.007409273Z%27+AND+time+%3C+%272020-02-25T19%3A09%3A30.007409273Z%27: dial tcp 127.0.0.1:8086: connect: connection refused"
ts=2020-02-25T19:09:30.008Z lvl=error msg="error executing query" service=kapacitor task_master=main task=alert_weather_batch.tick node=query2 err="Post http://localhost:8086/query?db=&q=SELECT+count%28rain%29+FROM+weather.%22default%22.temperature+WHERE+time+%3E%3D+%272020-02-25T19%3A04%3A30.007407014Z%27+AND+time+%3C+%272020-02-25T19%3A09%3A30.007407014Z%27: dial tcp 127.0.0.1:8086: connect: connection refused"
2020/02/25 19:09:30 TEST Alert weather:: batch (alert_weather_batch.tick) FAIL
Should have triggered 1 Critical alerts, triggered 0
Alerts triggered (ok: 0, warn: 0, crit: 0)
Note http://localhost:8086/query?
But when I look at myinfluxdb1
, I see the appropriate drop/create for each run:
highland@myinfluxdb1:~$ journalctl --since="3 hours ago" | grep weather | tail -n4
Feb 25 19:09:26 myinfluxdb1 influxd[1433]: ts=2020-02-25T19:09:26.977619Z lvl=info msg="Executing query" log_id=0KlPpmyl000 service=query query="CREATE DATABASE weather WITH DURATION 1h0m0s REPLICATION 1 NAME \"default\""
Feb 25 19:09:27 myinfluxdb1 influxd[1433]: [httpd] 192.168.0.17 - - [25/Feb/2020:11:09:27 -0800] "POST /write?db=weather&rp=default HTTP/1.1" 204 0 "-" "Go-http-client/1.1" 578b1f8f-5802-11ea-8e69-0050562ae7ac 23852
Feb 25 19:09:27 myinfluxdb1 influxd[1433]: [httpd] 192.168.0.17 - - [25/Feb/2020:11:09:27 -0800] "POST /write?db=weather&rp=default HTTP/1.1" 204 0 "-" "Go-http-client/1.1" 578ee596-5802-11ea-8e6a-0050562ae7ac 1111
Feb 25 19:09:30 myinfluxdb1 influxd[1433]: ts=2020-02-25T19:09:30.055504Z lvl=info msg="Executing query" log_id=0KlPpmyl000 service=query query="DROP DATABASE weather"