Skip to content

Move Google IP fetch into background job with rate limiting

What does this MR do and why?

Previously the initial merge request in the Google CDN code !96336 (merged) would fetch the list of Google IPs within the same thread as the process that attempts to serve out a Google CDN-frontend URL. However, there are several issues with this:

  1. If the HTTP endpoint is slow or down for some reason, this will delay the response handling.

  2. There is no throttling to prevent excessive requests to this endpoint.

To improve the reliability, we move the fetching of this URL to a background Sidekiq job that has an application rate limit to prevent too many requests. The initial limit is 10 requests in a minute, which should should be adequate since we only need one worker to populate the cache for a whole day.

Relates to #373115 (closed)

How to set up and validate locally

The configuration for using Google CDN isn't fully enabled yet, so this change shouldn't affect production at the moment. To verify locally, checkout this branch and run:

ObjectStorage::CDN::GoogleIpCache.async_refresh

Then check that the cache is populated:

[3] pry(main)> ObjectStorage::CDN::GoogleIpCache.ready?
=> true
[4] pry(main)> Rails.cache.fetch('google_cdn_ip_list')
=> [#<IPAddr: IPv4:34.80.0.0/255.254.0.0>,
 #<IPAddr: IPv4:34.137.0.0/255.255.0.0>,
 #<IPAddr: IPv4:35.185.128.0/255.255.224.0>,
 #<IPAddr: IPv4:35.185.160.0/255.255.240.0>,
<snip>

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Stan Hu

Merge request reports

Loading