[RFC] Kapacitor-unit: test automation for TICK scripts

TL;DR: I have been working on a project called kapacitor-unit (Github project) to help you automating tests for TICK scripts. It’s still under development but currently it’s being used to test TICK scripts in production. Go head and try it out, give feedback and contribute. I hope it helps!

So, I’ve been working on a tool called kapacitor-unit. After using the TICK stack in production and relying a lot on Kapacitor alerts for proactive system visibility and data processing, we noticed that it becomes quite hard to (sanely) maintain a lot of TICK scripts. In a system where you need to often tune alert thresholds and processing tasks or when the format changes, it becomes hard and cumbersome to manually check if the TICK scripts work as expected against real data over time.

So, kapacitor-unit was born! It automates the whole process of checking whether a set of TICK scripts behaved as supposed. Currently, it basically checks whether kapacitor tasks with a certain TICK script behaved as expected (e.g. OK and/or WARNING and/or CRITICAL alerts were triggered) given some particular data (in form of recording or protocol line). The plan is to also include checks on HTTPOutputNode data and so on.

It would be great to have your feedback on the project. Would kapacitor-unit be useful for you? Would you like to see any more features or improvements? Give it a spin and let me know what you think about it!

Gonçalo
https://gpestana.com | @gpestana

Thanks for creating a tool to test alerts. But when we are trying to use it, its giving me following error

-0-root@myhost:/home/advait_deo/go/bin # ./kapacitor-unit -dir ../scripts/ --tests ../conf/kapacitor-unit.conf
  _                          _ _                                _ _
 | |                        (_) |                              (_) |
 | | ____ _ _ __   __ _  ___ _| |_ ___  _ __ ______ _   _ _ __  _| |_
 | |/ / _` | '_ \ / _` |/ __| | __/ _ \| '__|______| | | | '_ \| | __|
 |   < (_| | |_) | (_| | (__| | || (_) | |         | |_| | | | | | |_
 |_|\_\__,_| .__/ \__,_|\___|_|\__\___/|_|          \__,_|_| |_|_|\__|
           | |
           |_|
The unit test framework for TICK scripts (v0.8)

2018/09/21 04:03:45 Init Tests failed: read ../scripts/: is a directory

My Scripts directory has a TICK script that I want to test

Following is the content of conf file

# Test case for test_alert.tick
tests:

   # This is the configuration for a test case. The 'name' must be unique in the
   # same test configuration. 'description' is optional

  - name: Alert test warning
    description: Task should trigger Warning when temperature raises about 80

    # 'task_name' defines the name of the file of the tick script to be loaded
    # when running the test
    task_id: test_alert.tick

    db: testing
    rp: default
    type: stream

     # 'data' is an array of data in the line protocol
    data:
      - test_alert,tag1=tag_value used_pct=80

    # Alert that should be triggered by Kapacitor when test data is running
    # against the task
    expects:
      ok: 0
      warn: 1
      crit: 0