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.
So what i wrote is pretty common task about trafic duplication. You allready discussed similiar issue here: https://www.ruby-forum.com/topic/6179585 but i am unable to write lua script which will use coscoket library https://github.com/bakins/lua-resty-http-simple for this purporse.
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.
Another option is go with tcpcopy project: https://github.com/session-replay-tools/tcpcopy 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)
- openresty + zeroMQ http://glipho.com/albert/http-traffic-duplication-with-nginx Looking promising, but i did not find any use case in production systems
- gor https://github.com/buger/gor/ looking like tcpcopy project but i did not test it yet.
It would be nice if you can make some example of lua script for this kind of task here : http://openresty.org/download/agentzh-nginx-tutorials-en.html. Sure i will be not the only person who benefit from it. From my site i can provide extra details or perform troubleshooting steps.
Regards Vladimir