Skip to content

Creating system wide custom functions #23839

Open
@vlcty

Description

@vlcty

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions