Skip to content

refactor(flowview): split run_flow_query, the report filter and field checks; fix single-thread reports - #324

Open
somethingwithproof wants to merge 12 commits into
Cacti:developfrom
somethingwithproof:refactor/flowview-query-pipeline
Open

somethingwithproof wants to merge 12 commits into
Cacti:developfrom
somethingwithproof:refactor/flowview-query-pipeline

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

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: 87 cases for run_flow_query() (every report type, single and parallel paths, with and without Filter and time range; the SQL issued and the returned data), 23 for flowview_display_filter() (rendered markup) and 86 for flowview_check_fields(). Every refactor commit passes them unchanged. Each fix: commit then updates only the expectations for the defect it fixes, with a test that fails without the fix.

Structure

  • flowview_check_fields(): one validator per field group; complexity 101 to at most 10.
  • flowview_display_filter(): row printers; complexity 68 to at most 21.
  • run_flow_query(): a query pipeline with report catalog, SQL builder, executor and table classes under lib/.

Fixes

  • Single-thread path: apply the Filter and time range to single-map reports; keep the Filter in two-map report 11; show the summary report (99) instead of warnings and N/A cells.
  • Head report 11's address column "Source/Destination IP" (the check compared against the wrong report id).
  • Remove the stray '> after the filter dialog button labels.
  • Escape the graph type in the filter page.

All except the dialog-button fix also apply to v4.9.

Overlap

Draft #296 adds guards in run_flow_query() and an enabled filter in flowview_display_filter(); after this lands those edits apply to the new pipeline and row printer. Draft #297's one-line change is in a branch this refactor removes.

Tests

Full Pest suite passes on PHP 8.3 (588 passed, 1 skipped) and 8.5 (589 passed); php -l clean on 8.2. Changed-line coverage 100% (644/644). PHPStan level 6 reports nothing new in plugin code. Complexity: run_flow_query 221 to 11, flowview_display_filter 68 to 2, flowview_check_fields 101 to 1; no touched function is above 21.

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>
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

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.

Split run_flow_query, flowview_display_filter and flowview_check_fields; fix single-thread report defects

1 participant