coderedcorp/wagtail-cache

Add option to raise Redis errors

aweakley opened this issue · 4 comments

Since 583f16d 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.

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.

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

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.