Extending Flux to Support Other Databases and Data Stores | Adam Anthony | InfluxData

InfluxData
InfluxDataInfluxData
Adam Anthony
Software Engineer, Flux team
Extending Flux –
Writing Custom Data
Sources
© InfluxData. All rights reserved.
Why Custom Data Sources
import “sql”
phBalances = from(bucket: "PH_Balances")
|> range(start: now- )
|> filter(fn: (r) => r._measurement == "water_sensor" )
deviceIds = sql.from(driverName: “mysql”,
dataSourceName: “username:password@tcp(host)/dbname”,
query: "SELECT customer_name, customer_location, device_id AS devicen"+
"FROM DeviceTable WHERE customer_name = ‘InfluxData’”)
join(tables: {t : phBalances, t : deviceIds}, on: ["device"])
|> aggregateWindow(every: v.windowPeriod, fn: mean)
|> yield(name: "mean")
© InfluxData. All rights reserved.
Overview
Pre-Demo
Flux Extension landscape
Flux Data Model
Creating tables from scratch
Source Decoder Interface
Row Reader Interface
Example: Promql Ephemeral Scraper
© InfluxData. All rights reserved.
Pre-Demo
● Counting Table Generator
● columns, N rows
● Each row has value +=
© InfluxData. All rights reserved.
Flux Extension Landscape
Write pure flux functions
Port scalar constants and functions from a Go library
Stream transformations
– Go API for processing streams of tables
– Used when pure flux cannot work
Data Sources/Sinks
– If there's a go library for it, you can connect it to Flux
© InfluxData. All rights reserved.
SINKSOURCE
Query Pipeline
from(bucket:
"my-bucket")
range(start: -5m)
filter(fn: (r) =>
r._measurement ==
"m", r._field == "f1")
window(every:5m) mean()
to(bucket:
"my-output")
Sinks may be
● custom writes to persistent storage
● client output (e.g. CSV encoding,
JSON encoding, charts, http, etc.)
© InfluxData. All rights reserved.
Columnar Data Stores
Logical
Joins vs. Aggregates
– Sales Lead vs. Avg Host CPU
1145 US-West nginx.svc 89%
_time Region Host CPU
1146 US-West docker.svc 99%
60%
Mem
99%
Physical
Disk + Memory locality
Cache locality
Data Requirements
© InfluxData. All rights reserved.
Flux Data Model
An infinite stream…
Of Finite tables…
Identified by the GroupKey
Time Host _field Value
10:45 H1A cpu 25.9
11:00 H1A cpu 20.0
GroupKey[Host=H1A,_field]
Time Host _field Value
11:45 H1A mem 18.0
12:00 H1A mem 34.8
GroupKey[Host=H2B,_field]
...
© InfluxData. All rights reserved.
Stream Transformation Process
Time Host Value
10:30 H1A 25.9
10:45 H1A 20.0
GroupKey[Host=H1A]
Time Host Value
11:45 H2B 18.0
11:50 H2B 34.8
GroupKey[Host=H2B]
Time Host Value
10:00 H1A 45.9
GroupKey[Host=H1A]
Time Host Value
11:00 H2B 52.8
GroupKey[Host=H2B]
|> aggregateWindow(every: 60m, fn: sum))
For Each Table:
. Convert
incoming rows
into or more
outgoing rows
. Sort outgoing
rows into tables
© InfluxData. All rights reserved.
CODE ALERT
Counting Table Demo:
● Written in go
● Will Learn:
○ how to create a table
○ how to install the source as a flux function
© InfluxData. All rights reserved.
Building Tables
func BuildStaticTable (keyColumn, valueColumn , key string, nrows int64, a execute.Administration ) (flux.Table, error) {
// 1. group keys help ID a table
groupKey := execute.NewGroupKeyBuilder (nil)
groupKey.AddKeyValue (keyColumn, values. NewString(key))
gk, err := groupKey.Build()
if err != nil { return nil, err }
// 2. Create a new table builder indexed by the group key.
builder := execute.NewColListTableBuilder (gk, a.Allocator())
if _, err = builder. AddCol(flux.ColMeta{Label: keyColumn, Type: flux.TString}); err != nil { return nil, err }
if _, err = builder. AddCol(flux.ColMeta{Label: valueColumn, Type: flux.TFloat}); err != nil { return nil, err }
// 3. Add a row of data by appending one value to each column.
for i := 0; i < int(nrows); i++ {
if err = builder. AppendString (0, key); err != nil { return nil, err
}
if err = builder. AppendFloat (1, float64(i)); err != nil {
return nil, err
}
}
return builder.Table()
}
© InfluxData. All rights reserved.
Implementing Custom Data Sources
type SourceDecoder interface {
// Create a connection to a data source
Connect(ctx context.Context) error
// Fetch all data for a single, complete table
Fetch(ctx context.Context) (bool, error)
// Given data fetched above, decode it into a flux table
Decode(ctx context.Context) (flux.Table, error)
Close() error
}
© InfluxData. All rights reserved.
A First Decoder
type StaticDecoder struct {
administration execute.Administration
keyColumn string
valueColumn string
key string
nrows int64
}
func (s *StaticDecoder) Connect(ctx context.Context) error {
return nil
}
func (s *StaticDecoder) Fetch(ctx context.Context) (bool, error) {
return false, nil
}
func (s *StaticDecoder) Decode(ctx context.Context) (flux.Table, error) {
return BuildStaticTable(s.keyColumn, s.valueColumn, s.key, s.nrows, s.administration)
}
func (s *StaticDecoder) Close() error {
return nil
}
© InfluxData. All rights reserved.
Install A Source Decoder: OpSpec
// unique name for mapping
const FromStaticKind = "fromStatic"
// storing user params that are declared elsewhere
// op spec represents what the user has told us;
type FromStaticOpSpec struct {
nrows int64
}
func createFromStaticOpSpec(args flux.Arguments, administration *flux.Administration) (flux.OperationSpec, error) {
spec := new(FromStaticOpSpec) // reading flux.args and extracting params
var err error
if spec.nrows, err = args.GetRequiredInt("nrows"); err != nil { return nil, err }
return spec, nil
}
func newFromStaticOp() flux.OperationSpec {
return new(FromStaticOpSpec)
}
func (s *FromStaticOpSpec) Kind() flux.OperationKind {
return FromStaticKind
}
● OpSpec: Collect User Parameters and Store for Execution
© InfluxData. All rights reserved.
Install a Source Decoder: Procedure Spec
type FromStaticProcedureSpec struct {
plan.DefaultCost
nrows int64
}
// use op spec to initialize procedure spec
func newFromStaticProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) {
spec, ok := qs.(*FromStaticOpSpec)
if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) }
return &FromStaticProcedureSpec{nrows: spec.nrows},nil
}
func (s *FromStaticProcedureSpec) Kind() plan.ProcedureKind {
return FromStaticKind
}
func (s *FromStaticProcedureSpec) Copy() plan.ProcedureSpec {
ns := new(FromStaticProcedureSpec)
return ns
}
● procedure spec is internal representation of the entire file used by the planner
© InfluxData. All rights reserved.
Install A Source Decoder: Create Source
// uses a procedure spec to create a source object for flux runtime
func createFromStaticSource (prSpec plan.ProcedureSpec, dsid execute.DatasetID, a execute.Administration )
(execute.Source, error) {
spec, ok := prSpec.(*FromStaticProcedureSpec)
if !ok {
return nil, fmt.Errorf("invalid spec type %T", prSpec)
}
StaticDecoder := StaticDecoder{
administration: a,
keyColumn: "T1",
valueColumn: "V1",
key: "tag1",
nrows: spec.nrows}
return execute.CreateSourceFromDecoder (&StaticDecoder, dsid, a)
}
© InfluxData. All rights reserved.
Install A Source Decoder: Register
Constructors
func init() {
fromStaticSignature := semantic.FunctionPolySignature{
Parameters: map[string]semantic.PolyType{
"nrows": semantic.Int,
}, // user params
Required: semantic.LabelSet{"nrows"},
Return: flux.TableObjectType,
}
// tell the flux runtime about the objects that we're creating
flux.RegisterPackageValue("static", "from",
flux.FunctionValue(FromStaticKind, createFromStaticOpSpec, fromStaticSignature))
flux.RegisterOpSpec(FromStaticKind, newFromStaticOp)
plan.RegisterProcedureSpec(FromStaticKind, newFromStaticProcedure, FromStaticKind)
execute.RegisterSource(FromStaticKind, createFromStaticSource)
}
© InfluxData. All rights reserved.
Final Steps
. flux package: flux/stdlib/static/static.flux
. Put `from.go` in same dir
. Flux root dir: run 'make'
. Build Flux/Influxdb binary
© InfluxData. All rights reserved.
Data!
© InfluxData. All rights reserved.
Demo Code
static.from:
https://github.com/influxdata/flux/tree/demo/influxdaysSFO2019
prometheus.scrape:
https://github.com/influxdata/flux/blob/cb2d438ac7881c794c8a2982618e81503b4f2781
/stdlib/experimental/prometheus/scrape.go
© InfluxData. All rights reserved.
Not Covered
● Writing data out.
○ Modeled after a normal flux function that sends data out as a side
effect
○ For each table:
i. Collect rows from a flux.table into a write request for your data destination
ii. Send the request
● Alternate Interface: RowIterator
© InfluxData. All rights reserved.
If you can connect to a data source in `go` you can write a
source/sink for it in flux.
● Currently, we can read from:
○ influxdb
○ mysql
○ postgres
○ BigTable
○ CSV
○ Prometheus
● Currently we can write to:
○ influxdb
○ mysql
○ postgres
○ MQTT
○ kafka
Contributions are welcome!
Thank You!
1 of 23

Recommended

Creating and Using the Flux SQL Datasource | Katy Farmer | InfluxData by
Creating and Using the Flux SQL Datasource | Katy Farmer | InfluxData Creating and Using the Flux SQL Datasource | Katy Farmer | InfluxData
Creating and Using the Flux SQL Datasource | Katy Farmer | InfluxData InfluxData
410 views18 slides
9:40 am InfluxDB 2.0 and Flux – The Road Ahead Paul Dix, Founder and CTO | ... by
 9:40 am InfluxDB 2.0 and Flux – The Road Ahead  Paul Dix, Founder and CTO | ... 9:40 am InfluxDB 2.0 and Flux – The Road Ahead  Paul Dix, Founder and CTO | ...
9:40 am InfluxDB 2.0 and Flux – The Road Ahead Paul Dix, Founder and CTO | ...InfluxData
493 views87 slides
Observability of InfluxDB IOx: Tracing, Metrics and System Tables by
Observability of InfluxDB IOx: Tracing, Metrics and System TablesObservability of InfluxDB IOx: Tracing, Metrics and System Tables
Observability of InfluxDB IOx: Tracing, Metrics and System TablesInfluxData
440 views29 slides
Let's Compare: A Benchmark review of InfluxDB and Elasticsearch by
Let's Compare: A Benchmark review of InfluxDB and ElasticsearchLet's Compare: A Benchmark review of InfluxDB and Elasticsearch
Let's Compare: A Benchmark review of InfluxDB and ElasticsearchInfluxData
4.1K views23 slides
Obtaining the Perfect Smoke By Monitoring Your BBQ with InfluxDB and Telegraf by
Obtaining the Perfect Smoke By Monitoring Your BBQ with InfluxDB and TelegrafObtaining the Perfect Smoke By Monitoring Your BBQ with InfluxDB and Telegraf
Obtaining the Perfect Smoke By Monitoring Your BBQ with InfluxDB and TelegrafInfluxData
346 views60 slides
InfluxDB IOx Tech Talks: Query Processing in InfluxDB IOx by
InfluxDB IOx Tech Talks: Query Processing in InfluxDB IOxInfluxDB IOx Tech Talks: Query Processing in InfluxDB IOx
InfluxDB IOx Tech Talks: Query Processing in InfluxDB IOxInfluxData
478 views30 slides

More Related Content

What's hot

Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira... by
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...InfluxData
329 views25 slides
Anais Dotis-Georgiou [InfluxData] | Learn Flux by Example | InfluxDays NA 2021 by
Anais Dotis-Georgiou [InfluxData] | Learn Flux by Example | InfluxDays NA 2021Anais Dotis-Georgiou [InfluxData] | Learn Flux by Example | InfluxDays NA 2021
Anais Dotis-Georgiou [InfluxData] | Learn Flux by Example | InfluxDays NA 2021InfluxData
225 views69 slides
Time Series Data with InfluxDB by
Time Series Data with InfluxDBTime Series Data with InfluxDB
Time Series Data with InfluxDBTuri, Inc.
6.3K views59 slides
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ... by
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...Hakka Labs
30K views67 slides
Kapacitor - Real Time Data Processing Engine by
Kapacitor - Real Time Data Processing EngineKapacitor - Real Time Data Processing Engine
Kapacitor - Real Time Data Processing EnginePrashant Vats
1.9K views21 slides
Lessons Learned: Running InfluxDB Cloud and Other Cloud Services at Scale | T... by
Lessons Learned: Running InfluxDB Cloud and Other Cloud Services at Scale | T...Lessons Learned: Running InfluxDB Cloud and Other Cloud Services at Scale | T...
Lessons Learned: Running InfluxDB Cloud and Other Cloud Services at Scale | T...InfluxData
380 views30 slides

What's hot(20)

Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira... by InfluxData
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
InfluxData329 views
Anais Dotis-Georgiou [InfluxData] | Learn Flux by Example | InfluxDays NA 2021 by InfluxData
Anais Dotis-Georgiou [InfluxData] | Learn Flux by Example | InfluxDays NA 2021Anais Dotis-Georgiou [InfluxData] | Learn Flux by Example | InfluxDays NA 2021
Anais Dotis-Georgiou [InfluxData] | Learn Flux by Example | InfluxDays NA 2021
InfluxData225 views
Time Series Data with InfluxDB by Turi, Inc.
Time Series Data with InfluxDBTime Series Data with InfluxDB
Time Series Data with InfluxDB
Turi, Inc.6.3K views
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ... by Hakka Labs
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
Hakka Labs30K views
Kapacitor - Real Time Data Processing Engine by Prashant Vats
Kapacitor - Real Time Data Processing EngineKapacitor - Real Time Data Processing Engine
Kapacitor - Real Time Data Processing Engine
Prashant Vats1.9K views
Lessons Learned: Running InfluxDB Cloud and Other Cloud Services at Scale | T... by InfluxData
Lessons Learned: Running InfluxDB Cloud and Other Cloud Services at Scale | T...Lessons Learned: Running InfluxDB Cloud and Other Cloud Services at Scale | T...
Lessons Learned: Running InfluxDB Cloud and Other Cloud Services at Scale | T...
InfluxData380 views
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in... by InfluxData
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
InfluxData3.6K views
INFLUXQL & TICKSCRIPT by InfluxData
INFLUXQL & TICKSCRIPTINFLUXQL & TICKSCRIPT
INFLUXQL & TICKSCRIPT
InfluxData1.6K views
Monitoring InfluxEnterprise by InfluxData
Monitoring InfluxEnterpriseMonitoring InfluxEnterprise
Monitoring InfluxEnterprise
InfluxData654 views
A Deeper Dive into EXPLAIN by EDB
A Deeper Dive into EXPLAINA Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAIN
EDB176 views
Wayfair Use Case: The four R's of Metrics Delivery by InfluxData
Wayfair Use Case: The four R's of Metrics DeliveryWayfair Use Case: The four R's of Metrics Delivery
Wayfair Use Case: The four R's of Metrics Delivery
InfluxData1.1K views
Introduction to Flux and Functional Data Scripting by InfluxData
Introduction to Flux and Functional Data ScriptingIntroduction to Flux and Functional Data Scripting
Introduction to Flux and Functional Data Scripting
InfluxData264 views
InfluxDB 1.0 - Optimizing InfluxDB by Sam Dillard by InfluxData
InfluxDB 1.0 - Optimizing InfluxDB by Sam DillardInfluxDB 1.0 - Optimizing InfluxDB by Sam Dillard
InfluxDB 1.0 - Optimizing InfluxDB by Sam Dillard
InfluxData520 views
Introduction to Flux and Functional Data Scripting by InfluxData
Introduction to Flux and Functional Data ScriptingIntroduction to Flux and Functional Data Scripting
Introduction to Flux and Functional Data Scripting
InfluxData243 views
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te... by InfluxData
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...
InfluxData664 views
Modus operandi of Spark Streaming - Recipes for Running your Streaming Applic... by DataWorks Summit
Modus operandi of Spark Streaming - Recipes for Running your Streaming Applic...Modus operandi of Spark Streaming - Recipes for Running your Streaming Applic...
Modus operandi of Spark Streaming - Recipes for Running your Streaming Applic...
DataWorks Summit2.7K views
Mixing Metrics and Logs with Grafana + Influx by David Kaltschmidt, Director ... by InfluxData
Mixing Metrics and Logs with Grafana + Influx by David Kaltschmidt, Director ...Mixing Metrics and Logs with Grafana + Influx by David Kaltschmidt, Director ...
Mixing Metrics and Logs with Grafana + Influx by David Kaltschmidt, Director ...
InfluxData1.6K views
Inside the InfluxDB storage engine by InfluxData
Inside the InfluxDB storage engineInside the InfluxDB storage engine
Inside the InfluxDB storage engine
InfluxData4K views
Taming the Tiger: Tips and Tricks for Using Telegraf by InfluxData
Taming the Tiger: Tips and Tricks for Using TelegrafTaming the Tiger: Tips and Tricks for Using Telegraf
Taming the Tiger: Tips and Tricks for Using Telegraf
InfluxData146 views
InfluxDB IOx Tech Talks: A Rusty Introduction to Apache Arrow and How it App... by InfluxData
InfluxDB IOx Tech Talks:  A Rusty Introduction to Apache Arrow and How it App...InfluxDB IOx Tech Talks:  A Rusty Introduction to Apache Arrow and How it App...
InfluxDB IOx Tech Talks: A Rusty Introduction to Apache Arrow and How it App...
InfluxData343 views

Similar to Extending Flux to Support Other Databases and Data Stores | Adam Anthony | InfluxData

Store and Process Big Data with Hadoop and Cassandra by
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraDeependra Ariyadewa
5.8K views23 slides
Job Queue in Golang by
Job Queue in GolangJob Queue in Golang
Job Queue in GolangBo-Yi Wu
22.3K views82 slides
Think Async: Asynchronous Patterns in NodeJS by
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSAdam L Barrett
282 views77 slides
Flux and InfluxDB 2.0 by Paul Dix by
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixInfluxData
1.3K views85 slides
Joe Walker Interactivewebsites Cometand Dwr by
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwrdeimos
1.6K views49 slides
What's new with Apache Spark's Structured Streaming? by
What's new with Apache Spark's Structured Streaming?What's new with Apache Spark's Structured Streaming?
What's new with Apache Spark's Structured Streaming?Miklos Christine
2K views49 slides

Similar to Extending Flux to Support Other Databases and Data Stores | Adam Anthony | InfluxData(20)

Store and Process Big Data with Hadoop and Cassandra by Deependra Ariyadewa
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
Deependra Ariyadewa5.8K views
Job Queue in Golang by Bo-Yi Wu
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
Bo-Yi Wu22.3K views
Think Async: Asynchronous Patterns in NodeJS by Adam L Barrett
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
Adam L Barrett282 views
Flux and InfluxDB 2.0 by Paul Dix by InfluxData
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul Dix
InfluxData1.3K views
Joe Walker Interactivewebsites Cometand Dwr by deimos
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwr
deimos1.6K views
What's new with Apache Spark's Structured Streaming? by Miklos Christine
What's new with Apache Spark's Structured Streaming?What's new with Apache Spark's Structured Streaming?
What's new with Apache Spark's Structured Streaming?
Miklos Christine2K views
Spark Summit EU 2015: Spark DataFrames: Simple and Fast Analysis of Structure... by Databricks
Spark Summit EU 2015: Spark DataFrames: Simple and Fast Analysis of Structure...Spark Summit EU 2015: Spark DataFrames: Simple and Fast Analysis of Structure...
Spark Summit EU 2015: Spark DataFrames: Simple and Fast Analysis of Structure...
Databricks13.7K views
2 BytesC++ course_2014_c3_ function basics&parameters and overloading by kinan keshkeh
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
kinan keshkeh321 views
Non Blocking I/O for Everyone with RxJava by Frank Lyaruu
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
Frank Lyaruu2K views
Reactive programming every day by Vadym Khondar
Reactive programming every dayReactive programming every day
Reactive programming every day
Vadym Khondar463 views
Tamir Dresher - What’s new in ASP.NET Core 6 by Tamir Dresher
Tamir Dresher - What’s new in ASP.NET Core 6Tamir Dresher - What’s new in ASP.NET Core 6
Tamir Dresher - What’s new in ASP.NET Core 6
Tamir Dresher134 views
Apache Flink Stream Processing by Suneel Marthi
Apache Flink Stream ProcessingApache Flink Stream Processing
Apache Flink Stream Processing
Suneel Marthi1.4K views
Meet Up - Spark Stream Processing + Kafka by Knoldus Inc.
Meet Up - Spark Stream Processing + KafkaMeet Up - Spark Stream Processing + Kafka
Meet Up - Spark Stream Processing + Kafka
Knoldus Inc.7.6K views
Introduction to Spark with Scala by Himanshu Gupta
Introduction to Spark with ScalaIntroduction to Spark with Scala
Introduction to Spark with Scala
Himanshu Gupta6.7K views
Flink Batch Processing and Iterations by Sameer Wadkar
Flink Batch Processing and IterationsFlink Batch Processing and Iterations
Flink Batch Processing and Iterations
Sameer Wadkar3.5K views
GDG Jakarta Meetup - Streaming Analytics With Apache Beam by Imre Nagi
GDG Jakarta Meetup - Streaming Analytics With Apache BeamGDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
Imre Nagi413 views
Lo Mejor Del Pdc2008 El Futrode C# by Juan Pablo
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
Juan Pablo 412 views
Dynamic C++ ACCU 2013 by aleks-f
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
aleks-f4.4K views

More from InfluxData

Announcing InfluxDB Clustered by
Announcing InfluxDB ClusteredAnnouncing InfluxDB Clustered
Announcing InfluxDB ClusteredInfluxData
100 views30 slides
Best Practices for Leveraging the Apache Arrow Ecosystem by
Best Practices for Leveraging the Apache Arrow EcosystemBest Practices for Leveraging the Apache Arrow Ecosystem
Best Practices for Leveraging the Apache Arrow EcosystemInfluxData
50 views25 slides
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu... by
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...InfluxData
134 views24 slides
Power Your Predictive Analytics with InfluxDB by
Power Your Predictive Analytics with InfluxDBPower Your Predictive Analytics with InfluxDB
Power Your Predictive Analytics with InfluxDBInfluxData
127 views41 slides
Build an Edge-to-Cloud Solution with the MING Stack by
Build an Edge-to-Cloud Solution with the MING StackBuild an Edge-to-Cloud Solution with the MING Stack
Build an Edge-to-Cloud Solution with the MING StackInfluxData
375 views52 slides
Meet the Founders: An Open Discussion About Rewriting Using Rust by
Meet the Founders: An Open Discussion About Rewriting Using RustMeet the Founders: An Open Discussion About Rewriting Using Rust
Meet the Founders: An Open Discussion About Rewriting Using RustInfluxData
235 views12 slides

More from InfluxData(20)

Announcing InfluxDB Clustered by InfluxData
Announcing InfluxDB ClusteredAnnouncing InfluxDB Clustered
Announcing InfluxDB Clustered
InfluxData100 views
Best Practices for Leveraging the Apache Arrow Ecosystem by InfluxData
Best Practices for Leveraging the Apache Arrow EcosystemBest Practices for Leveraging the Apache Arrow Ecosystem
Best Practices for Leveraging the Apache Arrow Ecosystem
InfluxData50 views
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu... by InfluxData
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...
InfluxData134 views
Power Your Predictive Analytics with InfluxDB by InfluxData
Power Your Predictive Analytics with InfluxDBPower Your Predictive Analytics with InfluxDB
Power Your Predictive Analytics with InfluxDB
InfluxData127 views
Build an Edge-to-Cloud Solution with the MING Stack by InfluxData
Build an Edge-to-Cloud Solution with the MING StackBuild an Edge-to-Cloud Solution with the MING Stack
Build an Edge-to-Cloud Solution with the MING Stack
InfluxData375 views
Meet the Founders: An Open Discussion About Rewriting Using Rust by InfluxData
Meet the Founders: An Open Discussion About Rewriting Using RustMeet the Founders: An Open Discussion About Rewriting Using Rust
Meet the Founders: An Open Discussion About Rewriting Using Rust
InfluxData235 views
Introducing InfluxDB Cloud Dedicated by InfluxData
Introducing InfluxDB Cloud DedicatedIntroducing InfluxDB Cloud Dedicated
Introducing InfluxDB Cloud Dedicated
InfluxData129 views
Gain Better Observability with OpenTelemetry and InfluxDB by InfluxData
Gain Better Observability with OpenTelemetry and InfluxDB Gain Better Observability with OpenTelemetry and InfluxDB
Gain Better Observability with OpenTelemetry and InfluxDB
InfluxData392 views
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali... by InfluxData
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
InfluxData182 views
How Delft University's Engineering Students Make Their EV Formula-Style Race ... by InfluxData
How Delft University's Engineering Students Make Their EV Formula-Style Race ...How Delft University's Engineering Students Make Their EV Formula-Style Race ...
How Delft University's Engineering Students Make Their EV Formula-Style Race ...
InfluxData105 views
Start Automating InfluxDB Deployments at the Edge with balena by InfluxData
Start Automating InfluxDB Deployments at the Edge with balena Start Automating InfluxDB Deployments at the Edge with balena
Start Automating InfluxDB Deployments at the Edge with balena
InfluxData185 views
Understanding InfluxDB’s New Storage Engine by InfluxData
Understanding InfluxDB’s New Storage EngineUnderstanding InfluxDB’s New Storage Engine
Understanding InfluxDB’s New Storage Engine
InfluxData134 views
Streamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDB by InfluxData
Streamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDBStreamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDB
Streamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDB
InfluxData63 views
Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa... by InfluxData
Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...
Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...
InfluxData74 views
Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022 by InfluxData
Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022
Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022
InfluxData26 views
Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022 by InfluxData
Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022
InfluxData9 views
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ... by InfluxData
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
InfluxData10 views
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022 by InfluxData
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022
InfluxData5 views
Paul Dix [InfluxData] The Journey of InfluxDB | InfluxDays 2022 by InfluxData
Paul Dix [InfluxData] The Journey of InfluxDB | InfluxDays 2022Paul Dix [InfluxData] The Journey of InfluxDB | InfluxDays 2022
Paul Dix [InfluxData] The Journey of InfluxDB | InfluxDays 2022
InfluxData112 views
Jay Clifford [InfluxData] | Tips & Tricks for Analyzing IIoT in Real-Time | I... by InfluxData
Jay Clifford [InfluxData] | Tips & Tricks for Analyzing IIoT in Real-Time | I...Jay Clifford [InfluxData] | Tips & Tricks for Analyzing IIoT in Real-Time | I...
Jay Clifford [InfluxData] | Tips & Tricks for Analyzing IIoT in Real-Time | I...
InfluxData19 views

Recently uploaded

Future of Indian ConsumerTech by
Future of Indian ConsumerTechFuture of Indian ConsumerTech
Future of Indian ConsumerTechKapil Khandelwal (KK)
21 views68 slides
Uni Systems for Power Platform.pptx by
Uni Systems for Power Platform.pptxUni Systems for Power Platform.pptx
Uni Systems for Power Platform.pptxUni Systems S.M.S.A.
56 views21 slides
The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
80 views25 slides
Attacking IoT Devices from a Web Perspective - Linux Day by
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day Simone Onofri
16 views68 slides
Design Driven Network Assurance by
Design Driven Network AssuranceDesign Driven Network Assurance
Design Driven Network AssuranceNetwork Automation Forum
15 views42 slides
Five Things You SHOULD Know About Postman by
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About PostmanPostman
33 views43 slides

Recently uploaded(20)

Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri16 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman33 views
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 views
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 views
Serverless computing with Google Cloud (2023-24) by wesley chun
Serverless computing with Google Cloud (2023-24)Serverless computing with Google Cloud (2023-24)
Serverless computing with Google Cloud (2023-24)
wesley chun11 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi127 views
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma39 views

Extending Flux to Support Other Databases and Data Stores | Adam Anthony | InfluxData

  • 1. Adam Anthony Software Engineer, Flux team Extending Flux – Writing Custom Data Sources
  • 2. © InfluxData. All rights reserved. Why Custom Data Sources import “sql” phBalances = from(bucket: "PH_Balances") |> range(start: now- ) |> filter(fn: (r) => r._measurement == "water_sensor" ) deviceIds = sql.from(driverName: “mysql”, dataSourceName: “username:password@tcp(host)/dbname”, query: "SELECT customer_name, customer_location, device_id AS devicen"+ "FROM DeviceTable WHERE customer_name = ‘InfluxData’”) join(tables: {t : phBalances, t : deviceIds}, on: ["device"]) |> aggregateWindow(every: v.windowPeriod, fn: mean) |> yield(name: "mean")
  • 3. © InfluxData. All rights reserved. Overview Pre-Demo Flux Extension landscape Flux Data Model Creating tables from scratch Source Decoder Interface Row Reader Interface Example: Promql Ephemeral Scraper
  • 4. © InfluxData. All rights reserved. Pre-Demo ● Counting Table Generator ● columns, N rows ● Each row has value +=
  • 5. © InfluxData. All rights reserved. Flux Extension Landscape Write pure flux functions Port scalar constants and functions from a Go library Stream transformations – Go API for processing streams of tables – Used when pure flux cannot work Data Sources/Sinks – If there's a go library for it, you can connect it to Flux
  • 6. © InfluxData. All rights reserved. SINKSOURCE Query Pipeline from(bucket: "my-bucket") range(start: -5m) filter(fn: (r) => r._measurement == "m", r._field == "f1") window(every:5m) mean() to(bucket: "my-output") Sinks may be ● custom writes to persistent storage ● client output (e.g. CSV encoding, JSON encoding, charts, http, etc.)
  • 7. © InfluxData. All rights reserved. Columnar Data Stores Logical Joins vs. Aggregates – Sales Lead vs. Avg Host CPU 1145 US-West nginx.svc 89% _time Region Host CPU 1146 US-West docker.svc 99% 60% Mem 99% Physical Disk + Memory locality Cache locality Data Requirements
  • 8. © InfluxData. All rights reserved. Flux Data Model An infinite stream… Of Finite tables… Identified by the GroupKey Time Host _field Value 10:45 H1A cpu 25.9 11:00 H1A cpu 20.0 GroupKey[Host=H1A,_field] Time Host _field Value 11:45 H1A mem 18.0 12:00 H1A mem 34.8 GroupKey[Host=H2B,_field] ...
  • 9. © InfluxData. All rights reserved. Stream Transformation Process Time Host Value 10:30 H1A 25.9 10:45 H1A 20.0 GroupKey[Host=H1A] Time Host Value 11:45 H2B 18.0 11:50 H2B 34.8 GroupKey[Host=H2B] Time Host Value 10:00 H1A 45.9 GroupKey[Host=H1A] Time Host Value 11:00 H2B 52.8 GroupKey[Host=H2B] |> aggregateWindow(every: 60m, fn: sum)) For Each Table: . Convert incoming rows into or more outgoing rows . Sort outgoing rows into tables
  • 10. © InfluxData. All rights reserved. CODE ALERT Counting Table Demo: ● Written in go ● Will Learn: ○ how to create a table ○ how to install the source as a flux function
  • 11. © InfluxData. All rights reserved. Building Tables func BuildStaticTable (keyColumn, valueColumn , key string, nrows int64, a execute.Administration ) (flux.Table, error) { // 1. group keys help ID a table groupKey := execute.NewGroupKeyBuilder (nil) groupKey.AddKeyValue (keyColumn, values. NewString(key)) gk, err := groupKey.Build() if err != nil { return nil, err } // 2. Create a new table builder indexed by the group key. builder := execute.NewColListTableBuilder (gk, a.Allocator()) if _, err = builder. AddCol(flux.ColMeta{Label: keyColumn, Type: flux.TString}); err != nil { return nil, err } if _, err = builder. AddCol(flux.ColMeta{Label: valueColumn, Type: flux.TFloat}); err != nil { return nil, err } // 3. Add a row of data by appending one value to each column. for i := 0; i < int(nrows); i++ { if err = builder. AppendString (0, key); err != nil { return nil, err } if err = builder. AppendFloat (1, float64(i)); err != nil { return nil, err } } return builder.Table() }
  • 12. © InfluxData. All rights reserved. Implementing Custom Data Sources type SourceDecoder interface { // Create a connection to a data source Connect(ctx context.Context) error // Fetch all data for a single, complete table Fetch(ctx context.Context) (bool, error) // Given data fetched above, decode it into a flux table Decode(ctx context.Context) (flux.Table, error) Close() error }
  • 13. © InfluxData. All rights reserved. A First Decoder type StaticDecoder struct { administration execute.Administration keyColumn string valueColumn string key string nrows int64 } func (s *StaticDecoder) Connect(ctx context.Context) error { return nil } func (s *StaticDecoder) Fetch(ctx context.Context) (bool, error) { return false, nil } func (s *StaticDecoder) Decode(ctx context.Context) (flux.Table, error) { return BuildStaticTable(s.keyColumn, s.valueColumn, s.key, s.nrows, s.administration) } func (s *StaticDecoder) Close() error { return nil }
  • 14. © InfluxData. All rights reserved. Install A Source Decoder: OpSpec // unique name for mapping const FromStaticKind = "fromStatic" // storing user params that are declared elsewhere // op spec represents what the user has told us; type FromStaticOpSpec struct { nrows int64 } func createFromStaticOpSpec(args flux.Arguments, administration *flux.Administration) (flux.OperationSpec, error) { spec := new(FromStaticOpSpec) // reading flux.args and extracting params var err error if spec.nrows, err = args.GetRequiredInt("nrows"); err != nil { return nil, err } return spec, nil } func newFromStaticOp() flux.OperationSpec { return new(FromStaticOpSpec) } func (s *FromStaticOpSpec) Kind() flux.OperationKind { return FromStaticKind } ● OpSpec: Collect User Parameters and Store for Execution
  • 15. © InfluxData. All rights reserved. Install a Source Decoder: Procedure Spec type FromStaticProcedureSpec struct { plan.DefaultCost nrows int64 } // use op spec to initialize procedure spec func newFromStaticProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*FromStaticOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) } return &FromStaticProcedureSpec{nrows: spec.nrows},nil } func (s *FromStaticProcedureSpec) Kind() plan.ProcedureKind { return FromStaticKind } func (s *FromStaticProcedureSpec) Copy() plan.ProcedureSpec { ns := new(FromStaticProcedureSpec) return ns } ● procedure spec is internal representation of the entire file used by the planner
  • 16. © InfluxData. All rights reserved. Install A Source Decoder: Create Source // uses a procedure spec to create a source object for flux runtime func createFromStaticSource (prSpec plan.ProcedureSpec, dsid execute.DatasetID, a execute.Administration ) (execute.Source, error) { spec, ok := prSpec.(*FromStaticProcedureSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", prSpec) } StaticDecoder := StaticDecoder{ administration: a, keyColumn: "T1", valueColumn: "V1", key: "tag1", nrows: spec.nrows} return execute.CreateSourceFromDecoder (&StaticDecoder, dsid, a) }
  • 17. © InfluxData. All rights reserved. Install A Source Decoder: Register Constructors func init() { fromStaticSignature := semantic.FunctionPolySignature{ Parameters: map[string]semantic.PolyType{ "nrows": semantic.Int, }, // user params Required: semantic.LabelSet{"nrows"}, Return: flux.TableObjectType, } // tell the flux runtime about the objects that we're creating flux.RegisterPackageValue("static", "from", flux.FunctionValue(FromStaticKind, createFromStaticOpSpec, fromStaticSignature)) flux.RegisterOpSpec(FromStaticKind, newFromStaticOp) plan.RegisterProcedureSpec(FromStaticKind, newFromStaticProcedure, FromStaticKind) execute.RegisterSource(FromStaticKind, createFromStaticSource) }
  • 18. © InfluxData. All rights reserved. Final Steps . flux package: flux/stdlib/static/static.flux . Put `from.go` in same dir . Flux root dir: run 'make' . Build Flux/Influxdb binary
  • 19. © InfluxData. All rights reserved. Data!
  • 20. © InfluxData. All rights reserved. Demo Code static.from: https://github.com/influxdata/flux/tree/demo/influxdaysSFO2019 prometheus.scrape: https://github.com/influxdata/flux/blob/cb2d438ac7881c794c8a2982618e81503b4f2781 /stdlib/experimental/prometheus/scrape.go
  • 21. © InfluxData. All rights reserved. Not Covered ● Writing data out. ○ Modeled after a normal flux function that sends data out as a side effect ○ For each table: i. Collect rows from a flux.table into a write request for your data destination ii. Send the request ● Alternate Interface: RowIterator
  • 22. © InfluxData. All rights reserved. If you can connect to a data source in `go` you can write a source/sink for it in flux. ● Currently, we can read from: ○ influxdb ○ mysql ○ postgres ○ BigTable ○ CSV ○ Prometheus ● Currently we can write to: ○ influxdb ○ mysql ○ postgres ○ MQTT ○ kafka Contributions are welcome!