Skip to content

Commit 0638324

Browse files
committed
Add the integration testing with hot plugging functionality
Signed-off-by: hanbingleixue <hanbingleixue@hotmail.com>
1 parent 6fe851e commit 0638324

File tree

16 files changed

+274
-13
lines changed

16 files changed

+274
-13
lines changed

.github/actions/common/plugin-change-check/action.yml

+2
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ runs:
829829
830830
# ==========grpc Tag Transmission is needed to test?==========
831831
if [ ${{ env.grpcTagTransmissionChanged }} == 'true' -o \
832+
${{ env.sermantAgentCoreChanged }} == 'true' -o \
832833
${{ steps.changed-common-action.outputs.changed }} == 'true' -o ${{ env.triggerPushEvent }} == 'true' ];then
833834
echo "enableGrpcTagTransmissionAction=true" >> $GITHUB_ENV
834835
fi
@@ -842,6 +843,7 @@ runs:
842843
843844
# ==========httpclientV4 Tag Transmission is needed to test?==========
844845
if [ ${{ env.httpclientV4TagTransmissionChanged }} == 'true' -o \
846+
${{ env.sermantAgentCoreChanged }} == 'true' -o \
845847
${{ steps.changed-common-action.outputs.changed }} == 'true' -o ${{ env.triggerPushEvent }} == 'true' ];then
846848
echo "enableHttpclientV4TagTransmissionAction=true" >> $GITHUB_ENV
847849
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: "Test the configuration management of Backend"
2+
description: "Auto test for Backend"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: compile AgentLoader
7+
shell: bash
8+
run: |
9+
cp sermant-integration-tests/scripts/AgentLoader.java ./
10+
javac -classpath ./:${{ env.JAVA_HOME}}/lib/tools.jar AgentLoader.java
11+
- name: start backend with zookeeper
12+
shell: bash
13+
env:
14+
DYNAMIC_CONFIG_SERVERADDRESS: 127.0.0.1:2181
15+
DYNAMIC_CONFIG_DYNAMICCONFIGTYPE: ZOOKEEPER
16+
DYNAMIC_CONFIG_ENABLE: true
17+
NETTY_PORT: 6893
18+
SERVER_PORT: 8910
19+
run: |
20+
nohup java -jar sermant-agent-${{ env.sermantVersion }}/server/sermant/sermant-backend-${{ env.sermantVersion }}.jar &
21+
sleep 20
22+
- name: start applications
23+
shell: bash
24+
env:
25+
dynamic.config.serverAddress: 127.0.0.1:2181
26+
dynamic.config.dynamicConfigType: ZOOKEEPER
27+
service.meta.project: TestAgentCore
28+
run: |
29+
nohup java -jar \
30+
sermant-agent-${{ env.sermantVersion }}/agent/agentcore-test-application-1.0.0-jar-with-dependencies.jar > ${{ env.logDir
31+
}}/agentcore-test.log 2>&1 &
32+
- name: waiting for agentcore services start
33+
shell: bash
34+
run: |
35+
bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8915/ping 120
36+
- name: (install agent) modify plugins file
37+
shell: bash
38+
run: |
39+
sed -i '/dynamic-test-first-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
40+
sed -i '/dynamic-test-second-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
41+
sed -i '/ passive:/a \ - dynamic-test-first-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
42+
sed -i '/ passive:/a \ - dynamic-test-second-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml
43+
- name: dynamic install agent
44+
shell: bash
45+
run: java -classpath ./:${{ env.JAVA_HOME}}/lib/tools.jar AgentLoader sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar \
46+
agent.service.hot.plugging.service.enable=true,agent.service.heartbeat.enable=true,agent.service.gateway.enable=true,event.enable=true,gateway.nettyPort=6893
47+
- name: Sleep for 5 Seconds
48+
shell: bash
49+
run: sleep 20
50+
- name: test install plugin
51+
shell: bash
52+
run: |
53+
export TEST_MODE=install
54+
python -m unittest ./sermant-integration-tests/scripts/test_backend_hot_plugging.py
55+
- name: test update plugin
56+
shell: bash
57+
run: |
58+
export TEST_MODE=update
59+
rm -rf sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-first-plugin/plugin/dynamic-test-first-plugin-1.0.0.jar
60+
rm -rf sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-second-plugin/plugin/dynamic-test-second-plugin-1.0.0.jar
61+
mv sermant-agent-${{ env.sermantVersion }}/dynamic-test-first-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-first-plugin/plugin
62+
mv sermant-agent-${{ env.sermantVersion }}/dynamic-test-second-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-second-plugin/plugin
63+
python -m unittest ./sermant-integration-tests/scripts/test_backend_hot_plugging.py
64+
- name: test uninstall plugin
65+
shell: bash
66+
run: |
67+
export TEST_MODE=unInstall
68+
python -m unittest ./sermant-integration-tests/scripts/test_backend_hot_plugging.py
69+
- name: exit
70+
if: always()
71+
uses: ./.github/actions/common/exit
72+
with:
73+
processor-keyword: agentcore|backend
74+
- name: if failure then upload error log
75+
uses: actions/upload-artifact@v3
76+
if: ${{ failure() || cancelled() }}
77+
with:
78+
name: (${{ github.job }})-backend-logs
79+
path: |
80+
./*.log
81+
./logs/**
82+
if-no-files-found: warn
83+
retention-days: 2

.github/workflows/backend_integration_test.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,14 @@ jobs:
7575
key: ${{ runner.os }}-agent-${{ github.run_id }}
7676
- name: package agent
7777
run: |
78-
sed -i '/sermant-integration-tests/d' pom.xml
7978
sed -i '/sermant-injector/d' pom.xml
80-
mvn package -DskipTests -Ptest --file pom.xml
79+
mvn clean package -DskipTests -Ptest --file pom.xml -Dfirst.plugin.paramIndex=1 -Dsecond.plugin.paramIndex=2
80+
mv sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-first-plugin/plugin/dynamic-test-first-plugin-1.0.0.jar ./
81+
mv sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-second-plugin/plugin/dynamic-test-second-plugin-1.0.0.jar ./
82+
mvn clean package -DskipTests -Ptest --file pom.xml -Dfirst.plugin.paramIndex=0 -Dsecond.plugin.paramIndex=1
83+
mv ./dynamic-test-first-plugin-1.0.0.jar ./sermant-agent-${{ env.sermantVersion }}
84+
mv ./dynamic-test-second-plugin-1.0.0.jar ./sermant-agent-${{ env.sermantVersion }}
85+
cp ./sermant-integration-tests/agentcore-test/agentcore-test-application/target/agentcore-test-application-1.0.0-jar-with-dependencies.jar sermant-agent-${{ env.sermantVersion }}/agent/
8186
test-for-backend:
8287
name: Test for backend
8388
runs-on: ubuntu-latest
@@ -95,3 +100,7 @@ jobs:
95100
uses: ./.github/actions/scenarios/backend/event/redis
96101
- name: start config manager test
97102
uses: ./.github/actions/scenarios/backend/config
103+
- name: start hot plugging test
104+
uses: ./.github/actions/scenarios/backend/hot-plugging
105+
106+

sermant-agentcore/sermant-agentcore-config/config/test/config.properties

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ agent.service.dynamic.config.enable=true
3636
agent.service.httpserver.enable=false
3737
# xDS service switch
3838
agent.service.xds.service.enable=false
39+
# hot plugging service switch
40+
agent.service.hot.plugging.service.enable=false
3941
# Metric service switch
4042
agent.service.metric.enable=false
4143
#============================= Event configuration =============================#

sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/example/sermant/agentcore/test/application/controller/TestController.java

+13
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ public Map<String, Object> testInstallPlugin() {
8383
return resultMap;
8484
}
8585

86+
/**
87+
* Test dynamic installation plugins
88+
*
89+
* @return test result
90+
*/
91+
public Map<String, Object> testUpdatePlugin() {
92+
Map<String, Object> resultMap = new HashMap<>();
93+
DynamicTest dynamicTest = new DynamicTest();
94+
dynamicTest.testUpdatePlugin();
95+
resultMap.put(DynamicResults.DYNAMIC_UPDATE_PLUGIN.name(), DynamicResults.DYNAMIC_UPDATE_PLUGIN.getResult());
96+
return resultMap;
97+
}
98+
8699
/**
87100
* 测试动态卸载插件
88101
*

sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/example/sermant/agentcore/test/application/results/DynamicResults.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ public enum DynamicResults {
7676
/**
7777
* agentmain启动,passive插件失效
7878
*/
79-
AGENTMAIN_PASSIVE_PLUGIN_INTERCEPTOR_FAILURE("Test agentmain startup, passive plugin failure.");
79+
AGENTMAIN_PASSIVE_PLUGIN_INTERCEPTOR_FAILURE("Test agentmain startup, passive plugin failure."),
80+
81+
/**
82+
* Dynamically update plugins
83+
*/
84+
DYNAMIC_UPDATE_PLUGIN("Test dynamic update plugin.");
8085

8186
/**
8287
* 用例描述

sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/example/sermant/agentcore/test/application/router/ControllerHandler.java

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ private Object setResponse(HttpExchange exchange) {
111111
return testController.testEnhancement();
112112
case RouterPath.REQUEST_PATH_RE_TRANSFORM:
113113
return testController.testReTransform();
114+
case RouterPath.UPDATE_PLUGIN:
115+
return testController.testUpdatePlugin();
114116
default:
115117
return REQUEST_URL_NOT_FOUND;
116118
}

sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/example/sermant/agentcore/test/application/router/RouterPath.java

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public class RouterPath {
8888
*/
8989
public static final String REQUEST_PATH_RE_TRANSFORM = "/testReTransform";
9090

91+
/**
92+
* Test plugin upgrade
93+
*/
94+
public static final String UPDATE_PLUGIN = "/testUpdatePlugin";
95+
9196
private RouterPath() {
9297
}
9398
}

sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/example/sermant/agentcore/test/application/tests/dynamic/DynamicTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class DynamicTest {
3131
private static final int FIRST_PLUGIN_ENHANCE_INDEX = 0;
3232
private static final int SECOND_PLUGIN_ENHANCE_INDEX = 1;
3333
private static final int THIRD_PLUGIN_ENHANCE_INDEX = 2;
34+
private static final int FIRST_PLUGIN_V2_ENHANCE_INDEX = 3;
3435
/**
3536
* 用于测试插件反射修改的回执结果:监听成功
3637
*/
@@ -50,6 +51,16 @@ public void testInstallPlugin() {
5051
}
5152
}
5253

54+
/**
55+
* Test dynamic upgrade plugin
56+
*/
57+
public void testUpdatePlugin() {
58+
boolean[] result = repeatEnhance(false, false, false);
59+
if (result[SECOND_PLUGIN_ENHANCE_INDEX] && result[THIRD_PLUGIN_ENHANCE_INDEX]) {
60+
DynamicResults.DYNAMIC_UPDATE_PLUGIN.setResult(true);
61+
}
62+
}
63+
5364
/**
5465
* 测试动态卸载插件
5566
*/

sermant-integration-tests/agentcore-test/dynamic-test-first-plugin/pom.xml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<maven.compiler.source>8</maven.compiler.source>
1515
<maven.compiler.target>8</maven.compiler.target>
1616
<package.plugin.type>plugin</package.plugin.type>
17+
<first.plugin.paramIndex>0</first.plugin.paramIndex>
1718
</properties>
1819

1920
<dependencies>
@@ -38,6 +39,7 @@
3839
<manifestEntries>
3940
<Sermant-Plugin-Name>${package.plugin.name}</Sermant-Plugin-Name>
4041
<Sermant-Plugin-Version>${package.plugin.version}</Sermant-Plugin-Version>
42+
<paramIndex>${first.plugin.paramIndex}</paramIndex>
4143
</manifestEntries>
4244
</archive>
4345
</configuration>

sermant-integration-tests/agentcore-test/dynamic-test-first-plugin/src/main/java/io/sermant/dynamic/test/first/plugin/interceptor/RepeatEnhanceInterceptor.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
import io.sermant.core.plugin.agent.entity.ExecuteContext;
2121
import io.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
2222

23+
import java.io.IOException;
24+
import java.net.URISyntaxException;
25+
import java.util.jar.Attributes;
26+
import java.util.jar.JarFile;
27+
import java.util.jar.Manifest;
2328
import java.util.logging.Level;
2429
import java.util.logging.Logger;
2530

@@ -34,8 +39,19 @@ public class RepeatEnhanceInterceptor extends AbstractInterceptor {
3439

3540
@Override
3641
public ExecuteContext before(ExecuteContext context) {
37-
context.getArguments()[0] = true;
38-
LOGGER.log(Level.INFO, "Test repeat enhance, first plugin enhance success");
42+
try {
43+
String path = this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
44+
try (JarFile jarFile = new JarFile(path)) {
45+
Manifest manifest = jarFile.getManifest();
46+
Attributes attributes = manifest.getMainAttributes();
47+
context.getArguments()[Integer.parseInt(attributes.getValue("paramIndex"))] = true;
48+
LOGGER.log(Level.INFO, "Test repeat enhance, first plugin enhance success");
49+
} catch (IOException e) {
50+
LOGGER.log(Level.SEVERE, "Test repeat enhance, first plugin enhance failed", e);
51+
}
52+
} catch (URISyntaxException e) {
53+
LOGGER.log(Level.SEVERE, "Test repeat enhance, first plugin enhance failed", e);
54+
}
3955
return context;
4056
}
4157

sermant-integration-tests/agentcore-test/dynamic-test-second-plugin/pom.xml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<maven.compiler.source>8</maven.compiler.source>
1515
<maven.compiler.target>8</maven.compiler.target>
1616
<package.plugin.type>plugin</package.plugin.type>
17+
<second.plugin.paramIndex>1</second.plugin.paramIndex>
1718
</properties>
1819

1920
<dependencies>
@@ -38,6 +39,7 @@
3839
<manifestEntries>
3940
<Sermant-Plugin-Name>${package.plugin.name}</Sermant-Plugin-Name>
4041
<Sermant-Plugin-Version>${package.plugin.version}</Sermant-Plugin-Version>
42+
<paramIndex>${second.plugin.paramIndex}</paramIndex>
4143
</manifestEntries>
4244
</archive>
4345
</configuration>

sermant-integration-tests/agentcore-test/dynamic-test-second-plugin/src/main/java/io/sermant/dynamic/test/second/plugin/interceptor/RepeatEnhanceInterceptor.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
import io.sermant.core.plugin.agent.entity.ExecuteContext;
2121
import io.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
2222

23+
import java.io.IOException;
24+
import java.net.URISyntaxException;
25+
import java.util.jar.Attributes;
26+
import java.util.jar.JarFile;
27+
import java.util.jar.Manifest;
2328
import java.util.logging.Level;
2429
import java.util.logging.Logger;
2530

@@ -34,8 +39,19 @@ public class RepeatEnhanceInterceptor extends AbstractInterceptor {
3439

3540
@Override
3641
public ExecuteContext before(ExecuteContext context) {
37-
context.getArguments()[1] = true;
38-
LOGGER.log(Level.INFO, "Test repeat enhance, second plugin enhance success");
42+
try {
43+
String path = this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
44+
try (JarFile jarFile = new JarFile(path)) {
45+
Manifest manifest = jarFile.getManifest();
46+
Attributes attributes = manifest.getMainAttributes();
47+
context.getArguments()[Integer.parseInt(attributes.getValue("paramIndex"))] = true;
48+
LOGGER.log(Level.INFO, "Test repeat enhance, second plugin enhance success");
49+
} catch (IOException e) {
50+
LOGGER.log(Level.SEVERE, "Test repeat enhance, second plugin enhance failed", e);
51+
}
52+
} catch (URISyntaxException e) {
53+
LOGGER.log(Level.SEVERE, "Test repeat enhance, second plugin enhance failed", e);
54+
}
3955
return context;
4056
}
4157

sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/pom.xml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<maven.compiler.source>8</maven.compiler.source>
1515
<maven.compiler.target>8</maven.compiler.target>
1616
<package.plugin.type>plugin</package.plugin.type>
17+
<third.plugin.paramIndex>2</third.plugin.paramIndex>
1718
</properties>
1819

1920
<dependencies>
@@ -38,6 +39,7 @@
3839
<manifestEntries>
3940
<Sermant-Plugin-Name>${package.plugin.name}</Sermant-Plugin-Name>
4041
<Sermant-Plugin-Version>${package.plugin.version}</Sermant-Plugin-Version>
42+
<paramIndex>${third.plugin.paramIndex}</paramIndex>
4143
</manifestEntries>
4244
</archive>
4345
</configuration>

sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/src/main/java/io/sermant/dynamic/test/third/plugin/interceptor/RepeatEnhanceInterceptor.java

+18-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
import io.sermant.core.plugin.agent.entity.ExecuteContext;
2121
import io.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
2222

23+
import java.io.IOException;
24+
import java.net.URISyntaxException;
25+
import java.util.jar.Attributes;
26+
import java.util.jar.JarFile;
27+
import java.util.jar.Manifest;
2328
import java.util.logging.Level;
2429
import java.util.logging.Logger;
2530

@@ -30,17 +35,24 @@
3035
* @since 2023-09-27
3136
*/
3237
public class RepeatEnhanceInterceptor extends AbstractInterceptor {
33-
/**
34-
* third测试插件增强参数下标
35-
*/
36-
private static final int ARGS_INDEX = 2;
3738

3839
private static final Logger LOGGER = LoggerFactory.getLogger();
3940

4041
@Override
4142
public ExecuteContext before(ExecuteContext context) {
42-
context.getArguments()[ARGS_INDEX] = true;
43-
LOGGER.log(Level.INFO, "Test repeat enhance, third plugin enhance success");
43+
try {
44+
String path = this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
45+
try (JarFile jarFile = new JarFile(path)) {
46+
Manifest manifest = jarFile.getManifest();
47+
Attributes attributes = manifest.getMainAttributes();
48+
context.getArguments()[Integer.parseInt(attributes.getValue("paramIndex"))] = true;
49+
LOGGER.log(Level.INFO, "Test repeat enhance, third plugin enhance success");
50+
} catch (IOException e) {
51+
LOGGER.log(Level.SEVERE, "Test repeat enhance, third plugin enhance failed", e);
52+
}
53+
} catch (URISyntaxException e) {
54+
LOGGER.log(Level.SEVERE, "Test repeat enhance, third plugin enhance failed", e);
55+
}
4456
return context;
4557
}
4658

0 commit comments

Comments
 (0)