Repository navigation
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
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>
|
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: 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 forflowview_display_filter()(rendered markup) and 86 forflowview_check_fields(). Every refactor commit passes them unchanged. Eachfix: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 underlib/.Fixes
'>after the filter dialog button labels.All except the dialog-button fix also apply to v4.9.
Overlap
Draft #296 adds guards in
run_flow_query()and anenabledfilter inflowview_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 -lclean on 8.2. Changed-line coverage 100% (644/644). PHPStan level 6 reports nothing new in plugin code. Complexity:run_flow_query221 to 11,flowview_display_filter68 to 2,flowview_check_fields101 to 1; no touched function is above 21.