-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gracefully handle missing SRV records
This code did not communicate its intentions well. ConsistentHashingMode has a CacheHosts member which corresponds to the SRV records for the consistent hash pods, in the correct order. This slice can contain gaps of empty string where there are gaps in the corresponding SRV records. For example, if a statefulset `foo` has 4 pods but foo-2 is not currently ready, CacheHosts will contain this slice: - 0: "foo-0" - 1: "foo-1" - 2: "" - 3: "foo-3" The code had a guard to ensure that it only overrides the request Host and Scheme if the CacheHost exists. This meant that if a cache host was not ready, the request would be made directly against upstream. This interacted poorly with CacheUsePathProxy, which also munged the HTTP path. This commit changes the `cacheHost[i] == ""` case to treat it as a regular failure, and to perform fallbacks as necessary. This is more correct in a few ways: - if a single cache pod is not ready, we should retry against another cache pod before going upstream, but the current code goes straight to upstream - it handles CacheUsePathProxy better, by ensuring we only ever munge the path if we're also sending the request to a real cache host I've written a test for this case. It's not ideal in that in the failure case it makes a request upstream to https://weights.replicate.delivery/hello.txt. Ideally we'd spin up an origin server in the test, but all the hashes depend on the origin URL and the current way we spin up test servers chooses a new port each time. I'd welcome improvements but it's good enough for now.
- Loading branch information
1 parent
4517037
commit 7593122
Showing
2 changed files
with
81 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters