influxdata / influxdata/influxdb
Creating system wide custom functions
- Dominant language
- Rust
- Stars
- 31.7k
- Forks
- 3.7k
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 8
Description
__Proposal:__
Let users create and use system wide custum functions.
__Current behavior:__
Custom functions can be created but must be redefined in ever query.
__Desired behavior:__
I'd like to have API endpoints to create, read, update and delete custom functions. For example a POST/PUT request to /api/v2/functions/{functionName} and the body containing a Flux function definition would create or update that function.
In queries I want to be able to use that custom function just like it would be a built in function from the standard library.
__Alternatives considered:__
An alternative could be to use an automation layer like ansible to create Flux scripts and deploy it into the systems requiring custom functions.
__Use case:__
Based on the selected time range I wanted to adjust the aggregation window to reduce query time. For example:
```
every =
if uint(v: v.timeRangeStop) - uint(v: v.timeRangeStart) < uint(v: 14d) then 5m
else 1d
from(bucket: "asdf")
// some filtering and other operations
|> aggregateWindow(every: every, fn: mean, createEmpty: true)
```
I'd want to create a function replicating this behaviour and store it in InfluxDB. For example:
```
my_cool_aggregation_window = (stop, start) => {
if uint(v: stop) - uint(v: start) < uint(v: 14d) then 5m
else 1d
}
```
Downstreams queries could the use it like this:
```
from(bucket: "asdf")
// some filtering and other operations
|> aggregateWindow(every: my_cool_aggregation_window(v.timeRangeStop, v.timeRangeStart), fn: mean, createEmpty: true)
```
Contributor guide
Research direction
Start by reviewing the proposed /api/v2/functions/{functionName} POST/PUT API and the requested create, read, update, and delete behavior. Compare the stored Flux function definition with the example query usage; done means system-wide functions can be managed through the API and used in downstream queries like built-in functions.
Written by the indexing model from the issue text.
Assessment
- Domain
- api, backend-api-design, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100