coderedcorp / wagtail-cache

A simple page cache for Wagtail based on the Django cache middleware.
Other
87 stars 29 forks source link

Add option to raise Redis errors #77

Closed aweakley closed 3 months ago

aweakley commented 3 months ago

Since 583f16d2124e99f8d3fe965397645c66ce26a3b9 Redis fetch errors are suppressed.

We've been having intermittent problems with Redis which we're working on. When we deployed this update, we started seeing intermittent really high loads on the database now.

I think what's happening is that Redis becomes slow or disconnected (the cause of that remains a mystery, but not the issue here), exceptions are suppressed and the request goes through to the backend, and the response is not cached. Things are slow so people probably hit reload many times, which makes it worse.

So in this case where we're using Redis to protect our other infrastructure, rather than just to make things fast, I'd like to be able to quickly raise Redis errors rather than pass all traffic through to the backend.

vsalvino commented 3 months ago

I don't think it would be the job of the cache to throw errors when your backend is unable to handle the traffic. The cache is effectively more transparent now, which is a good thing, and we don't want to change that. The reason being - that there are so many components that could fail (redis, database, server, reverse proxy, API calls, smtp server, etc.). The cache is not the appropriate place to handle all of those errors.

Luckily, we are now logging caching errors, so you can tap into them via Django logging (to log to file, send emails, etc.). The entry will look something like this in settings.py. See the docs here: https://docs.djangoproject.com/en/5.1/topics/logging/#configuring-logging

LOGGING = {
    ...
    "loggers": {
        "wagtail-cache": { ... }
    }
}

In your situation, if you want to protect your infrastructure, the ONLY real solution would be a reverse proxy. Most people use NGINX for this, or a DNS-based reverse proxy such as Cloudflare (with the orange cloud icon turned on). If you are a CodeRed Cloud customer, the platform automatically shows a "Temporarily out of service" message when the site gets overloaded.

Alternatively, you might want to write your own Django middleware that handles this in your own way. For example, if a certain type of error is returned, show a user-friendly message.

aweakley commented 3 months ago

I just want to know if there's a Redis error though, and currently that's suppressed and hidden from me.

vsalvino commented 3 months ago

It is not being suppressed or hidden - it is being logged to the "wagtail-cache" logger. You should be monitoring these logs. I provided the info on how to monitor them in the previous comment.

aweakley commented 1 month ago

Ohhh, sorry you're right I'd misunderstood. What you've said makes sense now.