GoReplay 介绍
- GoReplay是一个开源工具,用于捕获实时HTTP流量并将其重播到测试环境中,以便使用真实数据持续测试您的系统。它可用于增加对代码部署、配置更改和基础架构更改的信心。
- GoRepaly是一个开源网络监控工具,可以记录您的实时流量,并将用于跟踪、负载测试、监控和详细分析。
GoReplay价值
- 使用GoReplay准确模拟生产环境,使您的部署和基础架构更改可预测
- GoReplay是一种创新的开源解决方案,它允许您捕获现有用户的活动并将其重新用于测试您的应用程序。
- 使用GoReplay,您可以执行跟踪、负载测试或详细分析和监控
技术架构
下载
预编译版本 https://github.com/buger/goreplay/releases
编译代码 https://github.com/buger/goreplay
容器版本比较老旧 https://hub.docker.com/search?q=goreplay&type=image
演练环境
可以利用 gor python nginx 等各种工具搭建多套环境
python3 -m http.server 8001
./gor file-server :8000
dev 环境 http://127.0.0.1:8001
stage 环境 http://127.0.0.1:8002
prod 环境 http://127.0.0.1:8000
快速开始 Quick Start
- 监听模式
sudo ./gor --input-raw :8000 --output-stdout - 转发模式
sudo ./gor --input-raw :8000 --output-http=“http://localhost:8001” - 重放模式
gor --input-file requests.gor --output-http=“http://localhost:8001” - 性能模式
gor --input-file “requests.gor|200%” --output-http “staging.com”
使用流程
核心参数
input 参数 | output 参数 |
---|---|
–input-raw | –output-http |
–input-file | –output-file |
–input-http | –output-tcp |
–input-tcp | –output-stdout |
–input-raw-track-response |
请求过滤
gor --input-raw :8080 --output-http staging.com \
--http-allow-url /api
gor --input-raw :8080 --output-http staging.com \
--http-disallow-url /api
gor --input-raw :8080 --output-http staging.com \
--http-allow-header api-version:^1\.0\d
gor --input-raw :80 --output-http "http://staging.server" \
--http-allow-method GET \
--http-allow-method OPTIONS
请求重写
gor --input-raw :8080 --output-http staging.com \
--http-rewrite-url /v1/user/([^\\/]+)/ping:/v2/user/$1/ping
gor --input-raw :8080 --output-http staging.com \
--http-set-param api_key=1
gor --input-raw :80 --output-http "http://staging.server" \
--http-header "User-Agent: Replayed by Gor" \
--http-header "Enable-Feature-X: true"
经典案例
tcpdump(监听)模式
sudo ./gor --input-raw :8000 --output-stdout --input-raw-track-response
sudo ./gor --input-raw :8000 --output-file=requests.gor
线上流量同步
sudo ./gor --input-raw :8000 --output-http="http://127.0.0.1:8002"
压测
#录制并保存
sudo ./gor --input-raw :8000 --output-file=requests.gor
#加速回放
./gor --input-file "requests_0.gor|1000%" --http-allow-url json --output-http "http://127.0.0.1:8003"
#持续加压
./gor --input-file "requests_0.gor|1000%" --http-allow-url json --output-http "http://127.0.0.1:8003" -input-file-loop
总结
- 利用流量同步实现预发布测试
- 利用流量回放进行回归测试
- 利用流量放大进行压力测试