Flux |>
Nathaniel Cook
An overview of Flux and the future of the functional data
scripting and querying language.
Nathaniel Cook
Engineering Manager, Flux,
InfluxData
Nathaniel is the leader of the Flux Project at InfluxData. Nathaniel
started his career as an operations engineer, trying to make data do
the hard work of monitoring and managing large scale SaaS products.
Along the way he learned some data science and machine learning
and put them to use detecting anomalies in time series data. Nathaniel
holds an MS degree from University of Illinois.
Scripting Languages Demonstration
Agenda
1. Review of Flux over the past year
2. Look forward to the next year of Flux
http/requests
import "http/requests"
response =
requests.get(
url: "http://example.com",
params: ["start": ["100"], "interval": ["1h", "1d"]]
)
// http://example.com?start=100&interval=1h&interval=1d
requests.peek(response: response)
https://docs.influxdata.com/flux/v0.x/stdlib/http/requests/
array
import "array"
a = [ 1, 2, 3, 4, 5]
|> array.filter(fn: (x) => x >= 2)
|> array.map(fn: (x) => ({_value: x}))
array.from(rows: a)
https://docs.influxdata.com/flux/v0.x/stdlib/array/
typing.isType
data
|> filter(
fn: (r) =>
types.isType(v: r._value, type: "int")
or types.isType(v: r._value, type: "float"),
)
|> aggregateWindow(every: 30s, fn: last)
location
import "timezone"
// Set location using a fixed timezone
option location = timezone.fixed(offset: -8h)
// Set a location by its name
option location = timezone.location(name: "America/Los_Angeles")
join
import "join"
join.right(
left: left,
right: right,
on: (l, r) => l.label == r.id and l._time == r._time,
as: (l, r) => ({_time: r._time, label: r.id, v: l.v + r.v}),
)
https://docs.influxdata.com/flux/v0.x/stdlib/join/
Flux 1.0
Flux 1.0 Coming Soon
● Commitment to the stability of Flux
● No breaking changes to Flux behavior
● Today's Flux scripts will run on 1.0, no migration needed
Stability without Stagnation
● Editions
○ Editions are a set of features that are disabled by default
○ Enabling an edition enables those features
○ Editions are opt-in
○ Future versions of Flux will support all existing editions
○ Editions are for new features that would otherwise introduce
breaking changes to Flux
Edition Pacing
● Editions will be named after years and we expect around one
edition per year
● First edition will be named 2022.1
● Second edition will be published shortly after the first edition
with the first batch of new Flux features
Selecting an Edition
● Three methods for selecting an edition:
○ API Parameter
○ Org Property
○ Flux script syntax
@edition(2022.1)
from(bucket:"influxdays")
|> range(start: -1m)
Flux User Modules
Flux User Modules
● Save and share your Flux scripts
○ A module is a collection of Flux packages
● Can be shared within the same organization
● Versioned for easy management with the whole organization
● Cloud only for now
Module Versioning
● Modules will follow a semantic versioning scheme
○ MAJOR.MINOR.PATCH
● Importing specific versions of modules
○ Latest version is use by default
○ A minimum version can be specified
● Version selection will be a simple maximum version of all
minimum versions
Publishing a Module
1. Write Flux code within a package
2. Pick new version based on semantic rules (may automate this in
the future)
3. Publish module with the given version
a. Modules are immutable, once created they cannot be change
b. Publish a new version to make changes
Module Example
// datasets.flux
package datasets
widgets = (bucket) => from(bucket: bucket)
|> range(start: -1m)
|> filter(fn: (r) => r._measurement == "widgets")
// main.flux
import "datasets"
datasets.widgets() |> mean()
Modules + Editions
● Modules each have their own edition
● Modules can import and consume other module regardless of
their edition
T H A N K Y O U

Nathaniel Cook [InfluxData] | Scripting Languages Demonstration: Flux |> | InfluxDays 2022

  • 2.
  • 3.
    An overview ofFlux and the future of the functional data scripting and querying language. Nathaniel Cook Engineering Manager, Flux, InfluxData Nathaniel is the leader of the Flux Project at InfluxData. Nathaniel started his career as an operations engineer, trying to make data do the hard work of monitoring and managing large scale SaaS products. Along the way he learned some data science and machine learning and put them to use detecting anomalies in time series data. Nathaniel holds an MS degree from University of Illinois. Scripting Languages Demonstration
  • 4.
    Agenda 1. Review ofFlux over the past year 2. Look forward to the next year of Flux
  • 5.
    http/requests import "http/requests" response = requests.get( url:"http://example.com", params: ["start": ["100"], "interval": ["1h", "1d"]] ) // http://example.com?start=100&interval=1h&interval=1d requests.peek(response: response) https://docs.influxdata.com/flux/v0.x/stdlib/http/requests/
  • 6.
    array import "array" a =[ 1, 2, 3, 4, 5] |> array.filter(fn: (x) => x >= 2) |> array.map(fn: (x) => ({_value: x})) array.from(rows: a) https://docs.influxdata.com/flux/v0.x/stdlib/array/
  • 7.
    typing.isType data |> filter( fn: (r)=> types.isType(v: r._value, type: "int") or types.isType(v: r._value, type: "float"), ) |> aggregateWindow(every: 30s, fn: last)
  • 8.
    location import "timezone" // Setlocation using a fixed timezone option location = timezone.fixed(offset: -8h) // Set a location by its name option location = timezone.location(name: "America/Los_Angeles")
  • 9.
    join import "join" join.right( left: left, right:right, on: (l, r) => l.label == r.id and l._time == r._time, as: (l, r) => ({_time: r._time, label: r.id, v: l.v + r.v}), ) https://docs.influxdata.com/flux/v0.x/stdlib/join/
  • 10.
  • 11.
    Flux 1.0 ComingSoon ● Commitment to the stability of Flux ● No breaking changes to Flux behavior ● Today's Flux scripts will run on 1.0, no migration needed
  • 12.
    Stability without Stagnation ●Editions ○ Editions are a set of features that are disabled by default ○ Enabling an edition enables those features ○ Editions are opt-in ○ Future versions of Flux will support all existing editions ○ Editions are for new features that would otherwise introduce breaking changes to Flux
  • 13.
    Edition Pacing ● Editionswill be named after years and we expect around one edition per year ● First edition will be named 2022.1 ● Second edition will be published shortly after the first edition with the first batch of new Flux features
  • 14.
    Selecting an Edition ●Three methods for selecting an edition: ○ API Parameter ○ Org Property ○ Flux script syntax @edition(2022.1) from(bucket:"influxdays") |> range(start: -1m)
  • 15.
  • 16.
    Flux User Modules ●Save and share your Flux scripts ○ A module is a collection of Flux packages ● Can be shared within the same organization ● Versioned for easy management with the whole organization ● Cloud only for now
  • 17.
    Module Versioning ● Moduleswill follow a semantic versioning scheme ○ MAJOR.MINOR.PATCH ● Importing specific versions of modules ○ Latest version is use by default ○ A minimum version can be specified ● Version selection will be a simple maximum version of all minimum versions
  • 18.
    Publishing a Module 1.Write Flux code within a package 2. Pick new version based on semantic rules (may automate this in the future) 3. Publish module with the given version a. Modules are immutable, once created they cannot be change b. Publish a new version to make changes
  • 19.
    Module Example // datasets.flux packagedatasets widgets = (bucket) => from(bucket: bucket) |> range(start: -1m) |> filter(fn: (r) => r._measurement == "widgets") // main.flux import "datasets" datasets.widgets() |> mean()
  • 20.
    Modules + Editions ●Modules each have their own edition ● Modules can import and consume other module regardless of their edition
  • 21.
    T H AN K Y O U