jvm-sandbox-repeater 精简版部署之非standalone模式
[root@k8s-worker27-65 jvm-sandbox-repeater]# pwd
/root/work/traffic/jvm-sandbox-repeater
[root@k8s-worker27-65 jvm-sandbox-repeater]# ls
bin hessian-lite pom.xml repeater-aide repeater-console repeater-plugin-api repeater-plugins travis.sh
docs LICENSE Readme.md repeater-client repeater-module repeater-plugin-core target
1. 调整 repeater 模式配置,改为用 console
[root@k8s-worker27-65 jvm-sandbox-repeater]# cat bin/repeater.properties |grep -v '#' |grep -v '^$'
broadcaster.record.url=http://192.168.1.65:8001/facade/api/record/save
broadcaster.repeat.url=http://192.168.1.65:8001/facade/api/repeat/save
repeat.record.url=http://192.168.1.65:8001/facade/api/record/%s/%s
repeat.config.url=http://192.168.1.65:8001/facade/api/config/%s/%s
repeat.heartbeat.url=http://192.168.1.65:8001/module/report.json
repeat.standalone.mode=false
repeat.spring.advice.switch=false;
?2.?调整 console 工程中对应配置
[root@k8s-worker27-65 jvm-sandbox-repeater]# cat repeater-console/repeater-console-start/src/main/resources/application.properties |grep data
spring.datasource.url=jdbc:mysql://192.168.1.65:3306/repeater?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456aA
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
3.初始化数据:
[root@k8s-worker27-65 jvm-sandbox-repeater]# cat repeater-console/repeater-console-dal/src/main/resources/database.sql
CREATE DATABASE IF NOT EXISTS repeater
DEFAULT CHARSET utf8
COLLATE utf8_general_ci;
DROP TABLE IF EXISTS record;
CREATE TABLE record
(
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY
COMMENT '主键',
gmt_create DATETIME NOT NULL
COMMENT '创建时间',
gmt_record DATETIME NOT NULL
comment '录制时间',
app_name VARCHAR(255) NOT NULL
COMMENT '应用名',
environment VARCHAR(255) NOT NULL
COMMENT '环境信息',
host VARCHAR(36) NOT NULL
COMMENT '机器IP',
trace_id VARCHAR(32) NOT NULL
COMMENT '链路追踪ID',
entrance_desc VARCHAR(2000) NOT NULL
COMMENT '链路追踪ID',
wrapper_record LONGTEXT NOT NULL
COMMENT '记录序列化信息',
request LONGTEXT NOT NULL
COMMENT '请求参数JSON',
response LONGTEXT NOT NULL
COMMENT '返回值JSON'
)
ENGINE = InnoDB
COMMENT = '录制信息'
DEFAULT CHARSET = utf8
AUTO_INCREMENT = 1;
DROP TABLE IF EXISTS replay;
CREATE TABLE replay
(
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY
COMMENT '主键',
gmt_create DATETIME NOT NULL
COMMENT '创建时间',
gmt_modified DATETIME NOT NULL
comment '修改时间',
app_name VARCHAR(255) NOT NULL
COMMENT '应用名',
environment VARCHAR(255) NOT NULL
COMMENT '环境信息',
ip VARCHAR(36) NOT NULL
COMMENT '机器IP',
repeat_id VARCHAR(32) NOT NULL
COMMENT '回放ID',
status TINYINT NOT NULL
COMMENT '回放状态',
trace_id VARCHAR(32)
COMMENT '链路追踪ID',
cost BIGINT(20)
COMMENT '回放耗时',
diff_result LONGTEXT
COMMENT 'diff结果',
response LONGTEXT
COMMENT '回放结果',
mock_invocation LONGTEXT
COMMENT 'mock过程',
success BIT
COMMENT '是否回放成功',
record_id BIGINT(20)
COMMENT '外键'
)
ENGINE = InnoDB
COMMENT = '回放信息'
DEFAULT CHARSET = utf8
AUTO_INCREMENT = 1;
DROP TABLE IF EXISTS module_info;
CREATE TABLE module_info
(
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY
COMMENT '主键',
gmt_create DATETIME NOT NULL
COMMENT '创建时间',
gmt_modified DATETIME NOT NULL
comment '修改时间',
app_name VARCHAR(255) NOT NULL
COMMENT '应用名',
environment VARCHAR(255) NOT NULL
COMMENT '环境信息',
ip VARCHAR(36) NOT NULL
COMMENT '机器IP',
port VARCHAR(12) NOT NULL
COMMENT '链路追踪ID',
version VARCHAR(128) NOT NULL
COMMENT '模块版本号',
status VARCHAR(36) NOT NULL
COMMENT '模块状态'
)
ENGINE = InnoDB
COMMENT = '在线模块信息'
DEFAULT CHARSET = utf8
AUTO_INCREMENT = 1;
DROP TABLE IF EXISTS module_config;
CREATE TABLE module_config
(
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY
COMMENT '主键',
gmt_create DATETIME NOT NULL
COMMENT '创建时间',
gmt_modified DATETIME NOT NULL
comment '录制时间',
app_name VARCHAR(255) NOT NULL
COMMENT '应用名',
environment VARCHAR(255) NOT NULL
COMMENT '环境信息',
config LONGTEXT NOT NULL
COMMENT '配置信息'
)
ENGINE = InnoDB
COMMENT = '模块配置信息'
DEFAULT CHARSET = utf8
AUTO_INCREMENT = 1;
4.启动 console 和被测服务
启动被测服务:
4.1、下载示例项目:https://github.com/chenhengjie123/gs-rest-service
4.2、启动示例项目:
# 在示例项目 clone 后的根目录中运行
cd complete
mvn install && java -jar target/*.jar
4.3、修复官方仓库里 console 一些代码问题。
4.3.1)把?
repeater-console/repeater-console-start/src/main/resources/velocity
?下面的所有文件,查找?#parse("/blocks
?,统一改替换为?#parse("blocks
?。原有代码最前面带上?/
?会导致引用找不到报错
4.3.2)修改?
repeater-console/repeater-console-start/src/main/java/com/alibaba/repeater/console/start/controller/page/ReplayController.java
?中的?return "/replay/detail";
?,改为?return "replay/detail";
?,去掉双引号里面第一个?/
?
4.3.3)修改?
repeater-console/repeater-console-start/src/main/java/com/alibaba/repeater/console/start/controller/test/RegressPageController.java
?中的?return "/regress/index";
?,改为?return "regress/index";
,去掉双引号里面第一个?/
4.4修改配置
配置:bin/bootstrap.sh
[root@k8s-worker27-65 jvm-sandbox-repeater]# cat bin/bootstrap.sh
#!/usr/bin/env bash
# exit shell with err_code
# $1 : err_code
# $2 : err_msg
typeset HOME=/opt/data/fll
exit_on_err()
{
[[ ! -z "${2}" ]] && echo "${2}" 1>&2
exit ${1}
}
PID=$(ps -ef | grep "repeater-bootstrap.jar" | grep "java" | grep -v grep | awk '{print $2}')
expr ${PID} "+" 10 &> /dev/null
# if occurred error,exit
if [ ! $? -eq 0 ] || [ "" = "${PID}" ] ;then
echo ""
else
echo "found target pid exist, pid is ${PID}, kill it..."
kill -9 ${PID}
fi
if [ ! -f "${HOME}/sandbox-module/repeater-bootstrap.jar" ]; then
echo "repeater-bootstrap.jar not found, try to install";
sh ./install-local.sh || exit_on_err 1 "install repeater failed"
fi
${JAVA_HOME}/bin/java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 \
-javaagent:${HOME}/sandbox/lib/sandbox-agent.jar=server.port=8820\;server.ip=0.0.0.0 \
-Dapp.name=gs \
-Dapp.env=sit \
-jar ${HOME}/sandbox/sandbox-module/repeater-bootstrap.jar
配置:bin/install-local.sh
[root@k8s-worker27-65 jvm-sandbox-repeater]# cat bin/install-local.sh
#!/usr/bin/env bash
# repeater's target dir
REPEATER_TARGET_DIR=../target/repeater
# exit shell with err_code
# $1 : err_code
# $2 : err_msg
typeset HOME=/opt/data/fll
typeset SANDBOX_HOME=/opt/data/fll/sandbox
exit_on_err()
{
[[ ! -z "${2}" ]] && echo "${2}" 1>&2
exit ${1}
}
# package
sh ./package.sh || exit_on_err 1 "install failed cause package failed"
# extract sandbox to ${HOME}
#curl -s https://github.com/alibaba/jvm-sandbox-repeater/releases/download/v1.0.0/sandbox-1.3.3-bin.tar | tar xz -C ${HOME} || exit_on_err 1 "extract sandbox failed"
cat sandbox-1.3.3-bin.tar | tar xz -C ${HOME} || exit_on_err 1 "extract sandbox failed"
# copy module to ~/.sandbox-module
#mkdir -p ${HOME}/.sandbox-module || exit_on_err 1 "permission denied, can not mkdir ~/.sandbox-module"
cp -r ${REPEATER_TARGET_DIR}/* ${SANDBOX_HOME}/sandbox-module || exit_on_err 1 "permission denied, can not copy module to ${SANDBOX_HOME}/sandbox-module"
?配置:bin/repeater.properties
[root@k8s-worker27-65 jvm-sandbox-repeater]# cat bin/repeater.properties
# 录制消息投递地址
broadcaster.record.url=http://192.168.1.65:8001/facade/api/record/save
# 回放结果投递地址
broadcaster.repeat.url=http://192.168.1.65:8001/facade/api/repeat/save
# 回放消息取数据地址
repeat.record.url=http://192.168.1.65:8001/facade/api/record/%s/%s
# 配置文件拉取地址
repeat.config.url=http://192.168.1.65:8001/facade/api/config/%s/%s
# 心跳上报配置
repeat.heartbeat.url=http://192.168.1.65:8001/module/report.json
# 是否开启脱机工作模式
repeat.standalone.mode=false
# 是否开启spring advice拦截
repeat.spring.advice.switch=false;
?编译且直接启动
[root@k8s-worker27-65 bin]# ./bootstrap.sh
?也可以编译不启动
4.5 启动 console:
编译
[root@k8s-worker27-65 bin]# ./install-local.sh
启动
[root@k8s-worker27-65 sandbox-module]# pwd
/opt/data/fll/sandbox/sandbox-module
[root@k8s-worker27-65 sandbox-module]# ls
cfg plugins repeater-bootstrap.jar repeater-module.jar
[root@k8s-worker27-65 sandbox-module]# nohup java -jar repeater-bootstrap.jar &
我自己的在:
[root@k8s-worker27-65 .sandbox-module]# pwd
/root/.sandbox-module
[root@k8s-worker27-65 .sandbox-module]# ls
cfg plugins repeater-bootstrap.jar repeater-module.jar
[root@k8s-worker27-65 .sandbox-module]# nohup java -jar repeater-bootstrap.jar &
[1] 30357
5.?使用界面化的 console 进行录制回放
现在,借助界面来做一次录制回放吧。基本套路还是一样的:
5.1、在 console 增加配置,用于对接应用(注意这个和之前纯命令行有点不同,命令行是先完成第二步)
5.2、让 repeater 注入到被测应用,上报数据到 console
5.3、在 console 中操作,进行录制和回放
接下来,一步一步操作。
5.1、在 console 增加配置,用于对接应用
点击左侧的【配置管理】,添加如下配置:
应用名:gs
环境:sit
配置信息
{
"useTtl" : true,
"degrade" : false,
"exceptionThreshold" : 1000,
"sampleRate" : 10000,
"pluginsPath" : null,
"httpEntrancePatterns" : [ "^/greeting.*$" ],
"javaEntranceBehaviors" : [],
"javaSubInvokeBehaviors" : [ {
"classPattern" : "hello.GreetingController",
"methodPatterns" : [ "greeting" ],
"includeSubClasses" : false
} ],
"pluginIdentities" : [ "http", "java-entrance", "java-subInvoke", "mybatis", "ibatis" ],
"repeatIdentities" : [ "java", "http" ]
}
应用名:jettopro
环境:dev
{
"useTtl" : true,
"degrade" : false,
"exceptionThreshold" : 1000,
"sampleRate" : 10000,
"pluginsPath" : null,
"httpEntrancePatterns" : [ "^/jettopro-basic/.*$" ],
"javaEntranceBehaviors" : [],
"javaSubInvokeBehaviors" : [ {
"classPattern" : "com.cn.jettech.jettoprobasic.controller.basiccontroller02.BasicController201",
"methodPatterns" : [ "basichello20101" ],
"includeSubClasses" : false
} ],
"pluginIdentities" : [ "http", "java-entrance", "java-subInvoke", "mybatis", "ibatis" ],
"repeatIdentities" : [ "java", "http" ]
}
5.2、让 repeater 注入到被测应用 attach方式默认就是uknow
[root@k8s-worker27-65 bin]# ./sandbox.sh -p (ps -ef | grep "target/gs-rest-service-0.1.0.jar" | grep -v grep | awk '{print $2}') -P 12580
还可以agent方式:这种方式是指可以指定名字的
nohup java -javaagent:/opt/data/fll/sandbox/lib/sandbox-agent.jar=server.port=12580\;server.ip=192.168.1.65 -Dapp.name=gs -Dapp.env=sit -jar gs-rest-service-0.1.0.jar &
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!