Hi community. I’ve searched for information on how to do this and come up empty.
Goal: We are evaluating a new origin server and we’d like to load test it before deployment.
Request: Ideally, we’d like to use Cloudflare to duplicate 100% of traffic requests to server A and route them to server B. But all server B responses would be ignored; only server A responses are returned by Cloudflare to the end user. Server B takes all the load and makes responses, but those responses are not sent to the user.
I see many ways to use Cloudflare as a load balancer between A and B, but I don’t see a way to duplicate requests to B and ignore the response.
addEventListener('fetch', event => {
console.log("****** START ******")
event.respondWith(getFinalResponse(event.request))
})
async function getFinalResponse(request) {
console.log("Fetching the server B's response...")
var newURL = new URL(request.url)
newURL.host = 'myserver.mydomain.com'
let responseB = fetch(newURL, request)
console.log("Done.")
console.log("Fetching the server A's response...")
let responseA = await fetch(request.url, request)
console.log("Done.")
return responseA
}
I’m not sure about how concurrency works in this case. The first call does not use await, so supposedly it will send a request to both of your servers simultaneously and not wait for the Server B’s response.
If you’re testing a new origin, then more likely you’re concerned about CF CDN cache miss requests that hit the origin? If so on your live origin if it’s nginx server based, you can use nginx mirror module to replicate requests to another server Module ngx_http_mirror_module