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.73k stars 2.63k forks source link

Fatal error: ceil(): Argument #1 ($num) must be of type int|float, string given in BaseDraw.php #19940

Open tsteur opened 1 year ago

tsteur commented 1 year ago

See details below:

Error: {"message":"ceil(): Argument #1 ($num) must be of type int|float, string given","file":"\/vendor\/szymach\/c-pchart\/src\/BaseDraw.php","line":383,"request_id":"d387f","backtrace":" on \/vendor\/szymach\/c-pchart\/src\/BaseDraw.php(383)\n#0 \/vendor\/szymach\/c-pchart\/src\/BaseDraw.php(383): ceil('1.401.53')\n#1 \/vendor\/szymach\/c-pchart\/src\/BaseDraw.php(342): CpChart\BaseDraw->processScale(0, '1.401.53', 2, Array, 0)\n#2 \/vendor\/szymach\/c-pchart\/src\/Draw.php(2694): CpChart\BaseDraw->computeScale(0, '1.401.53', 2, Array, 0)\n#3 \/plugins\/ImageGraph\/StaticGraph\/GridGraph.php(177): CpChart\Draw->drawScale(Array)\n#4 \/plugins\/ImageGraph\/StaticGraph\/Evolution.php(24): Piwik\Plugins\ImageGraph\StaticGraph\GridGraph->initGridChart(true, 691053, false, true, true)\n#5 \/plugins\/ImageGraph\/API.php(506): Piwik\Plugins\ImageGraph\StaticGraph\Evolution->renderGraph()\n#6 [internal function]: Piwik\Plugins\ImageGraph\API->get(1, 'day', '2022-10-03,2022...', 'Goals', 'get', 'evolution', 0, 'revenue', false, true, 984, 450, '27', '27', '1', 'ecommerceOrder', '3450A3,43a047', '222222', 'efefef', 'dcdcdc', false, '0', false, false)\n#7 \/core\/API\/Proxy.php(244): call_user_func_array(Array, Array)\n#8 \/core\/Context.php(28): Piwik\API\Proxy->Piwik\API\{closure}()\n#9 \/core\/API\/Proxy.php(335): Piwik\Context::executeWithQueryParameters(Array, Object(Closure))\n#10 \/core\/API\/Request.php(267): Piwik\API\Proxy->call('\\Piwik\\Plugins\\...', 'get', Array)\n#11 \/plugins\/API\/Controller.php(45): Piwik\API\Request->process()\n#12 [internal function]: Piwik\Plugins\API\Controller->index()\n#13 \/core\/FrontController.php(631): call_user_func_array(Array, Array)\n#14 \/core\/FrontController.php(169): Piwik\FrontController->doDispatch('API', false, Array)\n#15 \/core\/dispatch.php(32): Piwik\FrontController->dispatch()\n#16

URL: /index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=Goals&apiAction=get&token_auth=XYZANONYMIZED&idGoal=ecommerceOrder&period=day&date=2022-10-03,2022-11-01&filter_sort_column=revenue&column=revenue&columns=revenue&language=en&width=984&height=450&fontSize=27&showMetricTitle=0&aliasedGraph=1&legendAppendMetric=0&backgroundColor=efefef&gridColor=dcdcdc&colors=3450A3%2C43a047&legendFontSize=27&cacherand=7280344

sgiehl commented 1 year ago

This is yet another issue with numbers that a formatted to early. The ImageGraph fetches the numbers formatted from the database. Using those for calculations might result in failures. There is actually some code, that tries to convert the formatted number back to something usable:

https://github.com/matomo-org/matomo/blob/a36b45a3764cd28303d2ce27c600c7d6f5a5ed20/plugins/ImageGraph/API.php#L557-L573

But this part actually might result in a invalid number. The error above seems to come from a revenue like 1,401.53 $. The code removes the currency and replaces the , with .. So the number being used i 1.401.53, which can't work.

I tried simply using the unformatted metrics for ImageGraph (see https://github.com/matomo-org/matomo/compare/m19940?expand=1), which fixes the problem above. But that means that most percent values, like conversion rate, are then not formatted at all and are used as their rate value, e.g. 0.15 instead of 15

This is actually a more general problem. Not sure if we already have a extra issue about that or only discussed that on various other ones. But the percentage metrics should actually not do any calculations while formatting. We might need to implement a way, that those metrics are always "calculated" automatically and formatted only when needed.

justinvelluppillai commented 1 year ago

Do we now have an issue tracking the more general case @sgiehl, or could you please create one?

tsteur commented 1 year ago

FYI this happened again a few times in GridGraph.php . Not BaseDraw.php

michalkleiner commented 1 year ago

Thanks @tsteur, yep, that was raised in #20616 which I linked to this issue and marked as duplicate due to the same symptoms and that it will be resolved at the same time.

tsteur commented 1 year ago

This has happened again in ceil(): Argument #1 ($num) must be of type int|float, string given","file":"/plugins\/ImageGraph\/StaticGraph\/GridGraph.php","line":137,"

tsteur commented 1 year ago

This happened again: Error: {"message":"ceil(): Argument #1 ($num) must be of type int|float, string given","file":"/plugins\/ImageGraph\/StaticGraph\/GridGraph.php","line":137

tsteur commented 1 year ago

This happened again

samjf commented 1 year ago

I've seen multiple reports of this in cloud alerts/logs. I've got a bit more info to add. Of all the alerts the majority are from the user agents (edited) Dalvik.../Android and Appcelerator Titanium/@"0.0.0" (iPhone...). Also, as far as I can see they are mostly date ranges.

Payload example:

    "module": "API",
    "method": "ImageGraph.get",
    "idSite": "1",
    "apiModule": "Goals",
    "apiAction": "get",
    "token_auth": "...",
    "idGoal": "ecommerceOrder",
    "period": "day",
    "date": "2022-09-01,2022-11-01",
    "filter_sort_column": "revenue",
    "column": "revenue",
    "columns": "revenue",
    "language": "en",
    "width": "900",
    "height": "450",
    "fontSize": "25",
    "showMetricTitle": "0",
    "aliasedGraph": "1",
    "legendAppendMetric": "0",
    "backgroundColor": "efefef",
    "gridColor": "dcdcdc",
    "colors": "3450A3,43a047",
    "legendFontSize": "25",
    "cacherand": "1111111",
    "filter_limit": 100
}
tsteur commented 1 year ago

This happened again

tsteur commented 1 year ago

This happened again

tsteur commented 1 year ago

This happened again

tsteur commented 1 year ago

This is still happening regularly

tsteur commented 1 year ago

This is still happening

tsteur commented 11 months ago

This error is still happening in Matomo 5. Users are still running into this bug. Also happened Oct 24th and Oct 23rd and Oct 21st.

Note that below is about GridGraph.php and not BaseDraw.php. I comment them in here as my other specific issue for this in https://github.com/matomo-org/matomo/issues/20616 was closed with a reference being a duplicate.

Can we have a fix for this some time? cc @Stan-vw

Error: {"message":"ceil(): Argument #1 ($num) must be of type int|float, string given","file":"\/plugins\/ImageGraph\/StaticGraph\/GridGraph.php","line":137,"request_id":"4d5dd","backtrace":" on \/plugins\/ImageGraph\/StaticGraph\/GridGraph.php(137)\n#0 \/plugins\/ImageGraph\/StaticGraph\/GridGraph.php(137): ceil('8.841.60')\n#1 \/plugins\/ImageGraph\/StaticGraph\/Evolution.php(24): Piwik\Plugins\ImageGraph\StaticGraph\GridGraph->initGridChart(true, 691053, false, true, true)\n#2 \/plugins\/ImageGraph\/API.php(504): Piwik\Plugins\ImageGraph\StaticGraph\Evolution->renderGraph()\n#3 [internal function]: Piwik\Plugins\ImageGraph\API->get(5, 'day', 'last7', 'Goals', 'get', 'evolution', 0, 'revenue', false, true, 996, 394, '24', '24', '1', 'ecommerceOrder', '3450A3,43a047', '222222', 'efefef', 'dcdcdc', false, '0', false, false)\n#4 \/core\/API\/Proxy.php(255): call_user_func_array(Array, Array)\n#5 \/core\/Context.php(28): Piwik\API\Proxy->Piwik\API\{closure}()\n#6 \/core\/API\/Proxy.php(346): Piwik\Context::executeWithQueryParameters(Array, Object(Closure))\n#7 \/core\/API\/Request.php(272): Piwik\API\Proxy->call('\\Piwik\\Plugins\\...', 'get', Array)\n#8 \/plugins\/API\/Controller.php(45): Piwik\API\Request->process()\n#9 [internal function]: Piwik\Plugins\API\Controller->index()\n#10 \/core\/FrontController.php(637): call_user_func_array(Array, Array)\n#11 \/core\/FrontController.php(169): Piwik\FrontController->doDispatch('API', false, Array)\n#12 \/core\/dispatch.php(32): Piwik\FrontController->dispatch()\n#13 \/index.php(25): require_once('\/c...')\n#14 {main}","safemode_backtrace":"#0 [internal function]: Piwik\Plugins\Cloud\Controller->safemode(Array)\n#1 \/core\/FrontController.php(637): call_user_func_array(Array, Array)\n#2 \/core\/FrontController.php(16

tsteur commented 10 months ago

This is still happening multiple times per week for customers

michalkleiner commented 10 months ago

Looking at GridGraph L137, we use ceil method there. That can take strings as long as they can be converted to numbers, so the issue here would be that we have a non-numeric string in the data, or a number that has been double sanitised or wrongly encoded/decoded and ended up e.g. with two decimal dots or so.

Stan-vw commented 10 months ago

I understand from the team that it's blocked by https://github.com/matomo-org/matomo/issues/20701 which isn't a quick fix

tsteur commented 9 months ago

This just happened again quite a few times:

Error: {"message":"ceil(): Argument #1 ($num) must be of type int|float, string given","file":"\/plugins\/ImageGraph\/StaticGraph\/GridGraph.php","line":137,"request_id":"f27fd","backtrace":" on \/plugins\/ImageGraph\/StaticGraph\/GridGraph.php(137)\n#0 \/plugins\/ImageGraph\/StaticGraph\/GridGraph.php(137): ceil('0.0.0.0')