2

I would like to query the same measurement across different retention policies into a single graph. Ideally, I'd like to do this in the query itself, as I'm working with Grafana.

According to Flux documentation, "Flux structures all data in tables. When data is streamed from data sources, Flux formats it as annotated comma-separated values (CSV), representing tables. Functions then manipulate or process them and output new tables."

Would different retention policies behave like different tables in this context? Would I be able to use the union() function in order to get what I want? Any insight would be greatly appreciated.

M0llzilla
  • 33
  • 5

1 Answers1

0

So for something like this, you would just use two different from statements and use union or join to combine them. Check out the docs on union for a query example: https://v2.docs.influxdata.com/v2.0/reference/flux/stdlib/built-in/transformations/union/#examples

left = from(bucket: "database1/policy1")
  |> range(start: 2018-05-22T19:53:00Z, stop: 2018-05-22T19:53:50Z)
  |> filter(fn: (r) =>
    r._field == "usage_guest" or
    r._field == "usage_guest_nice"
  )
  |> drop(columns: ["_start", "_stop"])

right = from(bucket: "database1/policy2")
  |> range(start: 2018-05-22T19:53:50Z, stop: 2018-05-22T19:54:20Z)
  |> filter(fn: (r) =>
    r._field == "usage_guest" or
    r._field == "usage_idle"
  )
  |> drop(columns: ["_start", "_stop"])

union(tables: [left, right])

In this case, the bucket used in the from function would be in the form of database_name/rp. See the docs on bucket naming conventions in 1.x: https://docs.influxdata.com/flux/v0.50/introduction/getting-started/#buckets

Russ Savage
  • 598
  • 4
  • 20