Repository navigation
refactor(flowview): split run_flow_query, the report filter and field checks; fix single-thread reports - #324
Draft
somethingwithproof wants to merge 17 commits into
Conversation
Record characterisation traces of run_flow_query(), flowview_display_filter() and flowview_check_fields() before they are split up: the value returned, the HTML printed, every SQL statement with its parameters, the log, raised messages, PHP notices, and the request and session state left behind. The run_flow_query matrix covers each statistical and printed report, unknown and missing reports, planning, each request override, each filter column, the NAT toggle, full and partial partition scans, the serial and the parallel query, and every result column. The traces are compared in tests/fixtures/golden and re-recorded only with FLOWVIEW_GOLDEN_UPDATE=1. The UI and session stubs the traces reach move to the unit bootstrap, so a trace does not depend on which test file ran first. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
flowview_check_fields() repeated the address and subnet checks for the source and destination, and the bounds check for each of seven number lists. Validate the report choice and dates, an address list, a number list, the TCP flags and the cut-offs in their own functions, and check the number lists from one table. The checks, their order and the messages are unchanged; the golden trace replays identically. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
flowview_display_filter() was 1,192 lines: the title, four filter rows, the dialogs and the page script, with the Report and Sort Field options worked out in the middle of the markup. Work out the title, the Report options and the Sort Field options in their own functions, and print each row, the dialogs and the script from its own function. The markup is moved verbatim; only the code between it moved. The Report options lose a branch for no Filter, which the page cannot reach, as the Report is only shown for a Filter. The golden trace replays identically, HTML, SQL text and request changes included. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
ReportSql holds one report's SQL fragments, ReportCatalog maps the statistical and printed report numbers to them in the original switch order with loose comparison, and ReportTable and PacketSizeTable render the result tables. Nothing calls them yet. List lib/ in the manifest and the classes in the coverage source. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
run_flow_query now applies the request overrides, builds the Filter WHERE and time range, looks the report up in ReportCatalog, builds the query structures, runs the parallel or serial query and renders the table through ReportTable or PacketSizeTable. The SQL text, the parallel query hash and the output are unchanged; the golden traces pin them. Remove the unreachable empty-row branch and unused assignments. Regenerate the POT for the moved strings; the msgid set is unchanged. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
When the time range applied to a partition, the serial query of a two map report, such as Source/Destination IP, replaced the Filter's WHERE with the range. The SQL started with AND and the Filter's parameters no longer matched the placeholders. Keep the WHERE and append the range, as the parallel query does. The golden trace of the partial two map scan with a filter is updated to the corrected query. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
With one parallel thread, a report with one map query read every partition whole: the Filter's WHERE and the time range were never added, so the report ignored both. Build the map query's WHERE the same way for one map and two, as the parallel query does. The golden traces of the four affected serial cases are updated to the corrected queries. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
With one parallel thread, the packet size summary read its one row as if it were a list of rows, so PHP warned and every cell showed N/A. Return the row in a list, as the parallel query does. The golden trace of the serial summary report is updated. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The heading was chosen by comparing the page's report with '11', but a statistical report is asked for as 's11' and a saved Filter sets no report, so the merged address column was always headed Source IP. Use the Filter's statistical report number instead, and drop the report value that is no longer needed. The golden traces of the five report 11 cases are updated. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The Save, Cancel and Continue buttons of the save and rename dialogs showed a stray "'>" after their label. Remove it. The golden traces of the filter page are updated; the only change in them is the four button labels. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Write the graph type into the filter page script with json_encode, as the other values there are, so it is always a JavaScript string. The golden traces of the filter page are updated; the only change in them is the graph type line. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
A saved Filter with a Stream and no Listener added "ex_addr = ?" without WHERE, so each map query read "FROM plugin_flowview_raw_... ex_addr = ?", a syntax error on both the one thread and the parallel path. Open the WHERE with it, as the other conditions do. No golden trace changes; the cache key changes only for this Filter shape, whose query could not run before. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
flowview_query_report() read $stat_columns_array as a global, which is set only because run_flow_query() declares it before requiring includes/arrays.php. Pass the columns in instead. run_flow_query() keeps the global declaration it had before the split. No golden trace changes. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Apply what php-cs-fixer reports on the lines this branch adds or changes in includes/functions.php and lib/ReportCatalog.php, and document ReportCatalog::totalsBy(). Two re-indentations the fixer suggests inside the filter page's inline HTML are left out, as they would misalign those lines with their neighbours. No golden trace changes. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
curl_close() has had no effect since PHP 8.0, when cURL handles became objects freed with their last reference, and PHP 8.5 deprecates it. Remove the calls in flowview_check_databases() and flowview_get_owner_from_arin(); neither uses the handle afterwards, and it is freed when the function returns. A source scan now fails on a curl_close() call in the plugin's own files. setup.php keeps its call for now, as other pending changes edit that file. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…wo map Filter Mutation testing of the query pipeline left these unnoticed by the golden cases: the part of a flow the time range applies to (the cases there read whole partitions, which skip the range), the order of the parameters across partitions that are and are not wholly in the range, the Filter and the cut-off handed to a two map report, the summary report read in one thread with no flows, the printed flag of a prepared report, an ampersand in the graph type, and a start date equal to the end date. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
somethingwithproof
marked this pull request as draft
December 4, 2026 21:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Closes #323.
Behaviour-preserving refactor of the three largest functions in
includes/functions.php, followed by fixes for the defects it exposed. The old function names stay as thin wrappers, so hooks and callers are unchanged.How behaviour is pinned
The first commit adds characterisation tests recorded on the unmodified code; that commit changes only files under
tests/. It records 87 cases forrun_flow_query()(every report type, single and parallel paths, with and without Filter and time range; the SQL issued and the returned data), 23 forflowview_display_filter()(rendered markup) and 63 forflowview_check_fields(). Every refactor commit passes them unchanged. Eachfix:commit then either updates only the expectations for the defect it fixes or leaves them unchanged, and adds a test that fails without the fix.Verification
An independent differential run fed 2,220 saved-Filter and request combinations (every statistical and printed report, NAT on and off, sort fields, four Filter shapes, and the planning, parallel and one-thread paths) to the pre-refactor and the refactored code and got identical plan cache keys, SQL text and parameters. The golden traces were recorded on unmodified code, in a commit that changes only tests.
Structure
flowview_check_fields(): one validator per field group; complexity 101 to at most 10. It has no caller in the plugin; it is kept here so this change stays a pure split, and a follow-up removes it.flowview_display_filter(): row printers; complexity 68 to at most 21. That figure does not countflowview_print_filter_script(), which is still about 822 lines, mostly emitted JavaScript. The script was moved, not reduced; a follow-up moves it to a static file.run_flow_query(): a query pipeline with report catalog, SQL builder, executor and table classes underlib/.flowview_query_report()takes the report columns as a parameter rather than reading them as a global.Fixes
'>after the filter dialog button labels.ex_addr = ?withoutWHERE, so each map query readFROM plugin_flowview_raw_... ex_addr = ?, a syntax error on the parallel path and, once the single-thread path applied the Filter, on that path too. No golden trace changes; the plan cache key changes only for this Filter shape, whose query could not run before.curl_close()calls inincludes/functions.php: the function has had no effect since PHP 8.0 and is deprecated in PHP 8.5. A source scan now fails on a new call in the plugin's own files. The call insetup.phpis left for a separate change, as other open pull requests edit that file.The first four fixes, except the dialog-button fix, also apply to v4.9.
Commits
f242f49test(flowview): pin run_flow_query, the report filter and field checksb53aa3erefactor(flowview): split flowview_check_fields into field validatorsabcf338refactor(flowview): split flowview_display_filter into row printersca5a022refactor(flowview): add report catalog and table classes under lib/0c0c4a4refactor(flowview): split run_flow_query into a query pipelined77cad0fix(flowview): keep the Filter in two map reports read in one thread31f7421fix(flowview): apply the Filter and time range to one thread reports5b69491fix(flowview): show the summary report read in one thread5abfdc6fix(flowview): head the Source/Destination IP report's address columnddf27d9fix(flowview): remove the stray quote from the filter dialog buttons4e23850fix(flowview): escape the graph type in the filter pageed22f93refactor: share FlowView report totals queries8969ee5fix(flowview): start the WHERE with a Stream that has no Listener286959drefactor(flowview): pass the report columns to flowview_query_report567e738style(flowview): apply php-cs-fixer to lines this change touches299453bfix: drop the curl_close() calls deprecated in PHP 8.5Overlap
#296 and #297 are open and not drafts.
run_flow_query()and anenabledfilter inflowview_display_filter(); after this lands those edits apply to the new pipeline and row printer.includes/functions.php,locales/po/cacti.potandmanifest.jsonafter this merges. Itsrun_flow_query()hunk is in code this change removes, so that one-line change has to be reapplied to the pipeline, if it is still needed.Tests
Full Pest suite passes on PHP 8.3 (593 passed, 1 skipped) and 8.5 (594 passed);
php -lclean on 8.2 and 8.3. Changed-line coverage againstdevelopis 100%. The translation template check passes. PHPStan level 6 reported nothing new in plugin code before the last four commits; it has not been re-run since. php-cs-fixer's findings on lines this change touches are applied, except two re-indentations inside the filter page's inline HTML that would misalign those lines. Complexity:run_flow_query221 to 11,flowview_display_filter68 to 2,flowview_check_fields101 to 1; no touched function is above 21.