influxdata / influxdata/kapacitor

Window#first cuts off fields after execution, no option to preserve field with keep()

Open
#2,273 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi all,

I'm pretty new to tick script and I'm trying to make a window of 30s and emits every 15s.

Here is a my code:
```
var source = stream
|from()
.measurement('measurement')
.where(lambda: isPresent("retxPacketsReceived") AND isPresent("packetsReceived"))
|groupBy('device')
|log()
|window()
.period(30s)
.every(10s)

var retxPercentage = source
|first('retxPacketsReceived')
.as('firstRetxPacketsReceived')
|last('retxPacketsReceived')
.as('lastRetxPacketsReceived')
|first('packetsReceived')
.as('firstPacketsReceived')
|last('packetsReceived')
.as('lastPacketsReceived')
|eval(lambda: int("lastRetxPacketsReceived") - int("firstRetxPacketsReceived"))
.as('retxPercentageValue')
|log()

retxPercentage
|alert()
.warn(lambda: "retxPercentageValue" >= RETX_PACKETS_PERCENTAGE_WARN)
.warnReset(lambda: "retxPercentageValue" < RETX_PACKETS_PERCENTAGE_WARN)
.message('')
.id('{{index .Tags "device"}})
.idTag(idTag)
.levelTag(levelTag)
.messageField(messageField)
.durationField(durationField)
```

Here are the code I insert in Influx:
```
insert measurement,device=101 retxPacketsReceived=100,packetsReceived=100
insert measurement,device=101 retxPacketsReceived=100,packetsReceived=200
insert measurement,device=101 retxPacketsReceived=100,packetsReceived=300
```

The error I see in logs:
```
ts=2020-01-09T21:42:28.535Z lvl=error msg="failed to realize reduce context from fields" service=kapacitor task_master=main task=argo-dev node=last48 err="field \"retxPacketsReceived\" missing from point"
```
If I remove the `last` and only call single time to `first` then I can make it work. It's like calling `first` removes the field from the window or something like that...
Any idea?

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 supplied Kapacitor task with its window, first, and last pipeline, then inspect the Window#first behavior and the keep() option mentioned in the issue. Done means the window preserves retxPacketsReceived so both first and last reductions run without the missing-field error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
stream-processing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.