influxdata / influxdata/influxdb

Flux InfluxDB query not working correctly

Open
#23,714 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

I'm using InfluxDB and telegraf to have a dashboard.

InfluxDB v2.4.0 (git: de247bab08) build_date: 2022-08-18T19:41:15Z
Telegraf 1.23.4 (git: HEAD 5b48f5da)

My goal is to create a table with "firmware_version" for each "MCU".

telegraf input is an mqtt_consumer with this config

[[inputs.mqtt_consumer]]
  ....

  topics = [ "+/+/hal" ]

  name_override = "test"
  data_format = "json_v2"

  [[inputs.mqtt_consumer.json_v2]]
    [[inputs.mqtt_consumer.json_v2.object]]
      path = "mcu"
      included_keys = ["target", "version"]
      disable_prepend_keys = true

The input (MQTT payload) looks like this

{
  "mcu": [
    {
      "target": "MCU_1",
      "version": "2022.08.1"
    },
    {
      "target": "MCU_2",
      "version": "2022.08.2"
    }
  ]
}

In addition to this mqtt_consumer, I have a processor regex to parse the topic and get the "cliend_id" and "device_id" where topic = <cliend_id>/<device_id>/hal
The desired output is a table in "Web Admin Interface" of InfluxDB where I can see the version per MCU per device per client

Client Device Target Version
Client_1 Device_1 MCU_1 2022.08.1
Client_1 Device_1 MCU_2 2022.08.2
Client_2 Device_2 MCU_1 2022.07.1
Client_2 Device_2 MCU_2 2022.07.2

With my humble understand to the query syntax, I thought about this query

from(bucket: "my_bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "test")
  |> filter(fn: (r) => r["_field"] == "version")
  |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
  |> last()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the reported InfluxDB 2.4.0, Telegraf 1.23.4, MQTT, and Flux query configuration, then reproduce the query against the described JSON input. Confirm whether the result produces the requested client, device, MCU target, and firmware version table; the issue names no repository files or tests to run.

Written by the indexing model from the issue text.

Assessment

Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.