Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle "Got invalid response from API request" better #14515

Closed
fdellwing opened this issue Jun 6, 2019 · 5 comments
Closed

Handle "Got invalid response from API request" better #14515

fdellwing opened this issue Jun 6, 2019 · 5 comments
Labels
answered For when a question was asked and we referred to forum or answered it. c: Usability For issues that let users achieve a defined goal more effectively or efficiently.

Comments

@fdellwing
Copy link
Contributor

We often have users on the forum that have some problem with the cron archiving.

Currently, the achiever tries to parse the response and fails. It then produces this two lines:

Jun 06 10:00:10 matomo matomo-console[871]: WARNING [2019-06-06 08:00:10] 871  /nix/store/5yq6hsmabykncchhxh44ay25nql87z4h-matomo-3.9.1/share/core/Common.php(271): Notice - unserialize(): Error at offset 0 of 295 bytes - Matomo 3.9.1 - Please report this message in the Matomo forums: https://forum.matomo.org (please do a search first as it might have been reported already)
Jun 06 10:00:10 matomo matomo-console[871]: ERROR [2019-06-06 08:00:10] 871  Empty or invalid response 'Got invalid response from API request: https://matomo.matomo?module=API&method=API.get&idSite=1&period=day&date=last6&format=php&trigger=archivephp&token_auth=removed. Response was 'curl_exec: Could not resolve host: matomo.matomo. Hostname requested was: matomo.matomo'' for website id 1, Time elapsed: 0.307s, skipping

If you know where to look, you are easily able to find the reason for the error curl_exec: Could not resolve host: matomo.matomo. Hostname requested was: matomo.matomo. But for a user using this the first time, this is hard to spot.

Another example for such an error message would be:

a:2:{s:6:"result";s:5:"error";s:7:"message";s:427:"SQLSTATE[42000]: Syntax error or access violation: 1064 Routing query to backend failed. See the error log for further details. - in plugin Actions, caused by: SQLSTATE[42000]: Syntax error or access violation: 1064 Routing query to backend failed. See the error log for further details., caused by: SQLSTATE[42000]: Syntax error or access violation: 1064 Routing query to backend failed. See the error log for further details.";}

Again preceded by ERROR [2019-03-19 14:58:46] 17845 Got invalid response from API request: ?module=API&method=API.get&idSite=52&period=day&date=last52&format=php&trigger=archivephp. Response was and on most devices out of sight of the user to the right.

It would be better to really print out what the error was, even on a new line.

Jun 06 10:00:10 matomo matomo-console[871]: ERROR [2019-06-06 08:00:10] 871  Empty or invalid response 'Got invalid response from API request: https://matomo.matomo?module=API&method=API.get&idSite=1&period=day&date=last6&format=php&trigger=archivephp&token_auth=removed.

Response was 'curl_exec: Could not resolve host: matomo.matomo. Hostname requested was: matomo.matomo'

' for website id 1, Time elapsed: 0.307s, skipping
@Findus23 Findus23 added the c: Usability For issues that let users achieve a defined goal more effectively or efficiently. label Jun 6, 2019
@Tealk
Copy link

Tealk commented Dec 4, 2019

i get the same error, how do i fix it?

@kwisatz
Copy link

kwisatz commented Jan 19, 2020

In my case, the error is not easy to spot and the only way to find out what is causing it was by guessing, reading other issues in here (e.g. #15123) and checking out the mariadb error log.

Matomo itself doesn't give a clue (or the wrong clue entirely):

INFO [2020-01-19 01:36:09] 14513  Archived website id = 12, period = month, 0 segments, 17876 visits in last 52 months, 760 visits this month, Time elapsed: 1.658s                                            
INFO [2020-01-19 01:36:09] 14513  Will pre-process for website id = 12, period = year, date = last7                                                     
INFO [2020-01-19 01:36:09] 14513  - pre-processing all visits                                                                                                                                                   
ERROR [2020-01-19 01:36:32] 14513  Got invalid response from API request: ?module=API&method=API.get&idSite=12&period=year&date=last7&format=php&trigger=archivephp. The response was empty. This usually means a server error. A solution to this error is generally to increase the value of 'memory_limit' in your php.ini f
ile.  For more information and the error message please check in your PHP CLI error log file. As this core:archive command triggers PHP processes over the CLI, you can find where PHP CLI logs are stored by running this command: php -i | grep error_log
INFO [2020-01-19 01:36:32] 14513  Archived website id = 12, period = year, 0 segments, 0 visits in last 7 years, 0 visits this year, Time elapsed: 22.715s                                                     
INFO [2020-01-19 01:36:32] 14513  Archived website id = 12, 3 API requests, Time elapsed: 25.563s [9/11 done] 

It also did not write to the php-cli error log.

@tsteur
Copy link
Member

tsteur commented Jan 20, 2020

@kwisatz Maybe check if your PHP ini settings if possible to see if you can enable more granular logging? It seems Matomo did not get any information from PHP so maybe it could be even a segfault or something. Have you checked the matomo.log in case it is enabled?

See https://matomo.org/faq/troubleshooting/faq_115/
Where it says you can add a line like this to config/config.ini.php

[log]
log_writers[] = file
log_writers[] = screen

Not sure but it might also help to launch the archiver using core:archive -vvv in case you are using CLI archiving.

@mattab
Copy link
Member

mattab commented Jan 21, 2020

it's really valuable to make error reporting clearer and easier 👍 recently we've actually made a few small improvements to how errors are reported in core:archive, and now we will report the stack trace along with the error, and make error reporting cleaner, etc. if you're still finding it's not clear enough, please create a new issue with the error output and we'll look into it.

@mattab mattab closed this as completed Jan 21, 2020
@mattab mattab added the answered For when a question was asked and we referred to forum or answered it. label Jan 21, 2020
@kwisatz
Copy link

kwisatz commented Jan 21, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it. c: Usability For issues that let users achieve a defined goal more effectively or efficiently.
Projects
None yet
Development

No branches or pull requests

6 participants