Skip to content

Conversation

@gjohansson-ST
Copy link
Member

Reverts #134758

See comment #134758 (comment)
When fixing that problem the tests doesn't work (locks).
Breaks dev apparently too in it's current state https://github.com/home-assistant/core/actions/runs/19080794349/job/54509512666?pr=155802

Copilot AI review requested due to automatic review settings November 4, 2025 20:15
@home-assistant
Copy link

home-assistant bot commented Nov 4, 2025

Hey there @mdegat01, mind taking a look at this pull request as it has been labeled with an integration (influxdb) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of influxdb can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign influxdb Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@gjohansson-ST
Copy link
Member Author

@jgaalen something you might want to fix without reverting the original PR?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the InfluxDB integration to remove user-configurable batch parameters and replace them with hardcoded constants. The changes align with Home Assistant's coding guideline that polling intervals and batch parameters should not be user-configurable, but rather determined programmatically by the integration.

  • Removed user-configurable batch_buffer_size and batch_timeout parameters from the configuration schema
  • Replaced configurable batch parameters with hardcoded constants BATCH_BUFFER_SIZE (100) and BATCH_TIMEOUT (1)
  • Simplified the get_events_json() method by removing dynamic batch timeout calculation logic

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
homeassistant/components/influxdb/const.py Removed configuration constants and schema for batch parameters; added hardcoded BATCH_BUFFER_SIZE and BATCH_TIMEOUT constants
homeassistant/components/influxdb/__init__.py Updated imports to use new constant names; removed batch configuration from schema; simplified InfluxThread initialization and batch_timeout() method; streamlined timeout calculation in get_events_json()

else batch_timeout - (time.monotonic() - start_time)
)
while len(json) < BATCH_BUFFER_SIZE and not self.shutdown:
timeout = None if count == 0 else self.batch_timeout()
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout calculation is incorrect. After the first event (count > 0), the timeout is always set to BATCH_TIMEOUT (1 second) regardless of how much time has already elapsed. The original code calculated a decreasing timeout based on batch_timeout - (time.monotonic() - start_time) to ensure the total batch collection time didn't exceed the timeout. This change means subsequent events will wait the full 1 second each time, potentially causing the batch collection to take much longer than intended (up to 100 seconds for a full batch instead of 1 second total).

Copilot uses AI. Check for mistakes.
Comment on lines 540 to 547
def get_events_json(self):
"""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()

count = 0
json = []

dropped = 0
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of start_time = time.monotonic() and the batch timeout check if count > 0 and time.monotonic() - start_time >= batch_timeout: break eliminates the mechanism that ensures batch collection completes within the timeout period. This was important for preventing the thread from spending excessive time collecting events when the queue has many items. Consider restoring this logic to maintain the original behavior where the total batch collection time is bounded.

Copilot uses AI. Check for mistakes.
@joostlek joostlek merged commit f93940b into dev Nov 5, 2025
41 of 42 checks passed
@joostlek joostlek deleted the revert-134758-add_influxdb_batch_config branch November 5, 2025 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants