influxdata / influxdata/kapacitor

Error when adding a required variable to a templated task

Open
#2,223 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
2.4k
Forks
479
Avg merge
4d 16h
Merged PRs (30d)
4

Description

This is pretty simple to replicate (for this example I use a docker container). Start with the task template `simple.tick`
```
dbrp "infra-metrics"."7d"

// required template variables
var measurement string

stream
|from()
.measurement(measurement)
|alert()
.crit(lambda: int("usage_idle") < 70)
// Whenever we get an alert write it to a file.
.log('/tmp/alerts.log')
```
and the task definition file `foo1.yaml`
```
template-id: simple
vars:
measurement: {type: string, value: "cpu"}
```
1. start Kapacitor
2. stop Kapacitor
3. Now update the files by adding a `crit` variable (should look like the following now)
```
dbrp "infra-metrics"."7d"

// required template variables
var measurement string
var crit int

stream
|from()
.measurement(measurement)
|alert()
.crit(lambda: int("usage_idle") < crit)
// Whenever we get an alert write it to a file.
.log('/tmp/alerts.log')
```
and the task definition file `foo1.yaml`
```
template-id: simple
vars:
measurement: {type: string, value: "cpu"}
crit: {type: int, value: 70}
```
4. start Kapacitor and get an error about the new required variable not being defined.
`ts=2019-06-20T21:13:36.508Z lvl=error msg="encountered error" service=run err="open server: failed to reload tasks/templates/handlers: failed to load file /root/.kapacitor/load/templates/simple.tick: failed to create template: error reloading associated task foo1: missing value for var \"crit\"."`

This can be addressed by deleting the Kapacitor database (/var/lib/kapacitor/kapacitor.db). After deleting the database, simply starting kapacitord again works perfectly fine.

My guess is that the template gets updated in the database and then the templated tasks in the database are applied before they are updated from the new yaml files.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using templates/simple.tick, foo1.yaml, and the Kapacitor database at /var/lib/kapacitor/kapacitor.db. Start Kapacitor, stop it, add the required crit variable to both files, and restart it to observe the reload error. Done means the updated YAML value is applied on restart without deleting the database.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.