matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.68k stars 2.62k forks source link

[Bug] Unhandled exception processing >50,000 dimensions for custom reports #22579

Closed marcel-innocraft closed 5 days ago

marcel-innocraft commented 1 week ago

What happened?

An unhandled exception is thrown when the code below runs for Dimension::TYPE_DURATION_MS and $value contains __mtm_ranking_query_others__ (from RankingQuery::LABEL_SUMMARY_ROW). This value is present when over 50,000 dimensions are being grouped/aggregated.

This issue is identified on Cloud but is not specific to cloud.

core/Columns/Dimension.php:422

public function groupValue($value, $idSite)
{
switch ($this->type) {
case Dimension::TYPE_URL:
return str_replace(array('http://', 'https://'), '', $value);
case Dimension::TYPE_BOOL:
return !empty($value) ? '1' : '0';
case Dimension::TYPE_DURATION_MS:
return round($value / 1000, 2) * 1000; // because we divide we need to group them and cannot do this in formatting step
}
return $value;
}

What should happen?

The rollup special value RankingQuery::LABEL_SUMMARY_ROW should be handled appropriately during archiving. This currently affects custom report archiving and we are seeing 000s of errors logged in the past couple of weeks. An example of the console command causing the issue is:

./console customreports:archive --idsites=1 --date=2024-07-01 --idreport=7

How can this be reproduced?

A custom report is created with the dimensions below:

Screenshot 2024-09-12 at 3 59 16 PM

Matomo version

5 (Cloud)

PHP version

8.1

Server operating system

No response

What browsers are you seeing the problem on?

Not applicable (e.g. an API call etc.)

Computer operating system

No response

Relevant log output

Uncaught exception: TypeError: Unsupported operand types: string / int in core/Columns/Dimension.php:422
Stack trace:
#0 plugins/CustomReports/RecordBuilders/CustomReport.php(475): Piwik\Columns\Dimension->groupValue()
#1 plugins/CustomReports/RecordBuilders/CustomReport.php(336): Piwik\Plugins\CustomReports\RecordBuilders\CustomReport->makeRegularReport()
#2 plugins/CustomReports/RecordBuilders/CustomReport.php(148): Piwik\Plugins\CustomReports\RecordBuilders\CustomReport->aggregateReport()
#3 core/ArchiveProcessor/RecordBuilder.php(98): Piwik\Plugins\CustomReports\RecordBuilders\CustomReport->aggregate()
#4 plugins/CustomReports/Commands/ArchiveReports.php(266): Piwik\ArchiveProcessor\RecordBuilder->buildFromLogs()
#5 plugins/CustomReports/Commands/ArchiveReports.php(134): Piwik\Plugins\CustomReports\Commands\ArchiveReports->archiveCustomReports()
#6 core/Plugin/ConsoleCommand.php(109): Piwik\Plugins\CustomReports\Commands\ArchiveReports->doExecute()
#7 vendor/symfony/console/Command/Command.php(298): Piwik\Plugin\ConsoleCommand->execute()
#8 core/Plugin/ConsoleCommand.php(124): Symfony\Component\Console\Command\Command->run()
#9 vendor/symfony/console/Application.php(1040): Piwik\Plugin\ConsoleCommand->run()
#10 vendor/symfony/console/Application.php(301): Symfony\Component\Console\Application->doRunCommand()
#11 core/Console.php(113): Symfony\Component\Console\Application->doRun()
#12 [internal function]: Piwik\Console->originDoRun()
#13 core/Console.php(152): call_user_func()
#14 core/Access.php(672): Piwik\Console->Piwik\{closure}()
#15 core/Console.php(153): Piwik\Access::doAsSuperUser()
#16 core/Console.php(92): Piwik\Console->doRunImpl()
#17 vendor/symfony/console/Application.php(171): Piwik\Console->doRun()
#18 console(32): Symfony\Component\Console\Application->run()
#19 {main}
Uncaught exception in core/Columns/Dimension.php line 422:
Unsupported operand types: string / int

Validations

sgiehl commented 1 week ago

Thanks @marcel-innocraft for the detailed report. I'll have a quick look if it's easy to fix.