SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
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!

Contenu connexe

Tendances

A Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINA Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAIN
EDB
 
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...
Modus operandi of Spark Streaming - Recipes for Running your Streaming Applic...
DataWorks Summit
 

Tendances (20)

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...
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
 
Anais Dotis-Georgiou [InfluxData] | Learn Flux by Example | InfluxDays NA 2021
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
 
Time Series Data with InfluxDB
Time Series Data with InfluxDBTime Series Data with InfluxDB
Time Series Data with InfluxDB
 
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 ...
Introduction to InfluxDB, an Open Source Distributed Time Series Database by ...
 
Kapacitor - Real Time Data Processing Engine
Kapacitor - Real Time Data Processing EngineKapacitor - Real Time Data Processing Engine
Kapacitor - Real Time Data Processing Engine
 
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...
Lessons Learned: Running InfluxDB Cloud and Other Cloud Services at Scale | T...
 
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...
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
 
INFLUXQL & TICKSCRIPT
INFLUXQL & TICKSCRIPTINFLUXQL & TICKSCRIPT
INFLUXQL & TICKSCRIPT
 
Monitoring InfluxEnterprise
Monitoring InfluxEnterpriseMonitoring InfluxEnterprise
Monitoring InfluxEnterprise
 
A Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINA Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAIN
 
Wayfair Use Case: The four R's of Metrics Delivery
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
 
Introduction to Flux and Functional Data Scripting
Introduction to Flux and Functional Data ScriptingIntroduction to Flux and Functional Data Scripting
Introduction to Flux and Functional Data Scripting
 
InfluxDB 1.0 - Optimizing InfluxDB by Sam Dillard
InfluxDB 1.0 - Optimizing InfluxDB by Sam DillardInfluxDB 1.0 - Optimizing InfluxDB by Sam Dillard
InfluxDB 1.0 - Optimizing InfluxDB by Sam Dillard
 
Introduction to Flux and Functional Data Scripting
Introduction to Flux and Functional Data ScriptingIntroduction to Flux and Functional Data Scripting
Introduction to Flux and Functional Data Scripting
 
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...
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...
 
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...
Modus operandi of Spark Streaming - Recipes for Running your Streaming Applic...
 
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 ...
Mixing Metrics and Logs with Grafana + Influx by David Kaltschmidt, Director ...
 
Inside the InfluxDB storage engine
Inside the InfluxDB storage engineInside the InfluxDB storage engine
Inside the InfluxDB storage engine
 
Taming the Tiger: Tips and Tricks for Using Telegraf
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
 
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...
InfluxDB IOx Tech Talks: A Rusty Introduction to Apache Arrow and How it App...
 

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

Store and Process Big Data with Hadoop and Cassandra
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 Ariyadewa
 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwr
deimos
 

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

Store and Process Big Data with Hadoop and Cassandra
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
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
 
Flux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul Dix
 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwr
 
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?
What's new with Apache Spark's Structured Streaming?
 
srgoc
srgocsrgoc
srgoc
 
Deeply Declarative Data Pipelines
Deeply Declarative Data PipelinesDeeply Declarative Data Pipelines
Deeply Declarative Data Pipelines
 
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...
Spark Summit EU 2015: Spark DataFrames: Simple and Fast Analysis of Structure...
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
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
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every day
 
Tamir Dresher - What’s new in ASP.NET Core 6
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
 
Apache Flink Stream Processing
Apache Flink Stream ProcessingApache Flink Stream Processing
Apache Flink Stream Processing
 
Meet Up - Spark Stream Processing + Kafka
Meet Up - Spark Stream Processing + KafkaMeet Up - Spark Stream Processing + Kafka
Meet Up - Spark Stream Processing + Kafka
 
Introduction to Spark with Scala
Introduction to Spark with ScalaIntroduction to Spark with Scala
Introduction to Spark with Scala
 
Flink Batch Processing and Iterations
Flink Batch Processing and IterationsFlink Batch Processing and Iterations
Flink Batch Processing and Iterations
 
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache BeamGDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
 

Plus de InfluxData

How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
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 ...
How Delft University's Engineering Students Make Their EV Formula-Style Race ...
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...
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
InfluxData
 
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022
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
InfluxData
 

Plus de InfluxData (20)

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

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

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!