1

I'm working with InfluxDB v2.1.

I have this task:

option task = {
   name: "DOWNSAMPLE APRILIA UTILITIES",
   cron: "0 * * * *",
}

from(bucket: "homeassistant-aprilia")
   |> range(start: -2h, stop: -1h)
   |> filter(fn: (r) => r["_measurement"] == "kWh")
   |> filter(fn: (r) => r["_field"] == "value")
   |> filter(fn: (r) => r.entity_id == "shellyem_c45bbe5fed52_channel_1_energy")
   |> aggregateWindow(every: 1h, fn: max, createEmpty: false)
   |> difference()
   |> to(bucket: "downsample-utility-aprilia", org: "sineverba")

it being executed every hour but... it doesn't write anything in the destination bucket.

I have all success logs but nothing in my destination bucket.

If I launch the task directly in source bucket, I can see the value of my interest.

Other, if I don't omit the "to" value, manually launched from bucket it writes the data.

Why?

sineverba
  • 5,059
  • 7
  • 39
  • 84

2 Answers2

1

Sometimes InfluxDB fails to write but doesn't respond with an error. In those cases, success status doesn't mean that the data was written. It means that data was accepted for writing but it might fail later. Try checking the _monitoring bucket. That bucket stores rejected data points with the error message.

For example, in my case, it was a schema mismatch. One type was expected but another was received. I was using implicit schema which means that schema was decided by the InfluxDB itself based on the data I put there. I resolved this by making schema explicit. In this case, InfluxDB returns an error right away at the moment of writing.

PovilasZ
  • 191
  • 1
  • 1
  • 15
  • 1
    Thank you for your time. By the way, `monitoring` bucket is empty. – sineverba Mar 28 '22 at 12:41
  • Hmmm, what about `_tasks` bucket? No clues there too? – PovilasZ Mar 28 '22 at 13:10
  • Only `success` inside it – sineverba Mar 28 '22 at 13:20
  • 1
    Does the query return any data if you just run it in the data explorer without having the `to` part? To be honest I'm out of options. I hope you'll be able to solve this. Would be great if you could post an answer to your question later as someone else might find it useful too. – PovilasZ Mar 28 '22 at 14:28
  • Yes, If i put it in explorer, without the to, I get data. If i leave there the "to" section, I get data written in bucket! – sineverba Mar 28 '22 at 18:31
1

At the end, I solved with stop at now:

option task = {
    name: "DOWNSAMPLE APRILIA UTILITIES",
    cron: "0 * * * *",
}

option entity_id = "shellyem_c45bbe5fed52_channel_1_energy"

data = from(bucket: "homeassistant-aprilia")
    |> range(start: -2h, stop: now())
    |> filter(fn: (r) => r["_measurement"] == "kWh")
    |> filter(fn: (r) => r["_field"] == "value")
    |> filter(fn: (r) => r.entity_id == entity_id)
    |> aggregateWindow(every: 1h, fn: last, createEmpty: false)
    |> difference()
    |> to(bucket: "downsample-utilities-aprilia", org: "sineverba")
sineverba
  • 5,059
  • 7
  • 39
  • 84