influxdata / influxdata/kapacitor
Need help on tick script
- Dominant language
- Go
- Stars
- 2.4k
- Forks
- 479
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 4
Description
Hi all:
I'm new to Kapacitor and I'm having trouble using the Eval() node in a tick script.
I have the following simple PoC script whose purpose is just to calculate the used percentage of CPU for each telemetry point received by Influx for a K8s cluster.
```
stream
|from()
.database('k8s')
.retentionPolicy('default')
.measurement('cpu')
|eval(lambda: "usage_rate" / "limit")
.as('used')
.keep('used')
|influxDBOut()
.database('test')
.retentionPolicy('default')
.measurement('test')
.create()
```
The problem I've been running into is that it appears fields aren't being queried properly from the measurement. Specifically, I keep seeing variations of this error:
```
ts=2018-02-01T21:12:07.860Z lvl=error msg="error evaluating expression" service=kapacitor task_master=main task=t1 node=eval2 err="invalid math operator /
for type missing"
```
While it is true that for some measurements, sometimes one or the other (or possibly both) fields are missing, they are almost always present:
```
> select "usage_rate", "limit" from cpu where time > now() - 1m;
name: cpu
time usage_rate limit
---- ---------- -----
1517519460000000000 0 20
1517519460000000000 753 14476
1517519460000000000 391 13726
1517519460000000000 116 750
1517519460000000000 0 100
1517519460000000000 0 100
1517519460000000000 5 500
1517519460000000000 8 500
1517519460000000000 0 300
1517519460000000000 21 1050
1517519460000000000 0 100
1517519460000000000 0 100
1517519460000000000 0 300
1517519460000000000 0 900
```
I'm at a loss as to why Kapacitor is complaining that it is always running into missing values:
```
DOT:
digraph t1 {
graph [throughput="0.00 points/s"];
stream0 [avg_exec_time_ns="0s" errors="0" working_cardinality="0" ];
stream0 -> from1 [processed="15440"];
from1 [avg_exec_time_ns="104.641µs" errors="0" working_cardinality="0" ];
from1 -> eval2 [processed="15440"];
eval2 [avg_exec_time_ns="625.296µs" errors="15440" working_cardinality="1" ];
eval2 -> influxdb_out3 [processed="0"];
```
But I assume it's just that I am missing something relatively obvious as to how this is supposed to work.
Contributor guide
Research direction
Start at the Eval() node in the supplied tick script and compare the fields it receives with the Influx query showing usage_rate and limit. Trace why the evaluation reports missing values, then verify the corrected expression by checking that points reach influxDBOut and the calculated used field is written.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kubernetes
- Domain
- observability-sre, stream-processing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100