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

/matomo.php always returns 200 OK #18851

Open
MrIsak opened this issue Feb 25, 2022 · 5 comments
Open

/matomo.php always returns 200 OK #18851

MrIsak opened this issue Feb 25, 2022 · 5 comments
Labels
c: Documentation For issues related to in-app product help messages, or to the Matomo knowledge base.

Comments

@MrIsak
Copy link

MrIsak commented Feb 25, 2022

Expected Behavior

When databas is down /matomo.php should return 503, since service is not operational.

Current Behavior

FAQ says, to monitor the "HTTP Tracker API: request to /matomo.php should return http status code 200"
It does.... all the time. Even when database is down, and not able to handle incoming data.

Ref:https://matomo.org/faq/how-to/faq_20278/

Steps to Reproduce (for Bugs)

  1. $ curl -i https://matomo.example.com/matomo.php -k
    HTTP/1.1 200 OK
  2. Shut down database
  3. $ curl -i https://matomo.example.com/matomo.php -k
    HTTP/1.1 200 OK

Context

When using loadbalancer/ssl-offloader/proxys, monitoring endpoints is crucial. Using /matomo.php is not reliable for the Tracker API as stated in FAQ.
When DB is down, clients will get a 400 error. But since matomo.php still reply with HTTP 200, loadbalancer will still send traffic to that broken endpoint.

Your Environment

  • Matomo Version:4.6.2
  • PHP Version:7.4
  • Server Operating System: Ubuntu 20.04 LTS
@MrIsak MrIsak added the Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. label Feb 25, 2022
@sgiehl
Copy link
Member

sgiehl commented Mar 4, 2022

HI @MrIsak
Thanks for creating the issue. I guess this might actually be on purpose, that the tracking doesn't return a error response code. Otherwise the failing request might be shown as error to website visitors.

@MrIsak
Copy link
Author

MrIsak commented Mar 4, 2022

Hi @sgiehl,
If that is the case, the documentation is misleading. Since /matomo.php never will result in anything else than HTTP 200-OK, it's quite useless to monitor it :P

I (from a IT-admin POV), rather get a notification from our surveillance system that something is wrong, than hiding an error in the visitors browser console; which they probably won't notice.

As I see it, there is two alternative:

  1. Database problem, matomo can't connect for whatever reason. /matomo.php still delivers 200-OK to client, no alert from surveillance. Takes X hours for administrators to notice. Results in X hours of loss of statistics.

  2. Database problem, matomo can't connect for whatever reason. /matomo.php delivers 503- Service is not available. Surveillance is configured as described in FAQ, sends alerts to administrator, whom can fix the problem. Yes, in the clients browser, the 503 will be visible, if they open network inspection tool. But on the other hand the problem will shortly be dealt with.

If you still think alternativ 1. is the way to go, how do you recommend we monitor the HTTP-tracking API?

@sgiehl
Copy link
Member

sgiehl commented Mar 7, 2022

@MrIsak Which documentation are you referring to?
From a Monitoring point of view it would indeed make sense to send another response code in that case.
But currently the code is catching all exceptions and outputs the error. See https://github.com/matomo-org/matomo/blob/4.x-dev/piwik.php#L71-L82
Maybe an option would be to look for the word Error: in the response 🤔

@tsteur what do you think of this?

@MrIsak
Copy link
Author

MrIsak commented Mar 7, 2022

@sgiehl https://matomo.org/faq/how-to/faq_20278/
"HOW DO I MONITOR THAT MATOMO SERVICE IS UP AND RUNNING?"
"HTTP Tracker API: request to /matomo.php should return http status code 200"

Looking for a specifik string in the response is one way to go. Even though I personally prefer a correct statuscode, since the possibility of string match/not match varies between different loadbalancers.

@tsteur
Copy link
Member

tsteur commented Mar 7, 2022

The FAQ would need to be updated. The matomo.php checking if Matomo is the web servers are up and running etc but doesn't test if the DB connection is working. I believe the first check /index.php?module=API&method=API.getMatomoVersion&token_auth=YOUR_TOKEN_AUTH_HERE would check this though.

In case you are wanting to use this for health checks for a load balancer, then you could

  • either use the first URL (where it requests the Matomo Version)
  • or create a new site in Matomo and change the matomo.php request to like matomo.php?rec=1&action_name=test&idsite={ID SITE OF THE NEWLY CREATED SITE}. This would then return an HTTP 400 or 500 (not sure). But not an HTTP 503.

In case you are a bit familiar with PHP, another way could be to create a simple plugin that provides an endpoint and checks the DB connection and if it fails then it would return eg an HTTP 503. The endpoint could also check if there's disk space available.

We could rename the issue to have a feature to provide an endpoint for health checks? Although I would assume that the URL mentioned to request the Matomo version could already work for this purpose.

@sgiehl sgiehl added c: Documentation For issues related to in-app product help messages, or to the Matomo knowledge base. and removed Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. labels Nov 9, 2022
@sgiehl sgiehl added this to the For Prioritization milestone Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Documentation For issues related to in-app product help messages, or to the Matomo knowledge base.
Projects
None yet
Development

No branches or pull requests

3 participants