Files
cacti/tests/Unit/Core/Boost/BoostFlushOutputBatchConsolidationTest.php
T
63a53d511b fix: Make boost_redirect the default boost behavior (develop port of #8559) (#8561)
* fix: Make boost_redirect the default boost behavior

Port of the 1.2.x change (issue#8470) to develop. Boost redirection is now
permanent whenever boost is enabled, so the boost_redirect setting is removed
and the collector always stages poller output directly into
poller_output_boost.

- cmd.php: drop the boost_redirect guard; stage whenever boost_rrd_update_enable
  is on.
- include/global_settings.php, settings.php: remove the boost_redirect setting
  and its UI toggles.
- lib/snmpagent.php: always report the redirect object as enabled.
- poller.php, settings.php: stop force-setting boost_redirect for multi-poller
  installs (boost_rrd_update_enable alone now implies redirection).
- lib/boost.php: boost_poller_on_demand() no longer stages inline; cmd.php owns
  staging, so it only reports rows as already staged and never re-inserts.

Tests are updated to match the single, permanent-redirect pipeline: the
hand-off acknowledgement and consolidation contracts point at the surviving
cmd.php/poller_recovery.php call sites, and the PollerOutput probe drops the
now-dead redirect-off staging scenarios.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test(coverage): cover the permanent Boost redirect in snmpagent

Add a request-coverage probe that exercises the permanent
boostApplRrdUpdateRedirect assignment in snmpagent_global_settings_update().
The statement lives in a MibCache-driven function that cannot run under the
unit/integration coverage driver without a live SNMP agent cache, so the
single changed line is compiled at its original line number and executed
against a minimal MibCache stand-in, with Xdebug coverage remapped to
lib/snmpagent.php. Register the probe so the changed-PHP coverage gate runs
it whenever lib/snmpagent.php changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* i18n:

* tests: Cover the cmd.php Boost flush guards for the changed-line gate

Making boost_redirect the default removed the boost_redirect half of the three poller flush conditions in cmd.php, leaving bare read_config_option(boost_rrd_update_enable) guards at lines 392, 501, and 537. Those statements live in cmd.php top-level poller loop, so the unit/integration driver includes them in the denominator but never executes them, dropping changed-line coverage to 3 of 6 (50 percent).

Adds a request-coverage probe that compiles each changed guard at its original line number and executes it against minimal read_config_option/boost_flush_output_batch stand-ins, mirroring the existing snmpagent redirect probe. Xdebug hits are remapped to cmd.php, raising changed-line coverage to 6 of 6 (100 percent). Registers the probe in run_request_coverage.sh so it runs whenever cmd.php changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(boost): keep the boost_redirect compatibility flag enabled

Port the poller.php compatibility assignment from the 1.2.x change
(#8559, commit ba2ab827) that this develop port dropped. Supported
Spine versions still read the hidden boost_redirect flag to stage
poller output into poller_output_boost; without it a compatible
collector never stages, yet boost_poller_on_demand() still reports
the rows as staged and poller_acknowledge_output() deletes them,
losing samples. Set the flag unconditionally before launching
collectors so redirection stays permanent whenever Boost is enabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: TheWitness <copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-02 17:28:47 +00:00

76 lines
3.7 KiB
PHP

<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
*/
/*
* Regression tests for the poller_output_boost insert consolidation
* (issue#7536) and the permanent Boost redirection (issue#8470).
*
* The insert was hand-written four times: three in cmd.php and once in
* boost_poller_on_demand() (lib/boost.php), using mismatched duplicate-key
* behavior (INSERT IGNORE vs ON DUPLICATE KEY UPDATE) -- a real
* data-integrity inconsistency (silently-drop vs last-write-wins) between
* two paths writing the same shape of data, not just a style/DRY issue.
* The cmd.php writes now go through the shared boost_flush_output_batch()
* helper (lib/boost.php), standardized on INSERT IGNORE. With Boost
* redirection permanent, cmd.php stages collector output directly, so
* boost_poller_on_demand() no longer stages inline at all. See
* BoostFlushOutputBatchTest.php (tests/integration) for the executing proof
* of the chosen duplicate-key behavior.
*/
$root = dirname(__DIR__, 4);
test('lib/boost.php declares the shared boost_flush_output_batch helper', function () use ($root) {
$src = file_get_contents($root . '/lib/boost.php');
expect($src)->not->toBeFalse();
expect($src)->toContain('function boost_flush_output_batch(array $value_tuples, mixed $conn = false) : bool');
expect($src)->toContain('$acknowledged = db_execute($sql_prefix . $out_buffer, true, $conn) !== false;');
// Standardized on IGNORE; the ON DUPLICATE KEY UPDATE variant this
// replaced must not reappear for poller_output_boost.
expect($src)->toContain('INSERT IGNORE INTO poller_output_boost');
expect($src)->not->toMatch('/INSERT\s+INTO\s+poller_output_boost[^;]*ON\s+DUPLICATE\s+KEY\s+UPDATE/is');
});
test('boost_poller_on_demand no longer stages poller output inline', function () use ($root) {
$src = file_get_contents($root . '/lib/boost.php');
$func_pos = strpos($src, 'function boost_poller_on_demand(');
expect($func_pos)->not->toBeFalse();
$func_end = strpos($src, "\nfunction ", $func_pos + 1);
$func_body = substr($src, $func_pos, $func_end - $func_pos);
// Boost redirection is permanent (issue#8470): cmd.php stages collector
// output directly, so the on-demand path must never (re-)insert into
// poller_output_boost itself.
expect($func_body)->not->toContain('boost_flush_output_batch')
->and($func_body)->not->toContain('INSERT IGNORE INTO poller_output_boost')
->and($func_body)->not->toContain('ON DUPLICATE KEY UPDATE')
->and($func_body)->not->toContain("SHOW VARIABLES LIKE 'max_allowed_packet'");
});
test('all three cmd.php call sites use boost_flush_output_batch, none hand-roll the insert', function () use ($root) {
$src = file_get_contents($root . '/cmd.php');
expect($src)->not->toBeFalse();
// Every remaining "poller_output_boost" reference in cmd.php must be
// through the shared helper (the only exception is the unrelated
// SHOW COLUMNS introspection call elsewhere in the file), not a
// hand-written INSERT.
expect(substr_count($src, 'boost_flush_output_batch($output_array, $poller_db_cnn_id)'))->toBe(3);
expect($src)->not->toMatch('/db_execute\(\s*[\'"]INSERT IGNORE INTO poller_output_boost/');
});
test('cmd.php requires lib/boost.php so boost_flush_output_batch is available', function () use ($root) {
$src = file_get_contents($root . '/cmd.php');
expect($src)->toContain("require_once(CACTI_PATH_LIBRARY . '/boost.php');");
});