Skip to content

fix: aggregate 95th percentile uses SUM instead of MAX for SIMILAR#6843

Merged
TheWitness merged 11 commits intoCacti:developfrom
somethingwithproof:fix/aggregate-ptile-similar-6835
Mar 24, 2026
Merged

fix: aggregate 95th percentile uses SUM instead of MAX for SIMILAR#6843
TheWitness merged 11 commits intoCacti:developfrom
somethingwithproof:fix/aggregate-ptile-similar-6835

Conversation

@somethingwithproof
Copy link
Copy Markdown
Contributor

@somethingwithproof somethingwithproof commented Mar 19, 2026

Summary

  • Split AGGREGATE_TOTAL_TYPE_SIMILAR from ALL in three locations in lib/api_aggregate.php
  • SIMILAR now uses aggregate_current / aggregate_current_peak (per-data-source percentiles) instead of aggregate_sum / aggregate_sum_peak (sum of all sources)
  • This restores the correct 95th percentile calculation: max(in, out) instead of sum(in + out)
  • Secondary fix: ALL + :max: text_format path now uses aggregate_sum_peak (was incorrectly using aggregate_sum), aligning it with the COMMENT/HRULE pparts paths which already used aggregate_sum_peak

Root cause

Three conditional blocks grouped SIMILAR with ALL:

  • text_format :current: / :max: replacement in aggregate_graphs_insert_graph_items()
  • pparts[3] replacement for COMMENT items in aggregate_handle_ptile_type()
  • pparts[3] replacement for HRULE items in aggregate_handle_ptile_type()

All three used aggregate_sum for SIMILAR, which sums inbound + outbound traffic together before computing the 95th percentile. The correct behavior for SIMILAR is aggregate_current, which computes percentiles per data source name (in/out separately) and takes the max.

Note: PR #6750 fixed the test stubs but the api_aggregate.php change was accidentally dropped during review cleanup.

Test plan

  • 12 existing unit tests (AggregatePtileTypeTest) pass
  • 18 new integration tests covering full COMMENT/HRULE pipeline, text_format replacement, edge cases, and regression guards
  • Manual verification: aggregate graph 95th percentile HRULE should show max(in, out), not sum(in + out)
  • Verify existing ALL-type aggregate graphs with :max: percentile items render correctly after the secondary fix

Fixes #6835
Ref #6470

AGGREGATE_TOTAL_TYPE_SIMILAR was grouped with ALL in three locations,
causing SIMILAR aggregate graphs to use aggregate_sum / aggregate_sum_peak
(which sums inbound + outbound together) instead of aggregate_current /
aggregate_current_peak (which computes percentiles per data source name).

This made 95th percentile HRULEs on aggregate graphs display the sum of
in+out instead of max(in, out), roughly doubling the reported value.

Split each conditional into separate ALL and SIMILAR branches:
- ALL: aggregate_sum / aggregate_sum_peak (sum all data sources)
- SIMILAR: aggregate_current / aggregate_current_peak (per-source)

Three locations in lib/api_aggregate.php:
- text_format substitution in aggregate_graphs_insert_graph_items()
- pparts replacement for COMMENT items in aggregate_handle_ptile_type()
- pparts replacement for HRULE items in aggregate_handle_ptile_type()

Fixes Cacti#6835
Ref Cacti#6470

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
- Add cacti_log debug traces for unhandled total_type values
- Add 18 integration tests covering full COMMENT/HRULE pparts pipeline
  and text_format replacement for SIMILAR vs ALL total types

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The test helpers replicate production logic from api_aggregate.php
because the production functions require DB/session state. Add a
comment documenting this dependency and the lines that must stay
in sync.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@somethingwithproof somethingwithproof force-pushed the fix/aggregate-ptile-similar-6835 branch from e3b5a5d to 691bc05 Compare March 19, 2026 17:06
TheWitness
TheWitness previously approved these changes Mar 22, 2026
@TheWitness
Copy link
Copy Markdown
Member

Is this ready to go?

@somethingwithproof
Copy link
Copy Markdown
Contributor Author

Is this ready to go?

yes

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@TheWitness TheWitness merged commit 0c281c9 into Cacti:develop Mar 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Aggregate graph 95th percentile uses SUM(in+out) instead of MAX(in,out) — broken since 1.2.30

3 participants