-
-
Notifications
You must be signed in to change notification settings - Fork 35.8k
Make influxdb batch settings configurable #134758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make influxdb batch settings configurable #134758
Conversation
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Hey there @mdegat01, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
3e0dc7e to
2e42eae
Compare
|
What is necessary to get this PR going? |
|
@mdegat01 So this PR is open for a while. What is that about? |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
@mdegat01 Hi, this PR is here now for a couple of months. Can you take a look please? Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe influxdb is an exception, but ideally we should not change YAML config anymore. There's a PR open to bring InfluxDB to the UI so I think it would be better to look at that PR and add it after that PR is merged
|
FTR, the other PR is this one: #134463 |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
Not stale |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
The config flow PR is still not ready for merge. @RobBie1221 do you see a problem with merging this PR first? |
|
No, I can deal with the conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. I'm good with this PR though searching influx documentation I notice a couple things:
- It says the optimal batch size for Influx v2 is 5000 lines. So maybe we want to increase the default there.
- Users of the cloud service need to be aware that it has it has hard limits here. In particular the free tier of Influx v2 cloud has a hard limit of 1MB/min. Since it only applies to free tier and cloud I don't know if we want to try and account for this in config schema but the corresponding documentation should note this.
To reach 5000 lines within the set delay, you probably need a hell of a lot lines. Basically the batch size is simply an upper limit of lines to add within the set timeout.
A good practise is to compress (gzip) the influx request payload to lower throughput and improve response times. For HA usually overkill. |
| """Return a batch of events formatted for writing.""" | ||
| queue_seconds = QUEUE_BACKLOG_SECONDS + self.max_tries * RETRY_DELAY | ||
| start_time = time.monotonic() | ||
| batch_timeout = self.batch_timeout() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like an error. batch_timeout is now a property which returns a float so this will raise a TypeError. From the test logs
tests/components/influxdb/test_sensor.py: 25 warnings
/home/runner/work/ha-core/ha-core/venv/lib/python3.13/site-packages/_pytest/threadexception.py:58:
PytestUnhandledThreadExceptionWarning: Exception in thread influxdb
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.13.9/x64/lib/python3.13/threading.py", line 1043, in _bootstrap_inner
self.run()
~~~~~~~~^^
File "/home/runner/work/ha-core/ha-core/homeassistant/components/influxdb/__init__.py", line 618, in run
_, json = self.get_events_json()
~~~~~~~~~~~~~~~~~~~~^^
File "/home/runner/work/ha-core/ha-core/homeassistant/components/influxdb/__init__.py", line 554, in get_events_json
batch_timeout = self.batch_timeout()
TypeError: 'float' object is not callableThis reverts commit 0e2a460.
Proposed change
This change makes the influxdb batch size and batch timeout configurable, rather than a fixed default of size: 100 and timeout: 1. It also fixes the timeout behaviour. Before, it waits for new events/values for the timeout (1s), but when values are received after 800ms, it waits for 1s again, causing situations where I had situations where it took more than 5 seconds before values are written.
This change makes it possible to write values quicker to influxdb, for a more realtime experience, or make larger batches and higher timeouts for lesser writes.
These values can be used in the influxdb yaml section:
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: