Why is this InfluxDB Flux query returning 2 tables?

6.8k Views Asked by At

Obv. I'm new to InfluxDB & the Flux query language so appreciate patience! Happy to be redirected to documentation but I haven't found anything genuinely useful to date.

I've configured Jenkins (2.277.3) to push build metrics to InfluxDB (Version 2.0.5 ('7c3ead)) using plugin (https://plugins.jenkins.io/influxdb/). No custom metrics at the moment. Data is being successfully sent.

I'd like to build a simple bar chart to show build times for a specific project. Each "bar" would be an individual build (with a distinct build number). Also:

  • X-axis, date/time of build
  • Y-axis, duration of build
  • (Ideally bars would be green/red to indicate success/anything else and would be labelled with job number. In time I'd like to add an overlay with average build time.)

I'm trying to create the query(ies) to support this view:

from(bucket: "db0")
  |> range(start: -2d)
  |> filter(fn: (r) => r["project_name"] == "Job2")
  |> filter(fn: (r) => r._measurement == "jenkins_data" and r._field == "build_time" )

This results in 2 tables in the Table view, one for build SUCCESS and one for build FAILURE. Can someone explain to be why this is the case, and whether I'm missing some fundamental understanding of how to use the tool?

Screen snip of the data "shape"

SUCCESS table

FAILURE table

2

There are 2 best solutions below

1
On BEST ANSWER

"Each flux query returns a stream of tables meaning your query can return multiple tables. Each table is created depending on the grouping. If you change the grouping at the end of your query you could merge these tables into 1. The simples example would be to just add |> group() at the end and see that now you are getting just 1 table."

Accepting @ditoslav's comment as the answer to my question.

0
On

Is anyone's still having issues with this, I'll describe what was happening for me and then how I fixed it.

For me it happened when I was downsampling data into less frequent groupings (from 3s to 15m) and I always got 2 streams instead of 1. I tried everything I could, like time-bucketing the periods in fixed buckets 21:00-21:15, 21:15-21:30, 21:30-21:45 and similar but that didn't fix it.

One particularity of my data was that the _field value was a float with a very high number of decimals e.g. 4967.212765957447, so what I ended up doing which fixed the issue is to round the number down to the closest integer.

Hope this helps anyone else that has this issue