Telegraf bucket not found 404 error

I have installed Telegraf and InfluxDB2 on a Kubernetes cluster. I have created a token on influxdb2 and configured telegraf with an output for the token and bucket. Telegraf has an mqtt consumer input. Telegraf is connecting to influxdb2 and the mqtt broker successfully, but when it processes a new mqtt message and tries to send the data to influxdb2 it reports an error “Failed to write metric (will be dropped: 404 Not Found): not found: bucket not found”. The bucket is set in the influxdb2 output and is correct. I have even created a token with all rights on all buckets to test, but it still can’t find the bucket. Does anyone have any pointers on how I can troubleshoot this? The debug level log doesn’t even say which bucket it’s trying to find, so I can’t see if it’s just a config problem. Any help greatly appreciated. Logs below:

2022-02-21T19:31:24Z I! Starting Telegraf 1.21.4
2022-02-21T19:31:24Z I! Using config file: /etc/telegraf/telegraf.conf
2022-02-22T08:31:24+13:00 I! Loaded inputs: mqtt_consumer (2x)
2022-02-22T08:31:24+13:00 I! Loaded aggregators:
2022-02-22T08:31:24+13:00 I! Loaded processors:
2022-02-22T08:31:24+13:00 I! Loaded outputs: influxdb_v2 (2x)
2022-02-22T08:31:24+13:00 I! Tags enabled: host=telegraf-c9fc696bc-qbsjg
2022-02-22T08:31:24+13:00 I! [agent] Config: Interval:10s, Quiet:false, Hostname:"telegraf-c9fc696bc-qbsjg", Flush Interval:10s
2022-02-22T08:31:24+13:00 D! [agent] Initializing plugins
2022-02-22T08:31:24+13:00 D! [agent] Connecting outputs
2022-02-22T08:31:24+13:00 D! [agent] Attempting connection to [outputs.influxdb_v2]
2022-02-22T08:31:24+13:00 D! [agent] Successfully connected to outputs.influxdb_v2
2022-02-22T08:31:24+13:00 D! [agent] Attempting connection to [outputs.influxdb_v2]
2022-02-22T08:31:24+13:00 D! [agent] Successfully connected to outputs.influxdb_v2
2022-02-22T08:31:24+13:00 D! [agent] Starting service inputs
2022-02-22T08:31:24+13:00 I! [inputs.mqtt_consumer] Connected [hidden]
2022-02-22T08:31:24+13:00 D! [inputs.mqtt_consumer] Session found [hidden]
2022-02-22T08:31:24+13:00 I! [inputs.mqtt_consumer] Connected [hidden]
2022-02-22T08:31:24+13:00 D! [inputs.mqtt_consumer] Session found [hidden]
2022-02-22T08:32:34+13:00 E! [outputs.influxdb_v2] Failed to write metric (will be dropped: 404 Not Found): not found: bucket not found
2022-02-22T08:32:34+13:00 D! [outputs.influxdb_v2] Wrote batch of 2 metrics in 2.890752ms

I’ve added a PR here to resolve the lack of the bucket name in the error message. Once the artifacts are built on that PR, please give it a shot.

For now, I would simplify your config if it has multiple buckets specified and try one at a time until you isolate the one causing you issues.

Thanks, in the end the “bucket name not found” was caused by a problem in my output config, please see here: Error parsing tagpass in telegraf.conf. So it’s possible it would not have been able to display the bucket name anyway, but for others trying to access a non-existent bucket it would be useful to see the name and fix their influxdb2 setup.