本文主要是介绍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 repeaterDEFAULT CHARSET utf8COLLATE utf8_general_ci;
DROP TABLE IF EXISTS record;
CREATE TABLE record
(id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEYCOMMENT '主键',gmt_create DATETIME NOT NULLCOMMENT '创建时间',gmt_record DATETIME NOT NULLcomment '录制时间',app_name VARCHAR(255) NOT NULLCOMMENT '应用名',environment VARCHAR(255) NOT NULLCOMMENT '环境信息',host VARCHAR(36) NOT NULLCOMMENT '机器IP',trace_id VARCHAR(32) NOT NULLCOMMENT '链路追踪ID',entrance_desc VARCHAR(2000) NOT NULLCOMMENT '链路追踪ID',wrapper_record LONGTEXT NOT NULLCOMMENT '记录序列化信息',request LONGTEXT NOT NULLCOMMENT '请求参数JSON',response LONGTEXT NOT NULLCOMMENT '返回值JSON'
)ENGINE = InnoDBCOMMENT = '录制信息'DEFAULT CHARSET = utf8AUTO_INCREMENT = 1;DROP TABLE IF EXISTS replay;
CREATE TABLE replay
(id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEYCOMMENT '主键',gmt_create DATETIME NOT NULLCOMMENT '创建时间',gmt_modified DATETIME NOT NULLcomment '修改时间',app_name VARCHAR(255) NOT NULLCOMMENT '应用名',environment VARCHAR(255) NOT NULLCOMMENT '环境信息',ip VARCHAR(36) NOT NULLCOMMENT '机器IP',repeat_id VARCHAR(32) NOT NULLCOMMENT '回放ID',status TINYINT NOT NULLCOMMENT '回放状态',trace_id VARCHAR(32)COMMENT '链路追踪ID',cost BIGINT(20)COMMENT '回放耗时',diff_result LONGTEXTCOMMENT 'diff结果',response LONGTEXTCOMMENT '回放结果',mock_invocation LONGTEXTCOMMENT 'mock过程',success BITCOMMENT '是否回放成功',record_id BIGINT(20)COMMENT '外键')ENGINE = InnoDBCOMMENT = '回放信息'DEFAULT CHARSET = utf8AUTO_INCREMENT = 1;DROP TABLE IF EXISTS module_info;
CREATE TABLE module_info
(id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEYCOMMENT '主键',gmt_create DATETIME NOT NULLCOMMENT '创建时间',gmt_modified DATETIME NOT NULLcomment '修改时间',app_name VARCHAR(255) NOT NULLCOMMENT '应用名',environment VARCHAR(255) NOT NULLCOMMENT '环境信息',ip VARCHAR(36) NOT NULLCOMMENT '机器IP',port VARCHAR(12) NOT NULLCOMMENT '链路追踪ID',version VARCHAR(128) NOT NULLCOMMENT '模块版本号',status VARCHAR(36) NOT NULLCOMMENT '模块状态'
)ENGINE = InnoDBCOMMENT = '在线模块信息'DEFAULT CHARSET = utf8AUTO_INCREMENT = 1;DROP TABLE IF EXISTS module_config;
CREATE TABLE module_config
(id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEYCOMMENT '主键',gmt_create DATETIME NOT NULLCOMMENT '创建时间',gmt_modified DATETIME NOT NULLcomment '录制时间',app_name VARCHAR(255) NOT NULLCOMMENT '应用名',environment VARCHAR(255) NOT NULLCOMMENT '环境信息',config LONGTEXT NOT NULLCOMMENT '配置信息'
)ENGINE = InnoDBCOMMENT = '模块配置信息'DEFAULT CHARSET = utf8AUTO_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_msgtypeset HOME=/opt/data/fllexit_on_err()
{[[ ! -z "${2}" ]] && echo "${2}" 1>&2exit ${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}" ] ;thenecho ""
elseecho "found target pid exist, pid is ${PID}, kill it..."kill -9 ${PID}
fiif [ ! -f "${HOME}/sandbox-module/repeater-bootstrap.jar" ]; thenecho "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_msgtypeset HOME=/opt/data/fll
typeset SANDBOX_HOME=/opt/data/fll/sandboxexit_on_err()
{[[ ! -z "${2}" ]] && echo "${2}" 1>&2exit ${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 &
这篇关于jvm-sandbox-repeater 精简版部署之非standalone模式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!