SlideShare a Scribd company logo
DevelopingYourOwn
FluxPackages
David McKay, DevRel at InfluxData
Agenda
★ A (Quick) Introduction to Flux
★ Standard Library
★ Writing Your Own Flux
★ What’s Coming Next?
A(Quick)Introduction toFlux
5 © 2018 InfluxData. All rights reserved.
/ / This i s a comment
Com m ents
6 © 2018 InfluxData. All rights reserved.
name =“ David McKay”
age = 1.2
a l i v e = t r u e
Assignment
7 © 2018 InfluxData. All rights reserved.
name = “David McKay”
o b je c t s ={ name, age: 23}
Objects
8 © 2018 InfluxData. All rights reserved.
t i m e L i t e r a l s = 2018-08-28T10:20:00Z
= 2018-08-28
dateMath = 2019- 01- 01 + 1mo3d
WorkingwithTime
d u r a t i o n L i t e r a l = 1mo7d
9 © 2018 InfluxData. All rights reserved.
square = ( n ) => n * n
t w e e t ( a t : “rawkode”, message: “ S we e t ! ” )
Functions
10 © 2018 InfluxData. All rights reserved.
PipeForwardOperator
moveIn()
| > moveOut()
| > handsUp()
| > handsDown()
| > backUp()
| > backUp()
| > r o l l ( )
11 © 2018 InfluxData. All rights reserved.
UTF-8
> ʭ = ( ) => " I d o n ' t know what t h i s symbol i s c a l l e d "
> ʭ
( ) - > s t r i n g
> ʭ()
I d o n ' t know what t h i s symbol i s c a l l e d
12 © 2018 InfluxData. All rights reserved.
UTF-8
> hotdog = ( ) => “Armour 🌭 ! ”
> hotdog()
> Armour 🌭 !
> 🌭 = ( ) => “Armour Hotdog!”
E r r o r: i n v a l i d statement @1: 1- 1: 5: 🌭
WritingYourOwnFlux
With Flux
14 © 2018 InfluxData. All rights reserved.
rawkode.flux
package rawkode
gitHubHandle =
“rawkode” h e l l o
= ( ) => " H e l l o "
awesomeThings = [ "BBQ", " H o t Sauce", “ 🌭 ” ]
15 © 2018 InfluxData. All rights reserved.
rawkode.flux
package rawkode
awesomeise = ( t a b l e = < - ) => {
t a b l e |> map( fn : ( r ) => "Awesome" + r )
}
16 © 2018 InfluxData. All rights reserved.
FluxREPL
rawkode@penguin:~ . / f l u x r e p l
> @rawkode.flux
> awesomeThings | > awesomeise
Limitations Your Flux packages will only be as good as our
standard library
Flux is still early
StandardLibrary
19 © 2018 InfluxData. All rights reserved.
➔ CSV
➔ HTTP
➔ InfluxDB
➔ Kafka
➔ Math
➔ SQL
➔ Testing
➔ Will continue to grow …
StandardLibrary
20 © 2018 InfluxData. All rights reserved.
Math
import "math"
math.NaN()
/ / Returns NaN
21 © 2018 InfluxData. All rights reserved.
Math
import "math"
math. s q r t( x: 4.0 )
/ / Returns 2.0
22 © 2018 InfluxData. All rights reserved.
Strings
import " s t r i n g s "
s t r i n g s . t i t l e ( v : " a f l u x o f f o x e s " )
/ / r e t u r n s "A Flux Of Foxes"
23 © 2018 InfluxData. All rights reserved.
CSV
import " c s v "
c s v . f r o m ( f i l e : " / p a t h / t o / d a t a - f i l e . c s v " )
/ / OR
c s v . f r o m ( c s v : csvData)
24 © 2018 InfluxData. All rights reserved.
Testing
import " t e s t i n g "
t e s t i n g . a s s e r t E q u a l s (
name: "some t e s t name",
g o t : g o t ,
want: want
)
https://v2.docs.influxdata.com/
Thank You,
Docs Team!
The v2 (InfluxDB) docs are a great way to
follow up on this:
★ Functional NB: It’s a functional language, by
design, as opposed to OOP.
I don’t mean “it kinda
works”
Our Vision is
Awesome
★ Flux is a generic data scripting language
★ It does/will support:
○ MySQL / PostgrSQL
○ Prometheus
○ Kafka
○ more!
Our Community
is Awesome
★ InfluxDB has 373 contributors
★ Telegraf has 520 contributors
★ Together they have over 20k+ stars
WritingYourOwnFlux
With Go
29 © 2018 InfluxData. All rights reserved.
30 © 2018 InfluxData. All rights reserved.
m ath.flux
package math
/ / b u i l t i n constants
b u i l t i n p i
/ / b u i l t i n f unctions
b u i l t i n abs
31 © 2018 InfluxData. All rights reserved.
math.go
package math
func i n i t ( ) {
/ / constants
f l u x . RegisterPackageValue( "math", " p i " ,
values.NewFloat(math.Pi))
}
Math has no rand()
What the
Flux!
NewFunction " g i t h u b . c o m / i n f l u x d a t a / f l u x / v a l u e s "
34 © 2018 InfluxData. All rights reserved.
math.go
package math
func i n i t ( ) {
/ / constants
f l u x . RegisterPackageValue( "math", " p i " ,
values.NewFloat(math.Pi))
}
35 © 2018 InfluxData. All rights reserved.
/ / rand f unction
math.go
package math
func i n i t ( ) {
/ / rand f u n c t i o n
flux.RegisterPackageValue (
values. NewFunction( “math”, ???)
)
}
36 © 2018 InfluxData. All rights reserved.
values.NewFunction
★ Takes 4 parameters
○ Name of function
○ Function signature
○ Actual function + safety harness
○ Side effect boolean
37 © 2018 InfluxData. All rights reserved.
???
)
NewFunction:FunctionName
values. NewFunction(
" r a n d " ,
???,
???,
38 © 2018 InfluxData. All rights reserved.
NewFunction:FunctionSignature
/ / rand wi t h no params
semantic.NewFunctionPolyType(semantic.FunctionPolySignature{
Parameters: map[string]semantic.PolyType{},
Return: semantic.UInt,
} ) ,
/ / i n Go: func r a n d ( ) u i n t
39 © 2018 InfluxData. All rights reserved.
semantic.LabelSet{"max"},
semantic.UInt,
Required:
Return:
} ) ,
/ / in Go: f unc rand(max u i n t ) u i n t
NewFunction:FunctionSignature
/ / rand with 1 param: max
semantic.NewFunctionPolyType(semantic.FunctionPolySignature{
Parameters: map[string]semantic.PolyType{ "max":
semantic.Int
} ,
40 © 2018 InfluxData. All rights reserved.
semantic.LabelSet{"min", "max"},
semantic.UInt,
Required:
Return:
} ) ,
/ / in Go: f unc rand(min u i n t , max u i n t ) u i n t
NewFunction:FunctionSignature
/ / rand with 2 param: min, max
semantic.NewFunctionPolyType(semantic.FunctionPolySignature{
Parameters: map[string]semantic.PolyType{ "min":
semantic.Int,
"max": semantic.Int
} ,
41 © 2018 InfluxData. All rights reserved.
???
)
NewFunction:FunctionName&Signature
values. NewFunction(
" r a n d " ,
semantic. NewFunctionPolyType( … )
???,
42 © 2018 InfluxData. All rights reserved.
goRand : = rand.New(rand.NewSource(...))
NewFunction:Function(NoParams)
/ / 🌭 No Er r o r Checking 🌭
f u n c ( ) ( v a l u e s . V a l u e , e r r o r ) {
goRand : = rand.New(rand.NewSource(...))
r e t u r n values. NewUInt( goRand. I n t n ( 100) ) , n i l
}
43 © 2018 InfluxData. All rights reserved.
NewFunction:Function(MaxParams)
f unc (args values . Objec t ) (values . V al ue , e r r o r ) {
max, ok : = args.Get("max")
i f ! o k {
r e t u r n n i l , errors.New("m issing argument max")
}
i f m ax.Type().Nature() == s e m a n t i c . I n t {
goRand : = rand.New(rand.NewSource(time.Now().UnixNano()))
r e t u r n values . NewUInt(goRand .Int n(max. Int())), n i l
}
r e t u r n n i l , f m t . E r r o r f (
"cannot convert argument o f type %vt o u i n t " ,
v . T y p e ( ) . N a t u r e ( )
)
}
44 © 2018 InfluxData. All rights reserved.
???
)
NewFunction:FunctionName,Signature,&Function
values. NewFunction(
" r a n d " ,
semantic.NewFunctionPolyType( … )
f unc( args values. Object) ( values. Value, e r r o r) { … } ,
45 © 2018 InfluxData. All rights reserved.
NewFunction:SideEffect
Flux will optimise code that “appears” pointless
Using true for this parameter will ensure Flux runs such code
“Classical” side-effects apply: network, disk, etc
46 © 2018 InfluxData. All rights reserved.
NewFunction:🌟 Completed🌟
values. NewFunction(
" r a n d " ,
semantic.NewFunctionPolyType( … )
f unc( args values. Object) ( values. Value, e r r o r) { … } ,
f a l s e
)
47 © 2018 InfluxData. All rights reserved.
48 © 2018 InfluxData. All rights reserved.
Compilation!==UnitTest
49 © 2018 InfluxData. All rights reserved.
expected = 100
Test
50 © 2018 InfluxData. All rights reserved.
Test
f l u x F n = v a lu e s . Ne wF u n c t i o n ( . . . )
f l u x A r g : = values.NewObjectWithValues(
m a p [ s t r in g ] v a lu e s . Va lu e {
"max": values.NewInt(expected)
}
)
r e s u l t , e r r : = f l u x F n . C a l l ( f l u x A r g )
AvoidingBoilerplate
52 © 2018 InfluxData. All rights reserved.
53 © 2018 InfluxData. All rights reserved.
54 © 2018 InfluxData. All rights reserved.
Let'sTakeaLook
What’sComingNext
Definitely Maybe
57 © 2018 InfluxData. All rights reserved.
Extending Flux Shouldn’t Need Go
FluxinFlux
HTTP
Files
ENV
More
Flux
Our standard library should allow for you to write
Flux extensions without dropping down to Go:
e lse
o t h e r _ s t u f f
More
Flux
i f 1==1 then
s t u f f
More
Flux
{ r wit h _value : "Awesome", name:
"David McKay"}
61 © 2018 InfluxData. All rights reserved.
You shouldn’t need to get your functionality
merged into influxdata/flux
PackageManagement
This will be OSS
You’ll be able to run and secure your own
Flux
Public
Repo
We’ll provide a public repository for all Flux
packages
We’ve also seen Cargo and Mix
We’ll get this right
Flux
Public
Repo
Don’t worry, we’ve all seen what’s happened in
Go land
64 © 2018 InfluxData. All rights reserved.
Documentation
You shouldn’t need to pause this video, browse
the standard library, or provide offerings to a
deity to know how to do allthis
Docs 1. I want to add a source
2. I want to add a sink
3. I want to add a transformation
Scenario driven documentation:
Docs They’ve already done it*
*They’re on it
Our docs team areawesome
Thank You

More Related Content

PDF
IT Monitoring in the Era of Containers | Luca Deri Founder & Project Lead | ntop
PDF
How to Build a Telegraf Plugin by Noah Crowley
PPTX
InfluxDB IOx Tech Talks: A Rusty Introduction to Apache Arrow and How it App...
PPTX
InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...
PPTX
Samantha Wang [InfluxData] | Best Practices on How to Transform Your Data Usi...
PDF
OPTIMIZING THE TICK STACK
PPTX
Keep Calm and Distributed Tracing
PPTX
Building Modern Data Pipelines for Time Series Data on GCP with InfluxData by...
IT Monitoring in the Era of Containers | Luca Deri Founder & Project Lead | ntop
How to Build a Telegraf Plugin by Noah Crowley
InfluxDB IOx Tech Talks: A Rusty Introduction to Apache Arrow and How it App...
InfluxDB 101 – Concepts and Architecture by Michael DeSa, Software Engineer |...
Samantha Wang [InfluxData] | Best Practices on How to Transform Your Data Usi...
OPTIMIZING THE TICK STACK
Keep Calm and Distributed Tracing
Building Modern Data Pipelines for Time Series Data on GCP with InfluxData by...

What's hot (20)

PPTX
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...
PPTX
Introduction to Flux and Functional Data Scripting
PDF
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
PDF
Catalogs - Turning a Set of Parquet Files into a Data Set
PDF
Introduction to InfluxDB 2.0 & Your First Flux Query by Sonia Gupta, Develope...
PPTX
Intro to InfluxDB 2.0 and Your First Flux Query by Sonia Gupta
PPTX
Sam Dillard [InfluxData] | Performance Optimization in InfluxDB | InfluxDays...
PDF
Worldsensing: A Real World Use Case for Flux by Albert Zaragoza, CTO & Head o...
PPTX
Development and Applications of Distributed IoT Sensors for Intermittent Conn...
PDF
Monitoring, Alerting, and Tasks as Code by Russ Savage, Director of Product M...
PDF
Big Data Day LA 2015 - Large Scale Distinct Count -- The HyperLogLog algorith...
PPTX
How to Use Telegraf and Its Plugin Ecosystem
PDF
IoT Event Processing and Analytics with InfluxDB in Google Cloud | Christoph ...
PDF
The Telegraf Toolbelt | David McKay | InfluxData
PPTX
InfluxDB Community Office Hours September 2020
PPTX
Shashi Raina [AWS] & Al Sargent [InfluxData] | Build Modern Monitoring with I...
PPTX
OPTIMIZING THE TICK STACK
PDF
Kenneth Knowles - Apache Beam - A Unified Model for Batch and Streaming Data...
PPTX
Influx data basic
PPTX
Anais Dotis-Georgiou & Steven Soroka [InfluxData] | Machine Learning with Tel...
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...
Introduction to Flux and Functional Data Scripting
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
Catalogs - Turning a Set of Parquet Files into a Data Set
Introduction to InfluxDB 2.0 & Your First Flux Query by Sonia Gupta, Develope...
Intro to InfluxDB 2.0 and Your First Flux Query by Sonia Gupta
Sam Dillard [InfluxData] | Performance Optimization in InfluxDB | InfluxDays...
Worldsensing: A Real World Use Case for Flux by Albert Zaragoza, CTO & Head o...
Development and Applications of Distributed IoT Sensors for Intermittent Conn...
Monitoring, Alerting, and Tasks as Code by Russ Savage, Director of Product M...
Big Data Day LA 2015 - Large Scale Distinct Count -- The HyperLogLog algorith...
How to Use Telegraf and Its Plugin Ecosystem
IoT Event Processing and Analytics with InfluxDB in Google Cloud | Christoph ...
The Telegraf Toolbelt | David McKay | InfluxData
InfluxDB Community Office Hours September 2020
Shashi Raina [AWS] & Al Sargent [InfluxData] | Build Modern Monitoring with I...
OPTIMIZING THE TICK STACK
Kenneth Knowles - Apache Beam - A Unified Model for Batch and Streaming Data...
Influx data basic
Anais Dotis-Georgiou & Steven Soroka [InfluxData] | Machine Learning with Tel...
Ad

Similar to Developing Your Own Flux Packages by David McKay | Head of Developer Relations | InfluxData (20)

PPTX
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
PDF
Building a Telegraf Plugin by Noah Crowly | Developer Advocate | InfluxData
PDF
Write your own telegraf plugin
PPTX
Extending Flux - Writing Your Own Functions by Adam Anthony
PDF
Python-GTK
PDF
Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018
PPTX
Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies
PDF
Python GTK (Hacking Camp)
PDF
Oczyszczacz powietrza i stos sieciowy? Czas na test! Semihalf Barcamp 13/06/2018
PDF
Java9を迎えた今こそ!Java本格(再)入門
DOCX
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
PDF
#PDR15 - Developing for Round
PDF
What's new in Apache SystemML - Declarative Machine Learning
PDF
David Mertz. Type Annotations. PyCon Belarus 2015
PDF
Eta lang Beauty And The Beast
PPTX
Kostiantyn Grygoriev "Wrapping C++ for Python"
PDF
Machine Learning on Code - SF meetup
DOCX
Billing in a supermarket c++
PDF
Terraform 0.12 Deep Dive: HCL 2.0 for Infrastructure as Code, Remote Plan & A...
DOCX
Itp practical file_1-year
Anais Dotis-Georgiou & Faith Chikwekwe [InfluxData] | Top 10 Hurdles for Flux...
Building a Telegraf Plugin by Noah Crowly | Developer Advocate | InfluxData
Write your own telegraf plugin
Extending Flux - Writing Your Own Functions by Adam Anthony
Python-GTK
Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018
Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies
Python GTK (Hacking Camp)
Oczyszczacz powietrza i stos sieciowy? Czas na test! Semihalf Barcamp 13/06/2018
Java9を迎えた今こそ!Java本格(再)入門
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
#PDR15 - Developing for Round
What's new in Apache SystemML - Declarative Machine Learning
David Mertz. Type Annotations. PyCon Belarus 2015
Eta lang Beauty And The Beast
Kostiantyn Grygoriev "Wrapping C++ for Python"
Machine Learning on Code - SF meetup
Billing in a supermarket c++
Terraform 0.12 Deep Dive: HCL 2.0 for Infrastructure as Code, Remote Plan & A...
Itp practical file_1-year
Ad

More from InfluxData (20)

PPTX
Announcing InfluxDB Clustered
PDF
Best Practices for Leveraging the Apache Arrow Ecosystem
PDF
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...
PDF
Power Your Predictive Analytics with InfluxDB
PDF
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
PDF
Build an Edge-to-Cloud Solution with the MING Stack
PDF
Meet the Founders: An Open Discussion About Rewriting Using Rust
PDF
Introducing InfluxDB Cloud Dedicated
PDF
Gain Better Observability with OpenTelemetry and InfluxDB
PPTX
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
PDF
How Delft University's Engineering Students Make Their EV Formula-Style Race ...
PPTX
Introducing InfluxDB’s New Time Series Database Storage Engine
PDF
Start Automating InfluxDB Deployments at the Edge with balena
PDF
Understanding InfluxDB’s New Storage Engine
PDF
Streamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDB
PPTX
Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...
PDF
Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022
PDF
Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022
PDF
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
PDF
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022
Announcing InfluxDB Clustered
Best Practices for Leveraging the Apache Arrow Ecosystem
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...
Power Your Predictive Analytics with InfluxDB
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
Build an Edge-to-Cloud Solution with the MING Stack
Meet the Founders: An Open Discussion About Rewriting Using Rust
Introducing InfluxDB Cloud Dedicated
Gain Better Observability with OpenTelemetry and InfluxDB
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
How Delft University's Engineering Students Make Their EV Formula-Style Race ...
Introducing InfluxDB’s New Time Series Database Storage Engine
Start Automating InfluxDB Deployments at the Edge with balena
Understanding InfluxDB’s New Storage Engine
Streamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDB
Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...
Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
Machine Learning_overview_presentation.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Empathic Computing: Creating Shared Understanding
PDF
Electronic commerce courselecture one. Pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Tartificialntelligence_presentation.pptx
PPTX
1. Introduction to Computer Programming.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
A comparative analysis of optical character recognition models for extracting...
Digital-Transformation-Roadmap-for-Companies.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Machine Learning_overview_presentation.pptx
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
Building Integrated photovoltaic BIPV_UPV.pdf
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Tartificialntelligence_presentation.pptx
1. Introduction to Computer Programming.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
NewMind AI Weekly Chronicles - August'25-Week II
A comparative analysis of optical character recognition models for extracting...

Developing Your Own Flux Packages by David McKay | Head of Developer Relations | InfluxData

  • 2. Agenda ★ A (Quick) Introduction to Flux ★ Standard Library ★ Writing Your Own Flux ★ What’s Coming Next?
  • 4. 5 © 2018 InfluxData. All rights reserved. / / This i s a comment Com m ents
  • 5. 6 © 2018 InfluxData. All rights reserved. name =“ David McKay” age = 1.2 a l i v e = t r u e Assignment
  • 6. 7 © 2018 InfluxData. All rights reserved. name = “David McKay” o b je c t s ={ name, age: 23} Objects
  • 7. 8 © 2018 InfluxData. All rights reserved. t i m e L i t e r a l s = 2018-08-28T10:20:00Z = 2018-08-28 dateMath = 2019- 01- 01 + 1mo3d WorkingwithTime d u r a t i o n L i t e r a l = 1mo7d
  • 8. 9 © 2018 InfluxData. All rights reserved. square = ( n ) => n * n t w e e t ( a t : “rawkode”, message: “ S we e t ! ” ) Functions
  • 9. 10 © 2018 InfluxData. All rights reserved. PipeForwardOperator moveIn() | > moveOut() | > handsUp() | > handsDown() | > backUp() | > backUp() | > r o l l ( )
  • 10. 11 © 2018 InfluxData. All rights reserved. UTF-8 > ʭ = ( ) => " I d o n ' t know what t h i s symbol i s c a l l e d " > ʭ ( ) - > s t r i n g > ʭ() I d o n ' t know what t h i s symbol i s c a l l e d
  • 11. 12 © 2018 InfluxData. All rights reserved. UTF-8 > hotdog = ( ) => “Armour 🌭 ! ” > hotdog() > Armour 🌭 ! > 🌭 = ( ) => “Armour Hotdog!” E r r o r: i n v a l i d statement @1: 1- 1: 5: 🌭
  • 13. 14 © 2018 InfluxData. All rights reserved. rawkode.flux package rawkode gitHubHandle = “rawkode” h e l l o = ( ) => " H e l l o " awesomeThings = [ "BBQ", " H o t Sauce", “ 🌭 ” ]
  • 14. 15 © 2018 InfluxData. All rights reserved. rawkode.flux package rawkode awesomeise = ( t a b l e = < - ) => { t a b l e |> map( fn : ( r ) => "Awesome" + r ) }
  • 15. 16 © 2018 InfluxData. All rights reserved. FluxREPL rawkode@penguin:~ . / f l u x r e p l > @rawkode.flux > awesomeThings | > awesomeise
  • 16. Limitations Your Flux packages will only be as good as our standard library Flux is still early
  • 18. 19 © 2018 InfluxData. All rights reserved. ➔ CSV ➔ HTTP ➔ InfluxDB ➔ Kafka ➔ Math ➔ SQL ➔ Testing ➔ Will continue to grow … StandardLibrary
  • 19. 20 © 2018 InfluxData. All rights reserved. Math import "math" math.NaN() / / Returns NaN
  • 20. 21 © 2018 InfluxData. All rights reserved. Math import "math" math. s q r t( x: 4.0 ) / / Returns 2.0
  • 21. 22 © 2018 InfluxData. All rights reserved. Strings import " s t r i n g s " s t r i n g s . t i t l e ( v : " a f l u x o f f o x e s " ) / / r e t u r n s "A Flux Of Foxes"
  • 22. 23 © 2018 InfluxData. All rights reserved. CSV import " c s v " c s v . f r o m ( f i l e : " / p a t h / t o / d a t a - f i l e . c s v " ) / / OR c s v . f r o m ( c s v : csvData)
  • 23. 24 © 2018 InfluxData. All rights reserved. Testing import " t e s t i n g " t e s t i n g . a s s e r t E q u a l s ( name: "some t e s t name", g o t : g o t , want: want )
  • 24. https://v2.docs.influxdata.com/ Thank You, Docs Team! The v2 (InfluxDB) docs are a great way to follow up on this:
  • 25. ★ Functional NB: It’s a functional language, by design, as opposed to OOP. I don’t mean “it kinda works” Our Vision is Awesome ★ Flux is a generic data scripting language ★ It does/will support: ○ MySQL / PostgrSQL ○ Prometheus ○ Kafka ○ more!
  • 26. Our Community is Awesome ★ InfluxDB has 373 contributors ★ Telegraf has 520 contributors ★ Together they have over 20k+ stars
  • 28. 29 © 2018 InfluxData. All rights reserved.
  • 29. 30 © 2018 InfluxData. All rights reserved. m ath.flux package math / / b u i l t i n constants b u i l t i n p i / / b u i l t i n f unctions b u i l t i n abs
  • 30. 31 © 2018 InfluxData. All rights reserved. math.go package math func i n i t ( ) { / / constants f l u x . RegisterPackageValue( "math", " p i " , values.NewFloat(math.Pi)) }
  • 31. Math has no rand() What the Flux!
  • 32. NewFunction " g i t h u b . c o m / i n f l u x d a t a / f l u x / v a l u e s "
  • 33. 34 © 2018 InfluxData. All rights reserved. math.go package math func i n i t ( ) { / / constants f l u x . RegisterPackageValue( "math", " p i " , values.NewFloat(math.Pi)) }
  • 34. 35 © 2018 InfluxData. All rights reserved. / / rand f unction math.go package math func i n i t ( ) { / / rand f u n c t i o n flux.RegisterPackageValue ( values. NewFunction( “math”, ???) ) }
  • 35. 36 © 2018 InfluxData. All rights reserved. values.NewFunction ★ Takes 4 parameters ○ Name of function ○ Function signature ○ Actual function + safety harness ○ Side effect boolean
  • 36. 37 © 2018 InfluxData. All rights reserved. ??? ) NewFunction:FunctionName values. NewFunction( " r a n d " , ???, ???,
  • 37. 38 © 2018 InfluxData. All rights reserved. NewFunction:FunctionSignature / / rand wi t h no params semantic.NewFunctionPolyType(semantic.FunctionPolySignature{ Parameters: map[string]semantic.PolyType{}, Return: semantic.UInt, } ) , / / i n Go: func r a n d ( ) u i n t
  • 38. 39 © 2018 InfluxData. All rights reserved. semantic.LabelSet{"max"}, semantic.UInt, Required: Return: } ) , / / in Go: f unc rand(max u i n t ) u i n t NewFunction:FunctionSignature / / rand with 1 param: max semantic.NewFunctionPolyType(semantic.FunctionPolySignature{ Parameters: map[string]semantic.PolyType{ "max": semantic.Int } ,
  • 39. 40 © 2018 InfluxData. All rights reserved. semantic.LabelSet{"min", "max"}, semantic.UInt, Required: Return: } ) , / / in Go: f unc rand(min u i n t , max u i n t ) u i n t NewFunction:FunctionSignature / / rand with 2 param: min, max semantic.NewFunctionPolyType(semantic.FunctionPolySignature{ Parameters: map[string]semantic.PolyType{ "min": semantic.Int, "max": semantic.Int } ,
  • 40. 41 © 2018 InfluxData. All rights reserved. ??? ) NewFunction:FunctionName&Signature values. NewFunction( " r a n d " , semantic. NewFunctionPolyType( … ) ???,
  • 41. 42 © 2018 InfluxData. All rights reserved. goRand : = rand.New(rand.NewSource(...)) NewFunction:Function(NoParams) / / 🌭 No Er r o r Checking 🌭 f u n c ( ) ( v a l u e s . V a l u e , e r r o r ) { goRand : = rand.New(rand.NewSource(...)) r e t u r n values. NewUInt( goRand. I n t n ( 100) ) , n i l }
  • 42. 43 © 2018 InfluxData. All rights reserved. NewFunction:Function(MaxParams) f unc (args values . Objec t ) (values . V al ue , e r r o r ) { max, ok : = args.Get("max") i f ! o k { r e t u r n n i l , errors.New("m issing argument max") } i f m ax.Type().Nature() == s e m a n t i c . I n t { goRand : = rand.New(rand.NewSource(time.Now().UnixNano())) r e t u r n values . NewUInt(goRand .Int n(max. Int())), n i l } r e t u r n n i l , f m t . E r r o r f ( "cannot convert argument o f type %vt o u i n t " , v . T y p e ( ) . N a t u r e ( ) ) }
  • 43. 44 © 2018 InfluxData. All rights reserved. ??? ) NewFunction:FunctionName,Signature,&Function values. NewFunction( " r a n d " , semantic.NewFunctionPolyType( … ) f unc( args values. Object) ( values. Value, e r r o r) { … } ,
  • 44. 45 © 2018 InfluxData. All rights reserved. NewFunction:SideEffect Flux will optimise code that “appears” pointless Using true for this parameter will ensure Flux runs such code “Classical” side-effects apply: network, disk, etc
  • 45. 46 © 2018 InfluxData. All rights reserved. NewFunction:🌟 Completed🌟 values. NewFunction( " r a n d " , semantic.NewFunctionPolyType( … ) f unc( args values. Object) ( values. Value, e r r o r) { … } , f a l s e )
  • 46. 47 © 2018 InfluxData. All rights reserved.
  • 47. 48 © 2018 InfluxData. All rights reserved. Compilation!==UnitTest
  • 48. 49 © 2018 InfluxData. All rights reserved. expected = 100 Test
  • 49. 50 © 2018 InfluxData. All rights reserved. Test f l u x F n = v a lu e s . Ne wF u n c t i o n ( . . . ) f l u x A r g : = values.NewObjectWithValues( m a p [ s t r in g ] v a lu e s . Va lu e { "max": values.NewInt(expected) } ) r e s u l t , e r r : = f l u x F n . C a l l ( f l u x A r g )
  • 51. 52 © 2018 InfluxData. All rights reserved.
  • 52. 53 © 2018 InfluxData. All rights reserved.
  • 53. 54 © 2018 InfluxData. All rights reserved.
  • 56. 57 © 2018 InfluxData. All rights reserved. Extending Flux Shouldn’t Need Go FluxinFlux
  • 57. HTTP Files ENV More Flux Our standard library should allow for you to write Flux extensions without dropping down to Go:
  • 58. e lse o t h e r _ s t u f f More Flux i f 1==1 then s t u f f
  • 59. More Flux { r wit h _value : "Awesome", name: "David McKay"}
  • 60. 61 © 2018 InfluxData. All rights reserved. You shouldn’t need to get your functionality merged into influxdata/flux PackageManagement
  • 61. This will be OSS You’ll be able to run and secure your own Flux Public Repo We’ll provide a public repository for all Flux packages
  • 62. We’ve also seen Cargo and Mix We’ll get this right Flux Public Repo Don’t worry, we’ve all seen what’s happened in Go land
  • 63. 64 © 2018 InfluxData. All rights reserved. Documentation You shouldn’t need to pause this video, browse the standard library, or provide offerings to a deity to know how to do allthis
  • 64. Docs 1. I want to add a source 2. I want to add a sink 3. I want to add a transformation Scenario driven documentation:
  • 65. Docs They’ve already done it* *They’re on it Our docs team areawesome