Flux - Timeseries with Group by - Data is missing a time field

  • What Grafana version and what operating system are you using?

Using grafana and influxdb on docker: grafana/grafana:10.0.5 influxdb:2.7

  • What are you trying to achieve?

Visualize the history of CI unittest results.

  • How are you trying to achieve it?
from(bucket: "junit")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "junit_data")
  |> filter(fn: (r) => r["_field"] == "test_name")
  |> filter(fn: (r) => r["project_path"] == "${project}")
  |> group(columns: ["build_number", "test_status", "_time"])
  |> count() 
  • What happened?

While the InfluxDB Data Explorer shows the results as expected with _time, build_number, _value and test_status as fields (or tags?), the Time Series visualization in Grafana shows “Data is missing a time field”.
Switching to the Table view, the only column available is the value (count as expected) with a column name like _value{_time=“xxxx”, test_status=“FAILED”, …}

  • What did you expect to happen?
    Visualization of the State/Value over time.

I just ran into a similar problem, and the solution is to remove _time from the group key after performing the aggregation (in your case count, but mine was sum).

If you add this, it should resolve the issue:

>| group(columns: ["build_number", "test_status"])
1 Like

Hello, I have a similar problem… Basically I want in a time series graph to be able to understand how many logs I am receiving over time (and not the sum of a specific field) and I have the single field “log_id” to identify each log that I receive and therefore after adding the last line you suggested (|> group(columns: [“log_id”]) in which we remove the “_time” to stop giving the error “Data is missing a time field” now gives me the error Status: 500. Message: invalid: runtime error @5:6-5:13: count: schema collision detected: column “_value” is both of type float and string.

from(bucket: “planner”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “success”)
|> group(columns: [“log_id”, “_time”])
|> count()
|> group(columns: [“log_id”])

Can you help me? Thanks !!