influxdata / influxdata/kapacitor

Automatically convert from int64 to float64 when using percentile

Open
#311 0 comments 0 reactions 0 assignees View on GitHub
new-feature
Dominant language
Go
Stars
2.4k
Forks
479
Avg merge
4d 16h
Merged PRs (30d)
4

Description

Version information:

```
Kapacitor 0.10.1 (git: master 22b917b4722addf9ff604d16fa01a09431641c55)
```

When attempting to define the TICK script:

```
stream
.from().measurement('cpu')
.eval(lambda: 100 - "usage_idle").as('used')
.groupBy('host')
.mapReduce(influxql.percentile('used', 95))
.alert()
.id('{{ .Name }}/{{ index .Tags "host"}}')
.warn(lambda: "used" > 2.5)
.crit(lambda: "used" > 3.0)
// Whenever we get an alert write it to a file.
.log('/tmp/cpu_idle_alerts.log')
.stateChangesOnly()
```

I get the error:

```
invalid task: error calling func "percentile" on obj *kapacitor.influxqlMapReducers: reflect: Call using int64 as type float64
```

It seems the issue is that the call `.mapReduce(influxql.percentile('used', 95))` expects `95` to be a float, so changing it to:

```
.mapReduce(influxql.percentile('used', 95.0))
```

Works like a charm. It would be great if the int to float was conversion was handled automatically, though.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported percentile call with an integer argument and compare it with the working float argument. Trace the percentile map-reducer invocation and its argument handling; done means an int64 percentile value is accepted without the reflect type error while the existing float form continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.