Hello Yichun Zhang,
Can you please provide a way to duplicate every requests to two different upstreams - production and staging environment. Clients requests goes to openresty and mirroring to two different upstreams(prod and stg). I would like to ignore staging responses and forward to the client response from production upstream only. Also it should be coscocket solution since it would be nice to avoid any delay for production environment if staging environment is unavailable.
As for know i have tried the following ways:
- lua cosocket based library lua-resty-http-simple - probably best way to go but need help to set it up
- lua ngx.location.capture
This kind of solution does work:
ngx.req.read_body()
local arguments = ngx.var.args
r1 = ngx.location.capture('/prod/', { args = arguments, share_all_vars = true })
ngx.print(r1.body)
ngx.eof()
r2 = ngx.location.capture('/dev/', { args = arguments, share_all_vars = true })
but i am not happy with this because of ngx.eof() and possible delay to production environment in case of staging is unavailable.
It also does work for some time in production environment but i have copied about half of the production trafic(i monitor incoming/outgoing network interface activity to figure this out)
Regards Vladimir