Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
69c11c5
Add archiving metrics code with timer
caddoo Dec 16, 2025
27706fd
Pass in segment/period objects where possible
caddoo Dec 18, 2025
96f8bc0
Make plugin not installed by default
caddoo Dec 18, 2025
33d9002
Add support back in for segment archiving
caddoo Dec 18, 2025
d2666b9
Don't prematurely filter plugins
caddoo Dec 18, 2025
994a7f2
Add additional test for when archive PHP not triggered
caddoo Dec 19, 2025
47062d5
Update UI Screenshots
caddoo Dec 19, 2025
fb8c79a
Make archiving_metrics.idarchive not null
caddoo Dec 22, 2025
975d012
Store archiving period as numeric id
caddoo Dec 22, 2025
f5c2896
Store segment hash in archiving metrics
caddoo Dec 22, 2025
a8f66b5
Derive ts_started from stored start time
caddoo Dec 22, 2025
e3b2716
Use mocks for Timer tests
caddoo Dec 22, 2025
8cae024
Move ArchivingMetrics description to lang file
caddoo Dec 22, 2025
6759035
Tighten ArchivingMetrics integration test
caddoo Dec 22, 2025
a95a42f
Add strict types and license headers
caddoo Dec 22, 2025
713e56c
Move context field extraction into writer
caddoo Dec 23, 2025
c742bbf
Update screenshots
caddoo Dec 23, 2025
c448132
Store done flag as archive name
caddoo Dec 23, 2025
8dde0bb
Add support for report timings
caddoo Jan 13, 2026
099b80c
Remove null check
caddoo Jan 13, 2026
f87db72
Update index names
caddoo Jan 13, 2026
c5a6652
Add check to make sure idArchives array is always 1
caddoo Jan 13, 2026
b0d2ca0
Update index name
caddoo Jan 13, 2026
c27b944
Switch to date function
caddoo Jan 14, 2026
b9e061f
Remove date now() function
caddoo Jan 14, 2026
8e0c2ed
Add 'type' to $runs
caddoo Jan 14, 2026
9f65f9f
Add clean up task for archive metrics (#23907)
caddoo Jan 14, 2026
e4cdeb3
Integrate archiveReports with ArchiveMetrics timer (#23906)
caddoo Jan 14, 2026
0ceb6ab
Update test to remove mocked 'now'
caddoo Jan 15, 2026
0ccc6a9
Remove report from archiving metrics context
caddoo Jan 16, 2026
d26df02
Add report to context only
caddoo Jan 16, 2026
a34bf5e
Clean up test
caddoo Jan 16, 2026
b865b4c
Update documented parameter order
mneudert Jan 16, 2026
d183374
Update tests to show full year <-> day cascading behaviour
mneudert Jan 16, 2026
d4985cb
Update expected UI test files
mneudert Jan 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/global.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,10 @@
delete_reports_keep_range_reports = 0
delete_reports_keep_segment_reports = 0

[ArchivingMetrics]
; retention_days - delete archiving metrics older than this many days. Set to 0 to disable cleanup.
retention_days = 180

[mail]
defaultHostnameIfEmpty = defaultHostnameIfEmpty.example.org ; default Email @hostname, if current host can't be read from system variables
transport = ; smtp (using the configuration below) or empty (using built-in mail() function)
Expand Down
1 change: 1 addition & 0 deletions core/Application/Kernel/PluginList.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PluginList
* @var array
*/
private $corePluginsDisabledByDefault = array(
'ArchivingMetrics',
'DBStats',
'ExamplePlugin',
'ExampleCommand',
Expand Down
19 changes: 19 additions & 0 deletions core/ArchiveProcessor/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class Loader
{
private static $archivingDepth = 0;

/**
* Tracks whether the current prepareArchive run reused an existing archive instead of processing.
*
* @var boolean
*/
private $didReuseArchive = false;

/**
* @var Parameters
*/
Expand Down Expand Up @@ -103,6 +110,11 @@ public function prepareArchive($pluginName)
return Context::changeIdSite($this->params->getSite()->getId(), function () use ($pluginName) {
try {
++self::$archivingDepth;

if (self::$archivingDepth === 1) {
$this->didReuseArchive = false;
}

return $this->prepareArchiveImpl($pluginName);
} finally {
--self::$archivingDepth;
Expand Down Expand Up @@ -135,6 +147,7 @@ private function prepareArchiveImpl($pluginName)
// load existing data from archive
$data = $this->loadArchiveData();
if (sizeof($data) == 2) {
$this->didReuseArchive = true;
return $data;
}
[$idArchives, $visits, $visitsConverted, $foundRecords] = $data;
Expand All @@ -153,6 +166,7 @@ private function prepareArchiveImpl($pluginName)
$data = $this->loadArchiveData();

if (sizeof($data) == 2) {
$this->didReuseArchive = true;
return $data;
}

Expand Down Expand Up @@ -542,6 +556,11 @@ public function canSkipThisArchiveWithReason(): array
];
}

public function didReuseArchive(): bool
{
return $this->didReuseArchive;
}

private function hasChildArchivesInPeriod($idSite, Period $period): bool
{
$cacheKey = CacheId::siteAware('Archiving.hasChildArchivesInPeriod.' . $period->getRangeString(), [$idSite]);
Expand Down
19 changes: 19 additions & 0 deletions core/Db/Schema/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,25 @@ public function getTablesCreateSql()
) $tableOptions
",

'archiving_metrics' => "CREATE TABLE {$prefixTables}archiving_metrics (
metadataid BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
idarchive BIGINT UNSIGNED NOT NULL,
idsite INTEGER UNSIGNED NOT NULL,
archive_name VARCHAR(255) NOT NULL,
date1 DATE NOT NULL,
date2 DATE NOT NULL,
period TINYINT UNSIGNED NOT NULL,
ts_started DATETIME NOT NULL,
ts_finished DATETIME NOT NULL,
total_time BIGINT UNSIGNED NOT NULL,
total_time_exclusive BIGINT UNSIGNED NOT NULL,
PRIMARY KEY(metadataid),
INDEX index_idarchive(idarchive),
INDEX index_idsite_archive_name(idsite, archive_name),
INDEX index_idsite_date1_period(idsite, date1, period)
) $tableOptions
",

'archive_invalidations' => "CREATE TABLE `{$prefixTables}archive_invalidations` (
idinvalidation BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
idarchive INTEGER UNSIGNED NULL,
Expand Down
62 changes: 62 additions & 0 deletions core/Updates/5.7.0-b2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Updates;

use Piwik\Updater;
use Piwik\Updater\Migration\Factory as MigrationFactory;
use Piwik\Updates as PiwikUpdates;
use Piwik\Updater\Migration;

/**
* Update for version 5.7.0-b1
*/
class Updates_5_7_0_b2 extends PiwikUpdates
{
/**
* @var MigrationFactory
*/
private $migration;

public function __construct(MigrationFactory $factory)
{
$this->migration = $factory;
}

/**
* @param Updater $updater
* @return Migration[]
*/
public function getMigrations(Updater $updater)
{
return [
$this->migration->db->createTable('archiving_metrics', [
'metadataid' => 'BIGINT UNSIGNED NOT NULL AUTO_INCREMENT',
'idarchive' => 'BIGINT UNSIGNED NOT NULL',
'idsite' => 'INTEGER UNSIGNED NOT NULL',
'archive_name' => 'VARCHAR(255) NOT NULL',
'date1' => 'DATE NOT NULL',
'date2' => 'DATE NOT NULL',
'period' => 'TINYINT UNSIGNED NOT NULL',
'ts_started' => 'DATETIME NOT NULL',
'ts_finished' => 'DATETIME NOT NULL',
'total_time' => 'BIGINT UNSIGNED NOT NULL',
'total_time_exclusive' => 'BIGINT UNSIGNED NOT NULL',
], ['metadataid']),
$this->migration->db->addIndex('archiving_metrics', ['idarchive'], 'index_idarchive'),
$this->migration->db->addIndex('archiving_metrics', ['idsite', 'archive_name'], 'index_idsite_archive_name'),
$this->migration->db->addIndex('archiving_metrics', ['idsite', 'date1', 'period'], 'index_idsite_date1_period'),
];
}

public function doUpdate(Updater $updater)
{
$updater->executeMigrations(__FILE__, $this->getMigrations($updater));
}
}
2 changes: 1 addition & 1 deletion core/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class Version
* The current Matomo version.
* @var string
*/
public const VERSION = '5.7.0-b1';
public const VERSION = '5.7.0-b2';

public const MAJOR_VERSION = 5;

Expand Down
64 changes: 64 additions & 0 deletions plugins/ArchivingMetrics/ArchivingMetrics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

declare(strict_types=1);

namespace Piwik\Plugins\ArchivingMetrics;

use Piwik\Period;
use Piwik\Segment;

class ArchivingMetrics extends \Piwik\Plugin
{
public function registerEvents()
{
return [
'CoreAdminHome.archiveReports.start' => 'onArchiveReportsStart',
'CoreAdminHome.archiveReports.complete' => 'onArchiveReportsComplete',
];
}

public function onArchiveReportsStart(
int $idSite,
Period $period,
Segment $segment,
string $plugin,
$report,
bool $isArchivePhpTriggered
): void {
$timer = Timer::getInstance($isArchivePhpTriggered);
$context = $this->buildContext($idSite, $period, $segment, $plugin, $report);

$timer->start($context);
}

/**
* @param int[] $idArchives
*/
public function onArchiveReportsComplete(
int $idSite,
Period $period,
Segment $segment,
string $plugin,
$report,
bool $isArchivePhpTriggered,
array $idArchives,
bool $wasCached
): void {
$timer = Timer::getInstance($isArchivePhpTriggered);
$context = $this->buildContext($idSite, $period, $segment, $plugin, $report);

$timer->complete($context, $idArchives, $wasCached);
}

private function buildContext(int $idSite, Period $period, Segment $segment, string $plugin, $report): Context
{
return new Context($idSite, $period, $segment, $plugin, $report);
}
}
20 changes: 20 additions & 0 deletions plugins/ArchivingMetrics/Clock/Clock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

declare(strict_types=1);

namespace Piwik\Plugins\ArchivingMetrics\Clock;

final class Clock implements ClockInterface
{
public function microtime(): float
{
return microtime(true);
}
}
17 changes: 17 additions & 0 deletions plugins/ArchivingMetrics/Clock/ClockInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

declare(strict_types=1);

namespace Piwik\Plugins\ArchivingMetrics\Clock;

interface ClockInterface
{
public function microtime(): float;
}
67 changes: 67 additions & 0 deletions plugins/ArchivingMetrics/Context.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

declare(strict_types=1);

namespace Piwik\Plugins\ArchivingMetrics;

use Piwik\Period;
use Piwik\Segment;

final class Context
{
/**
* @var int
*/
public $idSite;

/**
* @var Period
*/
public $period;

/**
* @var Segment
*/
public $segment;

/**
* @var string
*/
public $plugin;

/**
* @var false|string|string[]
*/
public $report;

/**
* @param false|string|string[] $report
*/
public function __construct(int $idSite, Period $period, Segment $segment, string $plugin, $report = false)
{
$this->idSite = $idSite;
$this->period = $period;
$this->segment = $segment;
$this->plugin = $plugin;
$this->report = $report;
}

public function getKey(): string
{
return implode('|', [
$this->idSite,
$this->period->getLabel(),
$this->segment->getString(),
$this->period->getDateTimeStart()->toString('Y-m-d'),
$this->period->getDateTimeEnd()->toString('Y-m-d'),
$this->plugin,
]);
}
}
Loading
Loading