SlideShare a Scribd company logo
Julius Volz - Prometheus Co-Founder
Creating the PromQL
Transpiler for Flux
Overview
InfluxDB as long-term storage for Prometheus
Reuse Prometheus Grafana dashboards with InfluxDB?
🠆 Support PromQL in InfluxDB via Flux! Build a transpiler.
Prometheus
Motivation
Grafana
PromQL
query write
InfluxDB as long-term storage for Prometheus
Reuse Prometheus Grafana dashboards with InfluxDB?
🠆 Support PromQL in InfluxDB via Flux! Build a transpiler.
Prometheus
Motivation
Grafana
PromQL
query write
What Needs to be Done?
Simple spec on the surface:
...such that results are equivalent (what does this mean?)
AST = Abstract Syntax Tree
Transpiler
PromQL
AST
Flux
AST
Input Output
What Needs to be Done?
Simple spec on the surface:
...such that results are equivalent (what does this mean?)
AST = Abstract Syntax Tree
Transpiler
PromQL
AST
Flux
AST
Input Output
Hidden Questions
How to map the data models?
Is every feature translatable?
If not, can we approximate it?
Hidden Questions
How to map the data models?
Is every feature translatable?
If not, can we approximate it?
Additionally...
Make it usable:
● Add PromQL HTTP API to InfluxDB
● Allow data ingestion in expected format
Additionally...
Make it usable:
● Add PromQL HTTP API to InfluxDB
● Allow data ingestion in expected format
Integrating Everything
Prometheus
Grafana PromQL API Transpiler
Flux EngineResult Converter
PromQL AST
Flux AST
Flux result
PromQL result
DBData Mapper
Series data
Query
Store data
PromQL
Query
Integrating Everything
Prometheus
Grafana PromQL API Transpiler
Flux EngineResult Converter
PromQL AST
Flux AST
Flux result
PromQL result
DBData Mapper
Series data
Query
Store data
PromQL
Query
Challenges
● Need to know both Flux and PromQL
● Early days for Flux
● Different data and query models
Challenges
● Need to know both Flux and PromQL
● Early days for Flux
● Different data and query models
Data Models
Data Model: Prometheus
Only metrics / time series
No logs / events
Data Model: Prometheus
Only metrics / time series
No logs / events
Data Model: Prometheus
Series identified once, then multiple timestamp / value pairs:
<identifier> → [ (t0, v0), (t1, v1), … ]
What is this? int64 (ms) float64
Data Model: Prometheus
Series identified once, then multiple timestamp / value pairs:
<identifier> → [ (t0, v0), (t1, v1), … ]
What is this? int64 (ms) float64
Data Model: Prometheus
How are series identified?
http_requests_total{job="nginx",instance="1.2.3.4:80",path="/home"}
metric name labels
Data Model: Prometheus
How are series identified?
http_requests_total{job="nginx",instance="1.2.3.4:80",path="/home"}
metric name labels
Data Model: Flux
For both events and metrics
Data Model: Flux
For both events and metrics
Data Model: Flux (Briefly)
Stream: set of tables
Tables: typed columns, grouping key, and records
Columns: 8 different data types (+ values can also be null)
Special columns: _time, _start, _stop, _measurement, _field
Data Model: Flux (Briefly)
Stream: set of tables
Tables: typed columns, grouping key, and records
Columns: 8 different data types (+ values can also be null)
Special columns: _time, _start, _stop, _measurement, _field
Data Model Mapping
● Metric name 🠆 _field
● _measurement = "prometheus" (see Telegraf #4415)
● Label name 🠆 column name (exception: _foo 🠆 ~_foo)
● Label value 🠆 column value
● Sample value 🠆 _value
● Sample timestamp 🠆 _time
Data Model Mapping
● Metric name 🠆 _field
● _measurement = "prometheus" (see Telegraf #4415)
● Label name 🠆 column name (exception: _foo 🠆 ~_foo)
● Label value 🠆 column value
● Sample value 🠆 _value
● Sample timestamp 🠆 _time
Data Model Mapping Example
http_requests_total{method="POST"}
🠆 1043.0 @ 1550767776.382
🠆 1070.0 @ 1550767786.344
🠆 ...
Column
name
_measurement method _field _start _stop _time _value
Grouping
key?
true true true true true false false
Column
type
string string string time time time float
"prometheus" "POST" "http_requests_total" 2019-02-21T16:49:00Z 2019-02-21T16:50:00Z 2019-02-21T16:49:36.382Z 1043.0
"prometheus" "POST" "http_requests_total" 2019-02-21T16:49:00Z 2019-02-21T16:50:00Z 2019-02-21T16:49:46.382Z 1070.0
... ... ... ... ... ... ...
Data Model Mapping Example
http_requests_total{method="POST"}
🠆 1043.0 @ 1550767776.382
🠆 1070.0 @ 1550767786.344
🠆 ...
Column
name
_measurement method _field _start _stop _time _value
Grouping
key?
true true true true true false false
Column
type
string string string time time time float
"prometheus" "POST" "http_requests_total" 2019-02-21T16:49:00Z 2019-02-21T16:50:00Z 2019-02-21T16:49:36.382Z 1043.0
"prometheus" "POST" "http_requests_total" 2019-02-21T16:49:00Z 2019-02-21T16:50:00Z 2019-02-21T16:49:46.382Z 1070.0
... ... ... ... ... ... ...
Query Models
PromQL Query Types
Instant Queries
+
Range Queries
PromQL Query Types
Instant Queries
+
Range Queries
PromQL Instant Queries
Evaluate PromQL
expression at single
timestamp:
PromQL Instant Queries
Evaluate PromQL
expression at single
timestamp:
PromQL Instant Queries
Input:
● PromQL Expression
● Evaluation timestamp
Output:
List of result time series:
● Single sample for each series (for vector selectors)
● Output timestamp is evaluation timestamp
PromQL Instant Queries
Input:
● PromQL Expression
● Evaluation timestamp
Output:
List of result time series:
● Single sample for each series (for vector selectors)
● Output timestamp is evaluation timestamp
Instant Query Example
Simplest Example: Series selection
Instant Query Example
Simplest Example: Series selection
Raw DataRaw Data
Instant Query Example: http_requests_totalInstant Query Example: http_requests_total
Instant Query Example: http_requests_total (Result)Instant Query Example: http_requests_total (Result)
Instant Query Example: http_requests_totalInstant Query Example: http_requests_total
Instant Query Example: http_requests_total (Empty Result)Instant Query Example: http_requests_total (Empty Result)
PromQL Range Queries
Evaluate PromQL
expression at several
timestamps along a
range:
PromQL Range Queries
Evaluate PromQL
expression at several
timestamps along a
range:
PromQL Range Queries
Semantically: Many subsequent instant queries
Under the hood: Optimized
PromQL Range Queries
Semantically: Many subsequent instant queries
Under the hood: Optimized
PromQL Range Queries
Input:
● PromQL Expression
● Time range (start, end)
● Step (output resolution)
Output:
List of result time series:
● Multiple samples for each series
PromQL Range Queries
Input:
● PromQL Expression
● Time range (start, end)
● Step (output resolution)
Output:
List of result time series:
● Multiple samples for each series
Raw DataRaw Data
Range Query Example: http_requests_totalRange Query Example: http_requests_total
Range Query Example: http_requests_total (Results)Range Query Example: http_requests_total (Results)
Flux Query Model (Briefly)
Input:
● Flux script: contains both data source (bucket) and all time parameters
● Usually: from() |> range() |> filter() |> window() |> ...
Output:
● Stream of arbitrary Flux tables
Flux Query Model (Briefly)
Input:
● Flux script: contains both data source (bucket) and all time parameters
● Usually: from() |> range() |> filter() |> window() |> ...
Output:
● Stream of arbitrary Flux tables
Transpilation
Example
PromQL Range Query: http_requests_totalPromQL Range Query: http_requests_total
Flux Transpilation Draft
from("prometheus")
|> range(...) 🠆 range boundaries?
|> filter(...) // Filter series identity here.
|> window(...) 🠆 windowing parameters?
|> <...more post-processing...>
Flux Transpilation Draft
from("prometheus")
|> range(...) 🠆 range boundaries?
|> filter(...) // Filter series identity here.
|> window(...) 🠆 windowing parameters?
|> <...more post-processing...>
Flux Range and WindowingFlux Range and Windowing
Real-World Transpilation Result
PromQL Flux
http_requests_total
Start: 1550768830.123
End: 1550767900.321
Step: 150
from(bucket: "prometheus")
|> range(start: 2019-02-21T16:45:30.123Z, stop: 2019-02-21T16:51:40.321Z)
|> filter(fn: (r) =>
(r._field == "http_requests_total" and r._measurement == "prometheus"))
|> window(every: 150000000000ns, period: 5m, offset: 130123000000ns)
|> filter(fn: (r) =>
(r._stop >= 2019-02-21T16:50:30.123Z and r._start <= 2019-02-21T16:46:40.321Z))
|> last()
|> timeShift(duration: 0ns)
|> drop(columns: ["_measurement"])
|> duplicate(column: "_stop", as: "_time")
Real-World Transpilation Result
PromQL Flux
http_requests_total
Start: 1550768830.123
End: 1550767900.321
Step: 150
from(bucket: "prometheus")
|> range(start: 2019-02-21T16:45:30.123Z, stop: 2019-02-21T16:51:40.321Z)
|> filter(fn: (r) =>
(r._field == "http_requests_total" and r._measurement == "prometheus"))
|> window(every: 150000000000ns, period: 5m, offset: 130123000000ns)
|> filter(fn: (r) =>
(r._stop >= 2019-02-21T16:50:30.123Z and r._start <= 2019-02-21T16:46:40.321Z))
|> last()
|> timeShift(duration: 0ns)
|> drop(columns: ["_measurement"])
|> duplicate(column: "_stop", as: "_time")
Transpilation, More
Generally
Complex Expressions
How to transpile complex expressions like:
sum by(path) (rate(http_requests_total{status="500"}[1m]))
/
sum by(path) (rate(http_requests_total[1m]))
* 100 > 5
Complex Expressions
How to transpile complex expressions like:
sum by(path) (rate(http_requests_total{status="500"}[1m]))
/
sum by(path) (rate(http_requests_total[1m]))
* 100 > 5
Complex Expressions
🠆 Start at root node, transpile all child nodes recursively
🠆 Use transpiled Flux children in parent Flux node
>
5*
100/
sum by(path)
rate rate
http_requests_total{status="500"}[1m] http_requests_total[1m]
sum by(path)
Complex Expressions
🠆 Start at root node, transpile all child nodes recursively
🠆 Use transpiled Flux children in parent Flux node
>
5*
100/
sum by(path)
rate rate
http_requests_total{status="500"}[1m] http_requests_total[1m]
sum by(path)
Supporting PromQL Features
PromQL: Lots of specific semantics and functionality. Not everything supported yet.
● sum(), avg(), etc. 🠆 Map into existing Flux functionality
● rate(), holt_winters(), etc. 🠆 Build custom Flux helper functions
● Subqueries etc. 🠆 Implement with similar semantics
● Staleness markers, special float values etc. 🠆 Not sure yet
● Non-constant scalar function params etc. 🠆 Won't support?
Supporting PromQL Features
PromQL: Lots of specific semantics and functionality. Not everything supported yet.
● sum(), avg(), etc. 🠆 Map into existing Flux functionality
● rate(), holt_winters(), etc. 🠆 Build custom Flux helper functions
● Subqueries etc. 🠆 Implement with similar semantics
● Staleness markers, special float values etc. 🠆 Not sure yet
● Non-constant scalar function params etc. 🠆 Won't support?
Current State
Branches in private forks:
● Flux transpiler: https://github.com/juliusv/flux/tree/transpile-promql-flux
● InfluxDB integration: https://github.com/juliusv/influxdb/tree/promflux-api
Code still experimental
Binary ops require new join features (#1297 or #1219)
Speed issues ➞ Determine viability after Flux optimizations
Current State
Branches in private forks:
● Flux transpiler: https://github.com/juliusv/flux/tree/transpile-promql-flux
● InfluxDB integration: https://github.com/juliusv/influxdb/tree/promflux-api
Code still experimental
Binary ops require new join features (#1297 or #1219)
Speed issues ➞ Determine viability after Flux optimizations
Demo
Thank You!Thank You!

More Related Content

PDF
InnoDB Locking Explained with Stick Figures
PDF
Best Practices for ETL with Apache NiFi on Kubernetes - Albert Lewandowski, G...
PPTX
Tuning kafka pipelines
PDF
Modern ETL Pipelines with Change Data Capture
PDF
Kubernetes Networking
PDF
NiFi Developer Guide
PDF
Bewährte Praktiken für HCL Notes/Domino-Sicherheit. Teil 2: Der Domino-Server
InnoDB Locking Explained with Stick Figures
Best Practices for ETL with Apache NiFi on Kubernetes - Albert Lewandowski, G...
Tuning kafka pipelines
Modern ETL Pipelines with Change Data Capture
Kubernetes Networking
NiFi Developer Guide
Bewährte Praktiken für HCL Notes/Domino-Sicherheit. Teil 2: Der Domino-Server

What's hot (20)

PDF
Continuous Data Replication into Cloud Storage with Oracle GoldenGate
PPTX
From cache to in-memory data grid. Introduction to Hazelcast.
PPTX
Improving go-git performance
PPTX
Containerized Applications Overview
PPTX
Kubernetes walkthrough
PPTX
Kubernetes fundamentals
PDF
MyRocks Deep Dive
PPTX
Kubernetes Workshop
PDF
Battle of the Stream Processing Titans – Flink versus RisingWave
PDF
Kafka Summit SF 2017 - Kafka Connect Best Practices – Advice from the Field
PDF
Kubernetes - A Comprehensive Overview
PDF
マルチスレッドRxSwift @ 社内RxSwift勉強会
PDF
Deep Dive AdminP Process - Admin and Infrastructure Track at UKLUG 2012
PDF
Kinh nghiệm triển khai Microservices tại Sapo.vn
PDF
Webinar: 99 Ways to Enrich Streaming Data with Apache Flink - Konstantin Knauf
PPTX
iceberg introduction.pptx
PPTX
Cassandra internals
PDF
Kubernetes Deployment Strategies
PDF
Building Bizweb Microservices with Docker
PDF
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
Continuous Data Replication into Cloud Storage with Oracle GoldenGate
From cache to in-memory data grid. Introduction to Hazelcast.
Improving go-git performance
Containerized Applications Overview
Kubernetes walkthrough
Kubernetes fundamentals
MyRocks Deep Dive
Kubernetes Workshop
Battle of the Stream Processing Titans – Flink versus RisingWave
Kafka Summit SF 2017 - Kafka Connect Best Practices – Advice from the Field
Kubernetes - A Comprehensive Overview
マルチスレッドRxSwift @ 社内RxSwift勉強会
Deep Dive AdminP Process - Admin and Infrastructure Track at UKLUG 2012
Kinh nghiệm triển khai Microservices tại Sapo.vn
Webinar: 99 Ways to Enrich Streaming Data with Apache Flink - Konstantin Knauf
iceberg introduction.pptx
Cassandra internals
Kubernetes Deployment Strategies
Building Bizweb Microservices with Docker
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
Ad

Similar to Creating the PromQL Transpiler for Flux by Julius Volz, Co-Founder | Prometheus (20)

PPTX
Google cloud Dataflow & Apache Flink
ODP
Introduction to Structured Streaming
PDF
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
PDF
Reducing Redundancies in Multi-Revision Code Analysis
PDF
Presto anatomy
PDF
[245] presto 내부구조 파헤치기
PDF
Processing large-scale graphs with Google Pregel
PDF
Spark (Structured) Streaming vs. Kafka Streams - two stream processing platfo...
PDF
Nzitf Velociraptor Workshop
PPT
NOSQL and Cassandra
PPTX
Why and how to leverage the power and simplicity of SQL on Apache Flink
PDF
Continuous Application with Structured Streaming 2.0
PPTX
Apache Flink Overview at SF Spark and Friends
PDF
Towards sql for streams
PDF
Streaming SQL
PPTX
Flink Forward SF 2017: Timo Walther - Table & SQL API – unified APIs for bat...
ODP
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
ODP
Intravert Server side processing for Cassandra
PPT
OrdRing 2013 keynote - On the need for a W3C community group on RDF Stream Pr...
PPT
On the need for a W3C community group on RDF Stream Processing
Google cloud Dataflow & Apache Flink
Introduction to Structured Streaming
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Reducing Redundancies in Multi-Revision Code Analysis
Presto anatomy
[245] presto 내부구조 파헤치기
Processing large-scale graphs with Google Pregel
Spark (Structured) Streaming vs. Kafka Streams - two stream processing platfo...
Nzitf Velociraptor Workshop
NOSQL and Cassandra
Why and how to leverage the power and simplicity of SQL on Apache Flink
Continuous Application with Structured Streaming 2.0
Apache Flink Overview at SF Spark and Friends
Towards sql for streams
Streaming SQL
Flink Forward SF 2017: Timo Walther - Table & SQL API – unified APIs for bat...
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
Intravert Server side processing for Cassandra
OrdRing 2013 keynote - On the need for a W3C community group on RDF Stream Pr...
On the need for a W3C community group on RDF Stream Processing
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)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
A Presentation on Artificial Intelligence
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Cloud computing and distributed systems.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Electronic commerce courselecture one. Pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Empathic Computing: Creating Shared Understanding
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Big Data Technologies - Introduction.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Approach and Philosophy of On baking technology
PDF
KodekX | Application Modernization Development
PDF
cuic standard and advanced reporting.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Per capita expenditure prediction using model stacking based on satellite ima...
Mobile App Security Testing_ A Comprehensive Guide.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
A Presentation on Artificial Intelligence
NewMind AI Weekly Chronicles - August'25 Week I
Cloud computing and distributed systems.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Electronic commerce courselecture one. Pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Empathic Computing: Creating Shared Understanding
Review of recent advances in non-invasive hemoglobin estimation
“AI and Expert System Decision Support & Business Intelligence Systems”
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Big Data Technologies - Introduction.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Approach and Philosophy of On baking technology
KodekX | Application Modernization Development
cuic standard and advanced reporting.pdf

Creating the PromQL Transpiler for Flux by Julius Volz, Co-Founder | Prometheus

  • 1. Julius Volz - Prometheus Co-Founder Creating the PromQL Transpiler for Flux
  • 3. InfluxDB as long-term storage for Prometheus Reuse Prometheus Grafana dashboards with InfluxDB? 🠆 Support PromQL in InfluxDB via Flux! Build a transpiler. Prometheus Motivation Grafana PromQL query write InfluxDB as long-term storage for Prometheus Reuse Prometheus Grafana dashboards with InfluxDB? 🠆 Support PromQL in InfluxDB via Flux! Build a transpiler. Prometheus Motivation Grafana PromQL query write
  • 4. What Needs to be Done? Simple spec on the surface: ...such that results are equivalent (what does this mean?) AST = Abstract Syntax Tree Transpiler PromQL AST Flux AST Input Output What Needs to be Done? Simple spec on the surface: ...such that results are equivalent (what does this mean?) AST = Abstract Syntax Tree Transpiler PromQL AST Flux AST Input Output
  • 5. Hidden Questions How to map the data models? Is every feature translatable? If not, can we approximate it? Hidden Questions How to map the data models? Is every feature translatable? If not, can we approximate it?
  • 6. Additionally... Make it usable: ● Add PromQL HTTP API to InfluxDB ● Allow data ingestion in expected format Additionally... Make it usable: ● Add PromQL HTTP API to InfluxDB ● Allow data ingestion in expected format
  • 7. Integrating Everything Prometheus Grafana PromQL API Transpiler Flux EngineResult Converter PromQL AST Flux AST Flux result PromQL result DBData Mapper Series data Query Store data PromQL Query Integrating Everything Prometheus Grafana PromQL API Transpiler Flux EngineResult Converter PromQL AST Flux AST Flux result PromQL result DBData Mapper Series data Query Store data PromQL Query
  • 8. Challenges ● Need to know both Flux and PromQL ● Early days for Flux ● Different data and query models Challenges ● Need to know both Flux and PromQL ● Early days for Flux ● Different data and query models
  • 10. Data Model: Prometheus Only metrics / time series No logs / events Data Model: Prometheus Only metrics / time series No logs / events
  • 11. Data Model: Prometheus Series identified once, then multiple timestamp / value pairs: <identifier> → [ (t0, v0), (t1, v1), … ] What is this? int64 (ms) float64 Data Model: Prometheus Series identified once, then multiple timestamp / value pairs: <identifier> → [ (t0, v0), (t1, v1), … ] What is this? int64 (ms) float64
  • 12. Data Model: Prometheus How are series identified? http_requests_total{job="nginx",instance="1.2.3.4:80",path="/home"} metric name labels Data Model: Prometheus How are series identified? http_requests_total{job="nginx",instance="1.2.3.4:80",path="/home"} metric name labels
  • 13. Data Model: Flux For both events and metrics Data Model: Flux For both events and metrics
  • 14. Data Model: Flux (Briefly) Stream: set of tables Tables: typed columns, grouping key, and records Columns: 8 different data types (+ values can also be null) Special columns: _time, _start, _stop, _measurement, _field Data Model: Flux (Briefly) Stream: set of tables Tables: typed columns, grouping key, and records Columns: 8 different data types (+ values can also be null) Special columns: _time, _start, _stop, _measurement, _field
  • 15. Data Model Mapping ● Metric name 🠆 _field ● _measurement = "prometheus" (see Telegraf #4415) ● Label name 🠆 column name (exception: _foo 🠆 ~_foo) ● Label value 🠆 column value ● Sample value 🠆 _value ● Sample timestamp 🠆 _time Data Model Mapping ● Metric name 🠆 _field ● _measurement = "prometheus" (see Telegraf #4415) ● Label name 🠆 column name (exception: _foo 🠆 ~_foo) ● Label value 🠆 column value ● Sample value 🠆 _value ● Sample timestamp 🠆 _time
  • 16. Data Model Mapping Example http_requests_total{method="POST"} 🠆 1043.0 @ 1550767776.382 🠆 1070.0 @ 1550767786.344 🠆 ... Column name _measurement method _field _start _stop _time _value Grouping key? true true true true true false false Column type string string string time time time float "prometheus" "POST" "http_requests_total" 2019-02-21T16:49:00Z 2019-02-21T16:50:00Z 2019-02-21T16:49:36.382Z 1043.0 "prometheus" "POST" "http_requests_total" 2019-02-21T16:49:00Z 2019-02-21T16:50:00Z 2019-02-21T16:49:46.382Z 1070.0 ... ... ... ... ... ... ... Data Model Mapping Example http_requests_total{method="POST"} 🠆 1043.0 @ 1550767776.382 🠆 1070.0 @ 1550767786.344 🠆 ... Column name _measurement method _field _start _stop _time _value Grouping key? true true true true true false false Column type string string string time time time float "prometheus" "POST" "http_requests_total" 2019-02-21T16:49:00Z 2019-02-21T16:50:00Z 2019-02-21T16:49:36.382Z 1043.0 "prometheus" "POST" "http_requests_total" 2019-02-21T16:49:00Z 2019-02-21T16:50:00Z 2019-02-21T16:49:46.382Z 1070.0 ... ... ... ... ... ... ...
  • 18. PromQL Query Types Instant Queries + Range Queries PromQL Query Types Instant Queries + Range Queries
  • 19. PromQL Instant Queries Evaluate PromQL expression at single timestamp: PromQL Instant Queries Evaluate PromQL expression at single timestamp:
  • 20. PromQL Instant Queries Input: ● PromQL Expression ● Evaluation timestamp Output: List of result time series: ● Single sample for each series (for vector selectors) ● Output timestamp is evaluation timestamp PromQL Instant Queries Input: ● PromQL Expression ● Evaluation timestamp Output: List of result time series: ● Single sample for each series (for vector selectors) ● Output timestamp is evaluation timestamp
  • 21. Instant Query Example Simplest Example: Series selection Instant Query Example Simplest Example: Series selection
  • 23. Instant Query Example: http_requests_totalInstant Query Example: http_requests_total
  • 24. Instant Query Example: http_requests_total (Result)Instant Query Example: http_requests_total (Result)
  • 25. Instant Query Example: http_requests_totalInstant Query Example: http_requests_total
  • 26. Instant Query Example: http_requests_total (Empty Result)Instant Query Example: http_requests_total (Empty Result)
  • 27. PromQL Range Queries Evaluate PromQL expression at several timestamps along a range: PromQL Range Queries Evaluate PromQL expression at several timestamps along a range:
  • 28. PromQL Range Queries Semantically: Many subsequent instant queries Under the hood: Optimized PromQL Range Queries Semantically: Many subsequent instant queries Under the hood: Optimized
  • 29. PromQL Range Queries Input: ● PromQL Expression ● Time range (start, end) ● Step (output resolution) Output: List of result time series: ● Multiple samples for each series PromQL Range Queries Input: ● PromQL Expression ● Time range (start, end) ● Step (output resolution) Output: List of result time series: ● Multiple samples for each series
  • 31. Range Query Example: http_requests_totalRange Query Example: http_requests_total
  • 32. Range Query Example: http_requests_total (Results)Range Query Example: http_requests_total (Results)
  • 33. Flux Query Model (Briefly) Input: ● Flux script: contains both data source (bucket) and all time parameters ● Usually: from() |> range() |> filter() |> window() |> ... Output: ● Stream of arbitrary Flux tables Flux Query Model (Briefly) Input: ● Flux script: contains both data source (bucket) and all time parameters ● Usually: from() |> range() |> filter() |> window() |> ... Output: ● Stream of arbitrary Flux tables
  • 35. PromQL Range Query: http_requests_totalPromQL Range Query: http_requests_total
  • 36. Flux Transpilation Draft from("prometheus") |> range(...) 🠆 range boundaries? |> filter(...) // Filter series identity here. |> window(...) 🠆 windowing parameters? |> <...more post-processing...> Flux Transpilation Draft from("prometheus") |> range(...) 🠆 range boundaries? |> filter(...) // Filter series identity here. |> window(...) 🠆 windowing parameters? |> <...more post-processing...>
  • 37. Flux Range and WindowingFlux Range and Windowing
  • 38. Real-World Transpilation Result PromQL Flux http_requests_total Start: 1550768830.123 End: 1550767900.321 Step: 150 from(bucket: "prometheus") |> range(start: 2019-02-21T16:45:30.123Z, stop: 2019-02-21T16:51:40.321Z) |> filter(fn: (r) => (r._field == "http_requests_total" and r._measurement == "prometheus")) |> window(every: 150000000000ns, period: 5m, offset: 130123000000ns) |> filter(fn: (r) => (r._stop >= 2019-02-21T16:50:30.123Z and r._start <= 2019-02-21T16:46:40.321Z)) |> last() |> timeShift(duration: 0ns) |> drop(columns: ["_measurement"]) |> duplicate(column: "_stop", as: "_time") Real-World Transpilation Result PromQL Flux http_requests_total Start: 1550768830.123 End: 1550767900.321 Step: 150 from(bucket: "prometheus") |> range(start: 2019-02-21T16:45:30.123Z, stop: 2019-02-21T16:51:40.321Z) |> filter(fn: (r) => (r._field == "http_requests_total" and r._measurement == "prometheus")) |> window(every: 150000000000ns, period: 5m, offset: 130123000000ns) |> filter(fn: (r) => (r._stop >= 2019-02-21T16:50:30.123Z and r._start <= 2019-02-21T16:46:40.321Z)) |> last() |> timeShift(duration: 0ns) |> drop(columns: ["_measurement"]) |> duplicate(column: "_stop", as: "_time")
  • 40. Complex Expressions How to transpile complex expressions like: sum by(path) (rate(http_requests_total{status="500"}[1m])) / sum by(path) (rate(http_requests_total[1m])) * 100 > 5 Complex Expressions How to transpile complex expressions like: sum by(path) (rate(http_requests_total{status="500"}[1m])) / sum by(path) (rate(http_requests_total[1m])) * 100 > 5
  • 41. Complex Expressions 🠆 Start at root node, transpile all child nodes recursively 🠆 Use transpiled Flux children in parent Flux node > 5* 100/ sum by(path) rate rate http_requests_total{status="500"}[1m] http_requests_total[1m] sum by(path) Complex Expressions 🠆 Start at root node, transpile all child nodes recursively 🠆 Use transpiled Flux children in parent Flux node > 5* 100/ sum by(path) rate rate http_requests_total{status="500"}[1m] http_requests_total[1m] sum by(path)
  • 42. Supporting PromQL Features PromQL: Lots of specific semantics and functionality. Not everything supported yet. ● sum(), avg(), etc. 🠆 Map into existing Flux functionality ● rate(), holt_winters(), etc. 🠆 Build custom Flux helper functions ● Subqueries etc. 🠆 Implement with similar semantics ● Staleness markers, special float values etc. 🠆 Not sure yet ● Non-constant scalar function params etc. 🠆 Won't support? Supporting PromQL Features PromQL: Lots of specific semantics and functionality. Not everything supported yet. ● sum(), avg(), etc. 🠆 Map into existing Flux functionality ● rate(), holt_winters(), etc. 🠆 Build custom Flux helper functions ● Subqueries etc. 🠆 Implement with similar semantics ● Staleness markers, special float values etc. 🠆 Not sure yet ● Non-constant scalar function params etc. 🠆 Won't support?
  • 43. Current State Branches in private forks: ● Flux transpiler: https://github.com/juliusv/flux/tree/transpile-promql-flux ● InfluxDB integration: https://github.com/juliusv/influxdb/tree/promflux-api Code still experimental Binary ops require new join features (#1297 or #1219) Speed issues ➞ Determine viability after Flux optimizations Current State Branches in private forks: ● Flux transpiler: https://github.com/juliusv/flux/tree/transpile-promql-flux ● InfluxDB integration: https://github.com/juliusv/influxdb/tree/promflux-api Code still experimental Binary ops require new join features (#1297 or #1219) Speed issues ➞ Determine viability after Flux optimizations
  • 44. Demo