Fix InfluxDB 1.x mean/sum and grouped query double-aggregation#1523
Fix InfluxDB 1.x mean/sum and grouped query double-aggregation#1523kizniche wants to merge 8 commits into
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates Mycodo’s InfluxDB Flux querying to work around InfluxDB 1.8.10 Flux panics for mean()/sum() and to re-enable mean-based downsampling/grouping behavior for 1.x.
Changes:
- Replaces the prior InfluxDB 1.x
aggregateWindow(..., fn: median)workaround with a manual mean/sum fallback path for 1.x results. - Adds helper structures/functions to compute mean/sum (and grouped mean) outside of Flux’s
mean()/sum()for InfluxDB 1.x. - Simplifies several callers (
output_sec_on,average_*,sum_past_seconds) to assume the query layer returns a single aggregated value.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Agent-Logs-Url: https://github.com/kizniche/Mycodo/sessions/fc2c2777-4ee3-444f-a9dc-78e1e6eada6a Co-authored-by: kizniche <838427+kizniche@users.noreply.github.com>
…d timestamps Agent-Logs-Url: https://github.com/kizniche/Mycodo/sessions/34bde69d-5ac8-47d4-9798-bee3ae0942fb Co-authored-by: kizniche <838427+kizniche@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…plicit value Agent-Logs-Url: https://github.com/kizniche/Mycodo/sessions/5cd03b98-919a-495c-944b-0f0ecf04d320 Co-authored-by: kizniche <838427+kizniche@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
…anual_calculate_sum Co-authored-by: kizniche <838427+kizniche@users.noreply.github.com>
Done in commit |
|
@copilot Install the proper dependencies with the requirements.txt and requirements-testing.txt files in the install directory, remove unnecessary mocks in the tests you made, and rerun the tests. |
…er deps now installed) Agent-Logs-Url: https://github.com/kizniche/Mycodo/sessions/d45eb174-543a-4d8c-8bd4-df1c294b5a00 Co-authored-by: kizniche <838427+kizniche@users.noreply.github.com>
Done in commit Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot apply changes based on the comments in this thread |
…whitespace Agent-Logs-Url: https://github.com/kizniche/Mycodo/sessions/b6c3ab53-7015-4636-9dba-2a0841a0589f Co-authored-by: kizniche <838427+kizniche@users.noreply.github.com>
Done in commit
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Do one more code review to ensure this PR solves the main issue and conforms to the original PR summary: |
The PR correctly solves the stated issue. Here's a summary of how each requirement is met: InfluxDB 1.8.x crash bug for MEAN/SUM: Fixed. The old workaround (
Grouped queries (group_sec) on 1.x: Uses Flux Callers simplified: Code quality: Dead code ( Tests: 14 unit tests cover Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Fixes InfluxDB 1.8.x crash bug when using MEAN or SUM in Flux queries. Previously, Mycodo worked around this by substituting MEDIAN for MEAN. Now, for InfluxDB 1.x, querying MEAN returns the actual mean and SUM returns the actual sum.
Changes Made
|> median()workaround for MEAN and the raw-point summing workaround for SUM. Raw points are now fetched and_manual_calculate_mean()/_manual_calculate_sum()compute the correct result client-side, avoiding the Flux crash (influxdata/influxdb#21649).window()+reduce()+map()server-side to compute per-window means without callingaggregateWindow(fn: mean), keeping server-side processing (less data to the client) while avoiding the crash.output_sec_on,average_past_seconds,average_start_end_seconds, andsum_past_secondsno longer contain version-specific workaround logic — they all consume the single aggregated value thatquery_flux/query_stringnow always returns._manual_aggregate_mean()function and its unreachable call site removed. AllTODO: Change median to mean when issue is fixedcomments removed.logger.errorfor the SUM workaround demoted tologger.debug.influxdb_get_first_point().Testing
mycodo/tests/software_tests/test_influxdb/test_manual_aggregation.pycovering_manual_calculate_meanand_manual_calculate_sum(empty input, None-skipping, single point, multiple points, correct scalar output — no live InfluxDB required).📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.