From 69c3b77c1ce97816e305fd4492fb166be746213f Mon Sep 17 00:00:00 2001 From: daizhenyu <1449308021@qq.com> Date: Mon, 6 Nov 2023 21:21:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E9=87=8F=E6=A0=87=E7=AD=BE=E9=80=8F?= =?UTF-8?q?=E4=BC=A0=E6=8F=92=E4=BB=B6=E9=9B=86=E6=88=90=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=83=A8=E5=88=86demo=E5=92=8C=E9=9B=86=E6=88=90=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 流量标签透传插件集成测试部分demo和集成测试脚本-2 流量标签透传插件集成测试部分demo和集成测试脚本-2 流量标签透传插件集成测试部分demo和集成测试脚本-2 --- .../common/plugin-change-check/action.yml | 18 +- .../common/tag-transmission/action.yml | 45 ++ .../tag-transmission/alibaba-dubbo/action.yml | 61 +++ .../tag-transmission/apache-dubbo/action.yml | 53 +++ .../tag-transmission/config/action.yml | 46 ++ .../tag-transmission/crossthread/action.yml | 46 ++ .../tag-transmission/grpc/action.yml | 52 +++ .../tag-transmission/httpclientv3/action.yml | 46 ++ .../tag-transmission/httpclientv4/action.yml | 46 ++ .../tag-transmission/jdkhttp-jetty/action.yml | 53 +++ .../jdkhttp-tomcat/action.yml | 53 +++ .../tag-transmission/kafka/action.yml | 65 +++ .../tag-transmission/okhttp/action.yml | 46 ++ .../tag-transmission/rocketmq/action.yml | 72 +++ .../tag-transmission/servicecomb/action.yml | 76 +++ .../tag-transmission/sofarpc/action.yml | 52 +++ .../tagtransmission_integration_test.yml | 432 ++++++++++++++++++ .../scripts/tryDownloadMidware.sh | 6 +- .../kafka-consumer-demo/pom.xml | 49 ++ .../consumer/KafkaConsumerApplication.java | 38 ++ .../kafka/consumer/KafkaWithConsumer.java | 73 +++ .../controller/KafkaConsumerController.java | 48 ++ .../src/main/resources/application.properties | 3 + .../kafka-producer-demo/pom.xml | 48 ++ .../producer/KafkaProducerApplication.java | 38 ++ .../controller/KafkaProducerController.java | 93 ++++ .../src/main/resources/application.properties | 2 + .../midware/common/MessageConstant.java | 4 +- .../rocketmq/consumer/RocketMqConsumer.java | 2 +- .../rocketmq-producer-demo/pom.xml | 48 ++ .../producer/RocketMqProducerApplication.java | 38 ++ .../RocketMqProducerController.java | 94 ++++ .../src/main/resources/application.properties | 2 + .../tag-transmission-integration-test/pom.xml | 68 +++ .../integration/TagTransmissionTest.java | 277 +++++++++++ .../integration/utils/RequestUtils.java | 69 +++ 36 files changed, 2239 insertions(+), 23 deletions(-) create mode 100644 .github/actions/common/tag-transmission/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/alibaba-dubbo/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/apache-dubbo/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/config/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/crossthread/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/grpc/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/httpclientv3/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/httpclientv4/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/jdkhttp-jetty/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/jdkhttp-tomcat/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/kafka/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/okhttp/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/rocketmq/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/servicecomb/action.yml create mode 100644 .github/actions/scenarios/tag-transmission/sofarpc/action.yml create mode 100644 .github/workflows/tagtransmission_integration_test.yml create mode 100644 sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/consumer/KafkaConsumerApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/consumer/KafkaWithConsumer.java create mode 100644 sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/consumer/controller/KafkaConsumerController.java create mode 100644 sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/resources/application.properties create mode 100644 sermant-integration-tests/tag-transmission-test/kafka-producer-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/kafka-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/producer/KafkaProducerApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/kafka-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/producer/controller/KafkaProducerController.java create mode 100644 sermant-integration-tests/tag-transmission-test/kafka-producer-demo/src/main/resources/application.properties create mode 100644 sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/producer/RocketMqProducerApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/producer/controller/RocketMqProducerController.java create mode 100644 sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/src/main/resources/application.properties create mode 100644 sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/src/test/java/com/huaweicloud/demo/tagtransmission/integration/TagTransmissionTest.java create mode 100644 sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/src/test/java/com/huaweicloud/demo/tagtransmission/integration/utils/RequestUtils.java diff --git a/.github/actions/common/plugin-change-check/action.yml b/.github/actions/common/plugin-change-check/action.yml index 0e353f72eb..b5d17f700e 100644 --- a/.github/actions/common/plugin-change-check/action.yml +++ b/.github/actions/common/plugin-change-check/action.yml @@ -91,14 +91,6 @@ runs: shell: bash run: | echo "sermantServiceRemovalChanged=${{ steps.changed-sermant-removal.outputs.changed }}" >> $GITHUB_ENV - - uses: marceloprado/has-changed-path@v1.0.1 - id: changed-sermant-tag-transmission - with: - paths: sermant-plugins/sermant-tag-transmission - - name: env sermant-sermant-tag-transmission - shell: bash - run: | - echo "sermantTagTransmissionChanged=${{ steps.changed-sermant-tag-transmission.outputs.changed }}" >> $GITHUB_ENV - uses: marceloprado/has-changed-path@v1.0.1 id: changed-workflow-or-test with: @@ -187,12 +179,6 @@ runs: echo "enableRemoval=true" >> $GITHUB_ENV fi - # *****************tagtransmission.yml***************** - # ==========tag transmission is needed to test?========== - if [ ${{ env.sermantAgentCoreChanged }} == 'true' -o ${{ env.sermantTagTransmissionChanged }} == 'true';then - echo "enableTagTransmission=true" >> $GITHUB_ENV - fi - # all workflow will trigger while workflow changed if [ ${{ steps.changed-workflow-or-test.outputs.changed }} == 'true' -o ${{ env.triggerPushEvent }} == 'true' ];then echo "enableDubboRouter=true" >> $GITHUB_ENV @@ -207,6 +193,4 @@ runs: echo "enableSpringLane=true" >> $GITHUB_ENV echo "enableDubboLane=true" >> $GITHUB_ENV echo "enableRemoval=true" >> $GITHUB_ENV - echo "enableTagTransmission=true" >> $GITHUB_ENV - fi - + fi \ No newline at end of file diff --git a/.github/actions/common/tag-transmission/action.yml b/.github/actions/common/tag-transmission/action.yml new file mode 100644 index 0000000000..23b3da9601 --- /dev/null +++ b/.github/actions/common/tag-transmission/action.yml @@ -0,0 +1,45 @@ +name: "Common operations" +description: "do something common for tag transmission plugin test" +runs: + using: "composite" + steps: + - name: Set up JDK ${{ env.javaVersion }} + uses: actions/setup-java@v3 + with: + java-version: ${{ env.javaVersion }} + distribution: 'adopt' + cache: maven + - name: get zookeeper from cache + uses: actions/cache@v3 + with: + path: apache-zookeeper-3.6.3-bin.tar.gz + key: ${{ runner.os }}-apache-zookeeper-3.6.3 + - name: run zookeeper + shell: bash + run: | + tar -zxf apache-zookeeper-3.6.3-bin.tar.gz + bash apache-zookeeper-3.6.3-bin/bin/zkServer.sh start apache-zookeeper-3.6.3-bin/conf/zoo_sample.cfg + - name: cache dependencies + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: cache agent + uses: actions/cache@v3 + with: + path: sermant-agent-*/ + key: ${{ runner.os }}-agent-${{ github.run_id }} + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/common + - name: package common demos + shell: bash + run: | + mvn package -DskipTests --file sermant-integration-tests/tag-transmission-test/pom.xml + - name: start common httpserver + shell: bash + run: | + nohup java -jar sermant-integration-tests/tag-transmission-test/httpserver-common-demo/target/httpserver-common-demo.jar > ${{ env.logDir }}/httpserver-common-demo.log 2>&1 & \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/alibaba-dubbo/action.yml b/.github/actions/scenarios/tag-transmission/alibaba-dubbo/action.yml new file mode 100644 index 0000000000..89ab217dce --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/alibaba-dubbo/action.yml @@ -0,0 +1,61 @@ +name: "Tag Transmission Plugin AlibabaDubbo Test" +description: "Auto test for tag transmission by AlibabaDubbo" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/alibaba-dubbo + - name: alibaba.dubbo.version != 2.6.0 + if: matrix.alibabaDubboVersion != '2.6.0' + shell: bash + run: | + sed -i '//{:a;N;/<\/dependency>/!ba};/com.101tec<\/groupId>\s*zkclient<\/artifactId>/d' \ + sermant-integration-tests/tag-transmission-test/alibaba-dubbo-consumer-demo/pom.xml + sed -i '//{:a;N;/<\/dependency>/!ba};/com.101tec<\/groupId>\s*zkclient<\/artifactId>/d' \ + sermant-integration-tests/tag-transmission-test/alibaba-dubbo-provider-demo/pom.xml + - name: package demos + shell: bash + run: | + mvn package -Dalibaba.dubbo.version=${{ matrix.alibabaDubboVersion }} -DskipTests -Palibaba-dubbo-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start alibabadubbo provider demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/alibaba-dubbo-provider \ + sermant-integration-tests/tag-transmission-test/alibaba-dubbo-provider-demo/target/alibaba-dubbo-provider-demo.jar > ${{ env.logDir }}/alibaba-dubbo-provider.log 2>&1 & + - name: start alibabadubbo consumer demo + shell: bash + run: | + sleep 5s + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/alibaba-dubbo-consumer \ + sermant-integration-tests/tag-transmission-test/alibaba-dubbo-consumer-demo/target/alibaba-dubbo-consumer-demo.jar > ${{ env.logDir }}/alibaba-dubbo-consumer.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9041/alibabaDubbo/testAlibabaDubbo 120 + - name: test alibabadubbo + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=ALIBABA_DUBBO --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|alibaba-dubbo + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-alibaba-dubbo-(${{ matrix.alibabaDubboVersion }}-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/apache-dubbo/action.yml b/.github/actions/scenarios/tag-transmission/apache-dubbo/action.yml new file mode 100644 index 0000000000..2a7845aeb4 --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/apache-dubbo/action.yml @@ -0,0 +1,53 @@ +name: "Tag Transmission Plugin ApacheDubbo Test" +description: "Auto test for tag transmission by ApacheDubbo" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/apache-dubbo + - name: package demos + shell: bash + run: | + mvn package -Dapache.dubbo.version=${{ matrix.apacheDubboVersion }} -DskipTests -Papache-dubbo-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start apachedubbo provider demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/apache-dubbo-provider \ + sermant-integration-tests/tag-transmission-test/apache-dubbo-provider-demo/target/apache-dubbo-provider-demo.jar > ${{ env.logDir }}/apache-dubbo-provider.log 2>&1 & + - name: start apachedubbo consumer demo + shell: bash + run: | + sleep 5s + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/apache-dubbo-consumer \ + sermant-integration-tests/tag-transmission-test/apache-dubbo-consumer-demo/target/apache-dubbo-consumer-demo.jar > ${{ env.logDir }}/apache-dubbo-consumer.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9043/apacheDubbo/testApacheDubbo 120 + - name: test apachedubbo + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=APACHE_DUBBO --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|apache-dubbo + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-apache-dubbo-(${{ matrix.apacheDubboVersion }}-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/config/action.yml b/.github/actions/scenarios/tag-transmission/config/action.yml new file mode 100644 index 0000000000..63cd4e1795 --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/config/action.yml @@ -0,0 +1,46 @@ +name: "Tag Transmission Plugin Config Test" +description: "Auto test for tag transmission by Config" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/config + - name: package demos + shell: bash + run: | + mvn package -DskipTests -Pconfig-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start config demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/crossthread \ + sermant-integration-tests/tag-transmission-test/tomcat-demo/target/tomcat-demo.jar > ${{ env.logDir }}/tomcat.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9052/tomcat/testConfig 120 + - name: test config + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=CONFIG --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|tomcat + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-config-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/crossthread/action.yml b/.github/actions/scenarios/tag-transmission/crossthread/action.yml new file mode 100644 index 0000000000..cca726700f --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/crossthread/action.yml @@ -0,0 +1,46 @@ +name: "Tag Transmission Plugin CrossThread Test" +description: "Auto test for tag transmission by CrossThread" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/crossthread + - name: package demos + shell: bash + run: | + mvn package -DskipTests -Pcrossthread-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start crossthread demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/crossthread \ + sermant-integration-tests/tag-transmission-test/crossthread-demo/target/crossthread-demo.jar > ${{ env.logDir }}/crossthread.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9045/thread/testNewThread 120 + - name: test crossthread + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=CROSS_THREAD --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|crossthread + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-crossthread-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/grpc/action.yml b/.github/actions/scenarios/tag-transmission/grpc/action.yml new file mode 100644 index 0000000000..21f9bf5bbe --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/grpc/action.yml @@ -0,0 +1,52 @@ +name: "Tag Transmission Plugin Grpc Test" +description: "Auto test for tag transmission by Grpc" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/grpc + - name: package demos + shell: bash + run: | + mvn package -Dgrpc.version=${{ matrix.grpcVersion }} -DskipTests -Pgrpc-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start grpc client demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/grpc-client \ + sermant-integration-tests/tag-transmission-test/grpc-client-demo/target/grpc-client-demo.jar > ${{ env.logDir }}/grpc-client.log 2>&1 & + - name: start grpc server demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/grpc-server \ + sermant-integration-tests/tag-transmission-test/grpc-server-demo/target/grpc-server-demo.jar > ${{ env.logDir }}/grpc-server.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9046/grpc/testGrpcByStub 120 + - name: test grpc + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=GRPC --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|grpc + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-grpc-(${{ matrix.grpcVersion }}-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/httpclientv3/action.yml b/.github/actions/scenarios/tag-transmission/httpclientv3/action.yml new file mode 100644 index 0000000000..163d11b72b --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/httpclientv3/action.yml @@ -0,0 +1,46 @@ +name: "Tag Transmission Plugin HttpClientV3 Test" +description: "Auto test for tag transmission by httpclientv3" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/httpclientv3 + - name: package demos + shell: bash + run: | + mvn package -Dhttpclient3x.version=${{ matrix.httpclientVersion }} -DskipTests -Phttpclientv3-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start httpclientv3 demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/sermant \ + sermant-integration-tests/tag-transmission-test/httpclientv3-demo/target/httpclientv3-demo.jar > ${{ env.logDir }}/httpclientv3.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9048/httpClientV3/testHttpClientV3 120 + - name: test httpclientv3 + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=HTTPCLIENTV3 --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|httpclientv3 + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-httpclientv3-(${{ matrix.httpClientVersion }}-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/httpclientv4/action.yml b/.github/actions/scenarios/tag-transmission/httpclientv4/action.yml new file mode 100644 index 0000000000..17c71c1bd6 --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/httpclientv4/action.yml @@ -0,0 +1,46 @@ +name: "Tag Transmission Plugin HttpClientV4 Test" +description: "Auto test for tag transmission by httpclientv4" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/httpclientv4 + - name: package demos + shell: bash + run: | + mvn package -Dhttpclient4x.version=${{ matrix.httpclientVersion }} -DskipTests -Phttpclientv4-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start httpclientv4 demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/sermant \ + sermant-integration-tests/tag-transmission-test/httpclientv4-demo/target/httpclientv4-demo.jar > ${{ env.logDir }}/httpclientv4.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9049/httpClientV4/testHttpClientV4 120 + - name: test httpclientv4 + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=HTTPCLIENTV4 --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|httpclientv4 + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-httpclientv4-(${{ matrix.httpClientVersion }}-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/jdkhttp-jetty/action.yml b/.github/actions/scenarios/tag-transmission/jdkhttp-jetty/action.yml new file mode 100644 index 0000000000..12d20c82a0 --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/jdkhttp-jetty/action.yml @@ -0,0 +1,53 @@ +name: "Tag Transmission Plugin JdkHttp and Jetty Test" +description: "Auto test for tag transmission by JdkHttp and Jetty" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/jdkhttp-jetty + - name: package demos + shell: bash + run: | + mvn package -Dspring.boot.version=${{ matrix.springBootVersion }} -DskipTests -Pjdkhttp-jetty-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start jdkhttp demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/jdkhttp \ + sermant-integration-tests/tag-transmission-test/jdkhttp-demo/target/jdkhttp-demo.jar > ${{ env.logDir }}/jdkhttp.log 2>&1 & + - name: start jetty demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/jetty \ + sermant-integration-tests/tag-transmission-test/jetty-demo/target/jetty-demo.jar > ${{ env.logDir }}/jetty.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9051/jetty/testJetty 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9050/jdkHttp/testJdkHttpAndJetty 120 + - name: test jdkhttp and jetty + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=JDKHTTP_JETTY --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|jdkhttp|jetty + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-jdkhttp-jetty-(${{ matrix.springBootVersion }}-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/jdkhttp-tomcat/action.yml b/.github/actions/scenarios/tag-transmission/jdkhttp-tomcat/action.yml new file mode 100644 index 0000000000..c7d6f7ef47 --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/jdkhttp-tomcat/action.yml @@ -0,0 +1,53 @@ +name: "Tag Transmission Plugin JdkHttp and Tomcat Test" +description: "Auto test for tag transmission by JdkHttp and Tomcat" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/jdkhttp-tomcat + - name: package demos + shell: bash + run: | + mvn package -Dspring.boot.version=${{ matrix.springBootVersion }} -DskipTests -Pjdkhttp-tomcat-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start jdkhttp demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/jdkhttp \ + sermant-integration-tests/tag-transmission-test/jdkhttp-demo/target/jdkhttp-demo.jar > ${{ env.logDir }}/jdkhttp.log 2>&1 & + - name: start tomcat demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/jetty \ + sermant-integration-tests/tag-transmission-test/tomcat-demo/target/tomcat-demo.jar > ${{ env.logDir }}/tomcat.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9052/tomcat/testTomcat 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9050/jdkHttp/testJdkHttpAndTomcat 120 + - name: test jdkhttp and tomcat + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=JDKHTTP_TOMCAT --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|jdkhttp|tomcat + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-jdkhttp-tomcat-(${{ matrix.springBootVersion }}-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/kafka/action.yml b/.github/actions/scenarios/tag-transmission/kafka/action.yml new file mode 100644 index 0000000000..71ea9126c5 --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/kafka/action.yml @@ -0,0 +1,65 @@ +name: "Tag Transmission Plugin kafka Test" +description: "Auto test for tag transmission by kafka" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/kafka + - name: get kafka from cache + uses: actions/cache@v3 + with: + path: kafka_2.13-2.7.0.tgz + key: ${{ runner.os }}-kafka_2.13-2.7.0 + restore-keys: | + ${{ runner.os }}-kafka_2.13-2.7.0 + - name: start kafka + shell: bash + run: | + tar -zxf kafka_2.13-2.7.0.tgz + nohup bash kafka_2.13-2.7.0/bin/kafka-server-start.sh kafka_2.13-2.7.0/config/server.properties & + - name: package demos + shell: bash + run: | + mvn package -Dkafka-client.version=${{ matrix.kafkaVersion }} -DskipTests -Pkafka-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start kafka producer demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/kafka-producer \ + sermant-integration-tests/tag-transmission-test/kafka-producer-demo/target/kafka-producer-demo.jar > ${{ env.logDir }}/kafka-producer.log 2>&1 & + - name: start kafka consumer demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/kafka-consumer \ + sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/target/kafka-consumer-demo.jar > ${{ env.logDir }}/kafka-consumer.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9054/kafkaProducer/checkKafkaProducerStatus 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9053/kafkaConsumer/queryKafkaTag 120 + - name: test kafka + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=KAFKA --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|kafka + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-kafka-(${{ matrix.kafkaVersion }}-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/okhttp/action.yml b/.github/actions/scenarios/tag-transmission/okhttp/action.yml new file mode 100644 index 0000000000..b2b47bf2ac --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/okhttp/action.yml @@ -0,0 +1,46 @@ +name: "Tag Transmission Plugin OkHttp Test" +description: "Auto test for tag transmission by okhttp" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/okhttp + - name: package demos + shell: bash + run: | + mvn package -Dokhttpv2.version=${{ matrix.okHttpVersion }} -DskipTests -Pokhttp-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start okhttp demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/sermant \ + sermant-integration-tests/tag-transmission-test/okhttp-demo/target/okhttp-demo.jar > ${{ env.logDir }}/okhttp.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9055/okHttp/testOkHttp 120 + - name: test okhttp + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=OKHTTP --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|okhttp + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-okhttp-(${{ matrix.okHttpVersion }}-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/rocketmq/action.yml b/.github/actions/scenarios/tag-transmission/rocketmq/action.yml new file mode 100644 index 0000000000..d73eb8734c --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/rocketmq/action.yml @@ -0,0 +1,72 @@ +name: "Tag Transmission Plugin rocketmq Test" +description: "Auto test for tag transmission by rocketmq" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/rocketmq + - name: get rocketmq from cache + uses: actions/cache@v3 + with: + path: rocketmq-all-4.8.0-bin-release.zip + key: ${{ runner.os }}-rocketmq-all-4.8.0-bin-release + restore-keys: | + ${{ runner.os }}-rocketmq-all-4.8.0-bin-release + - name: start rocketmq server + shell: bash + run: | + unzip rocketmq-all-4.8.0-bin-release.zip + sed -i 's/if \[\[ "$JAVA_MAJOR_VERSION" -lt "9" \]\]/if [ "$JAVA_MAJOR_VERSION" -lt "9" ]/g' rocketmq-all-4.8.0-bin-release/bin/runserver.sh + sed -i 's/-Xms4g -Xmx4g -Xmn2g/-Xms1g -Xmx1g -Xmn1g/g' rocketmq-all-4.8.0-bin-release/bin/runserver.sh + nohup bash rocketmq-all-4.8.0-bin-release/bin/mqnamesrv & + - name: start rocketmq broker + shell: bash + run: | + sed -i 's/-Xms8g -Xmx8g -Xmn4g/-Xms1g -Xmx1g -Xmn1g/g' rocketmq-all-4.8.0-bin-release/bin/runbroker.sh + nohup bash rocketmq-all-4.8.0-bin-release/bin/mqbroker -n localhost:9876 & + - name: package demos + shell: bash + run: | + mvn package -Drocketmq-client.version=${{ matrix.rocketMqVersion }} -DskipTests -Procketmq-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start rocketmq producer demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/rocketmq-producer \ + sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/target/rocketmq-producer-demo.jar > ${{ env.logDir }}/rocketmq-producer.log 2>&1 & + - name: start rocketmq consumer demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/rocketmq-consumer \ + sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/target/rocketmq-consumer-demo.jar > ${{ env.logDir }}/rocketmq-consumer.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9057/rocketMqProducer/checkRocketMqProducerStatus 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9056/rocketMqConsumer/queryRocketMqTag 120 + - name: test rocketmq + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=ROCKETMQ --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|rocketmq + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-rocketmq-(${{ matrix.rocketMqVersion }}-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/servicecomb/action.yml b/.github/actions/scenarios/tag-transmission/servicecomb/action.yml new file mode 100644 index 0000000000..952f6d7c86 --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/servicecomb/action.yml @@ -0,0 +1,76 @@ +name: "Tag Transmission Plugin ServiceComb Test" +description: "Auto test for tag transmission by ServiceComb" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/servicecomb + - name: get local cse from cache + uses: actions/cache@v3 + with: + path: Local-CSE-2.1.3-linux-amd64.zip + key: ${{ runner.os }}-local-cse + restore-keys: | + ${{ runner.os }}-local-cse + - name: start cse + shell: bash + run: | + export ROOT_PATH=$(pwd) + bash ./sermant-integration-tests/scripts/startCse.sh + - name: get nacos from cache + uses: actions/cache@v3 + with: + path: nacos-server-1.4.2.tar.gz + key: ${{ runner.os }}-nacos-server-1.4.2 + restore-keys: | + ${{ runner.os }}-nacos-server-1.4.2 + - name: start nacos + shell: bash + run: | + tar -zxf nacos-server-1.4.2.tar.gz + bash nacos/bin/startup.sh -m standalone + - name: package demos + shell: bash + run: | + mvn package -Dservicecomb.version=${{ matrix.serviceCombVersion }} -DskipTests -Pservicecomb-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start servicecomb consumer demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/servicecomb-consumer \ + sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/target/servicecomb-consumer-demo.jar > ${{ env.logDir }}/servicecomb-consumer.log 2>&1 & + - name: start servicecomb provider demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/servicecomb-provider \ + sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/target/servicecomb-provider-demo.jar > ${{ env.logDir }}/servicecomb-provider.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9058/serviceCombConsumer/testServiceCombRpc 120 + - name: test servicecomb + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=SERVICECOMB --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|servicecomb + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-servicecomb-(${{ matrix.serviceCombVersion }}-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/actions/scenarios/tag-transmission/sofarpc/action.yml b/.github/actions/scenarios/tag-transmission/sofarpc/action.yml new file mode 100644 index 0000000000..5aefa07f72 --- /dev/null +++ b/.github/actions/scenarios/tag-transmission/sofarpc/action.yml @@ -0,0 +1,52 @@ +name: "Tag Transmission Plugin SofaRpc Test" +description: "Auto test for tag transmission by SofaRpc" +runs: + using: composite + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/tag-transmission/sofarpc + - name: package demos + shell: bash + run: | + mvn package -Dsofarpc.version=${{ matrix.sofaRpcVersion }} -DskipTests -Psofarpc-test --file \ + sermant-integration-tests/tag-transmission-test/pom.xml + - name: start sofarpc consumer demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/sofarpc-consumer \ + sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/target/sofarpc-consumer-demo.jar > ${{ env.logDir }}/sofarpc-consumer.log 2>&1 & + - name: start sofarpc provider demo + shell: bash + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=default -jar \ + -Dsermant_log_dir=${{ env.logDir }}/sofarpc-provider \ + sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/target/sofarpc-provider-demo.jar > ${{ env.logDir }}/sofarpc-provider.log 2>&1 & + - name: waiting for services start + shell: bash + run: | + ps -ef | grep java + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9040/common/httpServer 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:9060/sofaRpc/testSofaRpc 120 + - name: test sofarpc + shell: bash + run: | + mvn test -Dtag.transmission.integration.test.type=SOFARPC --file \ + sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: httpserver-common|sofarpc + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: (${{ github.job }})-tag-transmission-sofarpc-(${{ matrix.sofaRpcVersion }}-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 \ No newline at end of file diff --git a/.github/workflows/tagtransmission_integration_test.yml b/.github/workflows/tagtransmission_integration_test.yml new file mode 100644 index 0000000000..f4a305d4e0 --- /dev/null +++ b/.github/workflows/tagtransmission_integration_test.yml @@ -0,0 +1,432 @@ +name: Tagtransmission integration test +env: + sermantVersion: 1.0.0 +on: + push: + pull_request: + branches: + - '*' + paths: + - 'sermant-agentcore/**' + - 'sermant-integration-tests/tag-transmission-test/**' + - 'sermant-plugins/sermant-tag-transmission/**' + - '.github/workflows/tagtransmission_integration_test.yml' + - '.github/actions/common/tag-transmission/**' + - '.github/actions/scenarios/tag-transmission/**' +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.head_ref }} + cancel-in-progress: true +jobs: + download-midwares-and-cache: + name: download midwares and cache + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: cache local cse + uses: actions/cache@v3 + with: + path: Local-CSE-2.1.3-linux-amd64.zip + key: ${{ runner.os }}-local-cse + restore-keys: | + ${{ runner.os }}-local-cse + - name: download cse + run: | + export ROOT_PATH=$(pwd) + bash ./sermant-integration-tests/scripts/tryDownloadMidware.sh cse + - name: cache zookeeper + uses: actions/cache@v3 + with: + path: apache-zookeeper-3.6.3-bin.tar.gz + key: ${{ runner.os }}-apache-zookeeper-3.6.3 + restore-keys: | + ${{ runner.os }}-apache-zookeeper-3.6.3 + - name: download zookeeper + run: | + export ROOT_PATH=$(pwd) + bash ./sermant-integration-tests/scripts/tryDownloadMidware.sh zk + - name: cache nacos server + uses: actions/cache@v3 + with: + path: nacos-server-1.4.2.tar.gz + key: ${{ runner.os }}-nacos-server-1.4.2 + restore-keys: | + ${{ runner.os }}-nacos-server-1.4.2 + - name: download nacos + run: | + export ROOT_PATH=$(pwd) + bash ./sermant-integration-tests/scripts/tryDownloadMidware.sh nacos + - name: cache rocketmq + uses: actions/cache@v3 + with: + path: rocketmq-all-4.8.0-bin-release.zip + key: ${{ runner.os }}-rocketmq-all-4.8.0-bin-release + restore-keys: | + ${{ runner.os }}-rocketmq-all-4.8.0-bin-release + - name: download rocketmq + run: | + export ROOT_PATH=$(pwd) + bash ./sermant-integration-tests/scripts/tryDownloadMidware.sh rocketmq + - name: cache kafka + uses: actions/cache@v3 + with: + path: kafka_2.13-2.7.0.tgz + key: ${{ runner.os }}-kafka_2.13-2.7.0 + restore-keys: | + ${{ runner.os }}-kafka_2.13-2.7.0 + - name: download kafka + run: | + export ROOT_PATH=$(pwd) + bash ./sermant-integration-tests/scripts/tryDownloadMidware.sh kafka + build-agent-and-cache: + name: build agent and cache + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'adopt' + cache: maven + - name: cache agent + uses: actions/cache@v3 + with: + path: sermant-agent-*/ + key: ${{ runner.os }}-agent-${{ github.run_id }} + - name: package agent + run: | + sed -i '/sermant-backend/d' pom.xml + sed -i '/sermant-integration-tests/d' pom.xml + sed -i '/sermant-injector/d' pom.xml + sed -i '/sermant-flowcontrol/d' sermant-plugins/pom.xml + mvn package -DskipTests -Ptest --file pom.xml + test-for-tag-transmission-httpclientv3: + name: Test for tag transmission httpclientv3 + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - httpClientVersion: "3.0.1" + - httpClientVersion: "3.1" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for httpClientVersion=${{ matrix.httpClientVersion }} + uses: ./.github/actions/scenarios/tag-transmission/httpclientv3 + test-for-tag-transmission-httpclientv4: + name: Test for tag transmission httpclientv4 + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - httpClientVersion: "4.3.6" + - httpClientVersion: "4.4.1" + - httpClientVersion: "4.5.14" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for httpClientVersion=${{ matrix.httpClientVersion }} + uses: ./.github/actions/scenarios/tag-transmission/httpclientv4 + test-for-tag-transmission-okhttp: + name: Test for tag transmission okhttp + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - okHttpVersion: "2.0.0" + - okHttpVersion: "2.1.0" + - okHttpVersion: "2.2.0" + - okHttpVersion: "2.3.0" + - okHttpVersion: "2.4.0" + - okHttpVersion: "2.5.0" + - okHttpVersion: "2.6.0" + - okHttpVersion: "2.7.5" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for okHttpVersion=${{ matrix.okHttpVersion }} + uses: ./.github/actions/scenarios/tag-transmission/okhttp + test-for-tag-transmission-grpc: + name: Test for tag transmission grpc + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - grpcVersion: "1.13.1" + - grpcVersion: "1.21.0" + - grpcVersion: "1.26.0" + - grpcVersion: "1.31.0" + - grpcVersion: "1.37.0" + - grpcVersion: "1.42.2" + - grpcVersion: "1.49.0" + - grpcVersion: "1.52.1" + - grpcVersion: "1.58.0" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for grpcVersion=${{ matrix.grpcVersion }} + uses: ./.github/actions/scenarios/tag-transmission/grpc + test-for-tag-transmission-sofarpc: + name: Test for tag transmission sofarpc + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - sofaRpcVersion: "5.3.4" + - sofaRpcVersion: "5.4.8" + - sofaRpcVersion: "5.5.9" + - sofaRpcVersion: "5.6.5" + - sofaRpcVersion: "5.7.10" + - sofaRpcVersion: "5.8.8" + - sofaRpcVersion: "5.9.2" + - sofaRpcVersion: "5.10.0" + - sofaRpcVersion: "5.11.1" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for sofaRpcVersion=${{ matrix.sofaRpcVersion }} + uses: ./.github/actions/scenarios/tag-transmission/sofarpc + test-for-tag-transmission-servicecomb: + name: Test for tag transmission servicecomb + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - serviceCombVersion: "2.1.6" + - serviceCombVersion: "2.2.4" + - serviceCombVersion: "2.3.6" + - serviceCombVersion: "2.5.3" + - serviceCombVersion: "2.6.3" + - serviceCombVersion: "2.7.10" + - serviceCombVersion: "2.8.12" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for servicecombVersion=${{ matrix.serviceCombVersion }} + uses: ./.github/actions/scenarios/tag-transmission/servicecomb + test-for-tag-transmission-alibabadubbo: + name: Test for tag transmission alibabadubbo + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - alibabaDubboVersion: "2.6.0" + - alibabaDubboVersion: "2.6.3" + - alibabaDubboVersion: "2.6.6" + - alibabaDubboVersion: "2.6.9" + - alibabaDubboVersion: "2.6.12" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for alibabaDubboVersion=${{ matrix.alibabaDubboVersion }} + uses: ./.github/actions/scenarios/tag-transmission/alibaba-dubbo + test-for-tag-transmission-apachedubbo: + name: Test for tag transmission apachedubbo + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - apacheDubboVersion: "2.7.5" + - apacheDubboVersion: "2.7.15" + - apacheDubboVersion: "2.7.23" + - apacheDubboVersion: "3.0.15" + - apacheDubboVersion: "3.1.11" + - apacheDubboVersion: "3.2.7" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for apacheDubboVersion=${{ matrix.apacheDubboVersion}} + uses: ./.github/actions/scenarios/tag-transmission/apache-dubbo + test-for-tag-transmission-crossthread: + name: Test for tag transmission crossthread + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for crossthread + uses: ./.github/actions/scenarios/tag-transmission/crossthread + test-for-tag-transmission-config: + name: Test for tag transmission config + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for config + uses: ./.github/actions/scenarios/tag-transmission/config + test-for-tag-transmission-kafka: + name: Test for tag transmission kafka + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - kafkaVersion: "2.3.1" + - kafkaVersion: "1.1.1" + - kafkaVersion: "2.7.2" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for kafkaVersion=${{ matrix.kafkaVersion }} + uses: ./.github/actions/scenarios/tag-transmission/kafka + test-for-tag-transmission-rocketmq: + name: Test for tag transmission rocketmq + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - rocketMqVersion: "4.8.0" + - rocketMqVersion: "4.9.7" + - rocketMqVersion: "5.0.0" + - rocketMqVersion: "5.1.4" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for rocketMqVersion=${{ matrix.rocketMqVersion }} + uses: ./.github/actions/scenarios/tag-transmission/rocketmq + test-for-tag-transmission-jdkhttp-jetty: + name: Test for tag transmission jdkhttp and jetty + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - springBootVersion: "1.0.2.RELEASE" + - springBootVersion: "1.1.12.RELEASE" + - springBootVersion: "1.3.8.RELEASE" + - springBootVersion: "1.4.7.RELEASE" + - springBootVersion: "1.5.22.RELEASE" + - springBootVersion: "2.2.0.RELEASE" + - springBootVersion: "2.4.13" + - springBootVersion: "2.7.16" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for springBootVersion=${{ matrix.springBootVersion }} + uses: ./.github/actions/scenarios/tag-transmission/jdkhttp-jetty + test-for-tag-transmission-jdkhttp-tomcat: + name: Test for tag transmission jdkhttp and tomcat + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - springBootVersion: "1.0.2.RELEASE" + - springBootVersion: "1.1.12.RELEASE" + - springBootVersion: "1.3.8.RELEASE" + - springBootVersion: "1.4.7.RELEASE" + - springBootVersion: "1.5.22.RELEASE" + - springBootVersion: "2.2.0.RELEASE" + - springBootVersion: "2.4.13" + - springBootVersion: "2.7.16" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/tag-transmission + - name: tag transmission test for springBootVersion=${{ matrix.springBootVersion }} + uses: ./.github/actions/scenarios/tag-transmission/jdkhttp-tomcat \ No newline at end of file diff --git a/sermant-integration-tests/scripts/tryDownloadMidware.sh b/sermant-integration-tests/scripts/tryDownloadMidware.sh index 628a4e439c..db5385cffe 100644 --- a/sermant-integration-tests/scripts/tryDownloadMidware.sh +++ b/sermant-integration-tests/scripts/tryDownloadMidware.sh @@ -35,9 +35,9 @@ NACOS_FILE_NAME_210=nacos-server-2.1.0.tar.gz SERVICE_CENTER_ADDRESS=https://github.com/apache/servicecomb-service-center/releases/download/v2.1.0/apache-servicecomb-service-center-2.1.0-linux-amd64.tar.gz SERVICE_CENTER_FILE_NAME=apache-servicecomb-service-center-2.1.0-linux-amd64.tar.gz #======================================rocketmq配置====================================== -ROCKETMQ_ADDRESS=https://archive.apache.org/dist/rocketmq/4.8.0/rocketmq-all-4.8.0-source-release.zip -ROCKETMQ_FILE_NAME=rocketmq-all-4.8.0-source-release.zip -#======================================rocketmq配置====================================== +ROCKETMQ_ADDRESS=https://archive.apache.org/dist/rocketmq/4.8.0/rocketmq-all-4.8.0-bin-release.zip +ROCKETMQ_FILE_NAME=rocketmq-all-4.8.0-bin-release.zip +#======================================kafka配置====================================== KAFKA_ADDRESS=https://archive.apache.org/dist/kafka/2.7.0/kafka_2.13-2.7.0.tgz KAFKA_FILE_NAME=kafka_2.13-2.7.0.tgz diff --git a/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/pom.xml new file mode 100644 index 0000000000..6bcad6b56c --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/pom.xml @@ -0,0 +1,49 @@ + + + + tag-transmission-test + com.huaweicloud.sermant.tagtransmission + 1.0.0 + + 4.0.0 + + kafka-consumer-demo + + + 8 + 8 + + + + + com.huaweicloud.sermant.tagtransmission + midware-common-demo + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-util-demo + + + org.springframework.boot + spring-boot-starter-web + + + org.apache.kafka + kafka-clients + ${kafka-client.version} + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/consumer/KafkaConsumerApplication.java b/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/consumer/KafkaConsumerApplication.java new file mode 100644 index 0000000000..4e9d8dce5e --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/consumer/KafkaConsumerApplication.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.huaweicloud.demo.tagtransmission.kafka.consumer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@SpringBootApplication +public class KafkaConsumerApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(KafkaConsumerApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/consumer/KafkaWithConsumer.java b/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/consumer/KafkaWithConsumer.java new file mode 100644 index 0000000000..1084e4de12 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/consumer/KafkaWithConsumer.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.huaweicloud.demo.tagtransmission.kafka.consumer; + +import com.huaweicloud.demo.tagtransmission.midware.common.MessageConstant; +import com.huaweicloud.demo.tagtransmission.util.HttpClientUtils; + +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * kafka消费者 + * + * @author daizhenyu + * @since 2023-09-08 + **/ +@Component +public class KafkaWithConsumer implements CommandLineRunner { + /** + * 存储消费者调用http服务端返回的流量标签 + */ + public static final Map KAFKA_TAG_MAP = new HashMap<>(); + + @Value("${common.server.url}") + private String commonServerUrl; + + @Value("${kafka.address}") + private String kafkaAddress; + + @Override + public void run(String[] args) { + Properties properties = new Properties(); + properties.put("bootstrap.servers", kafkaAddress); + properties.put("group.id", "my-group"); + properties.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); + properties.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); + + KafkaConsumer consumer = new KafkaConsumer<>(properties); + + consumer.subscribe(Collections.singletonList(MessageConstant.TOPIC)); + + while (true) { + ConsumerRecords records = consumer.poll(MessageConstant.KAFKA_CONSUMER_TIMEOUT); + for (ConsumerRecord record : records) { + record.value(); + KAFKA_TAG_MAP.put("kafkaTag", HttpClientUtils.doHttpUrlConnectionGet(commonServerUrl)); + } + } + } +} diff --git a/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/consumer/controller/KafkaConsumerController.java b/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/consumer/controller/KafkaConsumerController.java new file mode 100644 index 0000000000..890f794790 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/consumer/controller/KafkaConsumerController.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.huaweicloud.demo.tagtransmission.kafka.consumer.controller; + +import com.huaweicloud.demo.tagtransmission.kafka.consumer.KafkaWithConsumer; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +/** + * 消息中间件消费者controller + * + * @author daizhenyu + * @since 2023-09-28 + **/ +@RestController +@RequestMapping(value = "kafkaConsumer") +public class KafkaConsumerController { + /** + * 查询kafka消费者消费消息后返回的流量标签透传 + * + * @return string + */ + @RequestMapping(value = "queryKafkaTag", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String queryKafkaTag() { + String trafficTag = KafkaWithConsumer.KAFKA_TAG_MAP.get("kafkaTag"); + + // 删除流量标签,以免干扰下一次测试查询 + KafkaWithConsumer.KAFKA_TAG_MAP.remove("kafkaTag"); + return trafficTag; + } +} diff --git a/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..647efc6236 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/kafka-consumer-demo/src/main/resources/application.properties @@ -0,0 +1,3 @@ +common.server.url=http://127.0.0.1:9040/common/httpServer +kafka.address=127.0.0.1:9092 +server.port=9053 \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/kafka-producer-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/kafka-producer-demo/pom.xml new file mode 100644 index 0000000000..09a15e9989 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/kafka-producer-demo/pom.xml @@ -0,0 +1,48 @@ + + + + tag-transmission-test + com.huaweicloud.sermant.tagtransmission + 1.0.0 + + 4.0.0 + + kafka-producer-demo + + + 8 + 8 + + + + + com.huaweicloud.sermant.tagtransmission + midware-common-demo + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-util-demo + + + org.springframework.boot + spring-boot-starter-web + + + org.apache.kafka + kafka-clients + ${kafka-client.version} + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/kafka-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/producer/KafkaProducerApplication.java b/sermant-integration-tests/tag-transmission-test/kafka-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/producer/KafkaProducerApplication.java new file mode 100644 index 0000000000..f360430528 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/kafka-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/producer/KafkaProducerApplication.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.huaweicloud.demo.tagtransmission.kafka.producer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@SpringBootApplication +public class KafkaProducerApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(KafkaProducerApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/kafka-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/producer/controller/KafkaProducerController.java b/sermant-integration-tests/tag-transmission-test/kafka-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/producer/controller/KafkaProducerController.java new file mode 100644 index 0000000000..99b67c5e22 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/kafka-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/kafka/producer/controller/KafkaProducerController.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.huaweicloud.demo.tagtransmission.kafka.producer.controller; + +import com.huaweicloud.demo.tagtransmission.midware.common.MessageConstant; + +import org.apache.kafka.clients.producer.Callback; +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.clients.producer.Producer; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.apache.kafka.clients.producer.RecordMetadata; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Properties; + +/** + * 消息中间件生产者controller, 用于生产消息和查询kafka透传的流量标签 + * + * @author daizhenyu + * @since 2023-09-28 + **/ +@RestController +@RequestMapping(value = "kafkaProducer") +public class KafkaProducerController { + @Value("${kafka.address}") + private String kafkaAddress; + + /** + * kafka生产一条消息 + * + * @return string + */ + @RequestMapping(value = "testKafkaProducer", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String testKafkaProducer() { + produceKafkaData(); + return "kafka-produce-message-success"; + } + + /** + * 用于检测kafka生产者进程是否正常启动 + * + * @return string + */ + @RequestMapping(value = "checkKafkaProducerStatus", method = RequestMethod.GET, + produces = MediaType.TEXT_PLAIN_VALUE) + public String checkKafkaProducerStatus() { + return "ok"; + } + + private void produceKafkaData() { + Properties properties = new Properties(); + properties.put("bootstrap.servers", kafkaAddress); + properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); + properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); + + Producer producer = new KafkaProducer<>(properties); + String messageBody = buildMessageBody(MessageConstant.MESSAGE_BODY_KAFKA); + ProducerRecord record = new ProducerRecord<>(MessageConstant.TOPIC, MessageConstant.KAFKA_KEY, + messageBody); + producer.send(record, new Callback() { + @Override + public void onCompletion(RecordMetadata metadata, Exception exception) { + } + }); + producer.close(); + } + + private String buildMessageBody(String body) { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern(MessageConstant.TIME_FORMAT); + String messageBody = body + dtf.format(LocalDateTime.now()); + return messageBody; + } +} diff --git a/sermant-integration-tests/tag-transmission-test/kafka-producer-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/kafka-producer-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..84f29decfb --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/kafka-producer-demo/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port=9054 +kafka.address=127.0.0.1:9092 \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/midware-common-demo/src/main/java/com/huaweicloud/demo/tagtransmission/midware/common/MessageConstant.java b/sermant-integration-tests/tag-transmission-test/midware-common-demo/src/main/java/com/huaweicloud/demo/tagtransmission/midware/common/MessageConstant.java index 719bba4eb0..d5c37a2661 100644 --- a/sermant-integration-tests/tag-transmission-test/midware-common-demo/src/main/java/com/huaweicloud/demo/tagtransmission/midware/common/MessageConstant.java +++ b/sermant-integration-tests/tag-transmission-test/midware-common-demo/src/main/java/com/huaweicloud/demo/tagtransmission/midware/common/MessageConstant.java @@ -17,7 +17,7 @@ package com.huaweicloud.demo.tagtransmission.midware.common; /** - * 消息中间件的公共常量 + * 消息中间件的常量 * * @author daizhenyu * @since 2023-09-28 @@ -51,7 +51,7 @@ public class MessageConstant { /** * rocketmq消费者组 */ - public static final String CONSUME_GROUP = "consume_group"; + public static final String ROCKETMQ_CONSUME_GROUP = "consume_group"; /** * rocketmq消息体 diff --git a/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/RocketMqConsumer.java b/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/RocketMqConsumer.java index 8377f394b1..33d1c55ec3 100644 --- a/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/RocketMqConsumer.java +++ b/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/RocketMqConsumer.java @@ -59,7 +59,7 @@ public void run(String[] args) throws MQClientException { } private void consumeData() throws MQClientException { - DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(MessageConstant.CONSUME_GROUP); + DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(MessageConstant.ROCKETMQ_CONSUME_GROUP); consumer.setNamesrvAddr(rocketMqAddress); consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET); consumer.subscribe(MessageConstant.TOPIC, MessageConstant.TAG_SCOPE); diff --git a/sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/pom.xml new file mode 100644 index 0000000000..30e747b5ce --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/pom.xml @@ -0,0 +1,48 @@ + + + + tag-transmission-test + com.huaweicloud.sermant.tagtransmission + 1.0.0 + + 4.0.0 + + rocketmq-producer-demo + + + 8 + 8 + + + + + com.huaweicloud.sermant.tagtransmission + midware-common-demo + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-util-demo + + + org.springframework.boot + spring-boot-starter-web + + + org.apache.rocketmq + rocketmq-client + ${rocketmq-client.version} + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/producer/RocketMqProducerApplication.java b/sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/producer/RocketMqProducerApplication.java new file mode 100644 index 0000000000..1be007a7ec --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/producer/RocketMqProducerApplication.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.huaweicloud.demo.tagtransmission.rocketmq.producer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@SpringBootApplication +public class RocketMqProducerApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(RocketMqProducerApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/producer/controller/RocketMqProducerController.java b/sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/producer/controller/RocketMqProducerController.java new file mode 100644 index 0000000000..8f939f19c5 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/producer/controller/RocketMqProducerController.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.huaweicloud.demo.tagtransmission.rocketmq.producer.controller; + +import com.huaweicloud.demo.tagtransmission.midware.common.MessageConstant; + +import org.apache.rocketmq.client.exception.MQBrokerException; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.client.producer.DefaultMQProducer; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.remoting.exception.RemotingException; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * 消息中间件生产者controller, 用于生产消息 + * + * @author daizhenyu + * @since 2023-09-28 + **/ +@RestController +@RequestMapping(value = "rocketMqProducer") +public class RocketMqProducerController { + @Value("${rocketmq.address}") + private String rocketMqAddress; + + /** + * 用于检查生产者进程是否正常启动 + * + * @return string + */ + @RequestMapping(value = "checkRocketMqProducerStatus", method = RequestMethod.GET, + produces = MediaType.TEXT_PLAIN_VALUE) + public String checkRocketMqProducerStatus() { + return "ok"; + } + + /** + * roketmq生成一条消息 + * + * @return string + * @throws InterruptedException + * @throws RemotingException + * @throws MQClientException + * @throws MQBrokerException + */ + @RequestMapping(value = "testRocketMqProducer", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String testRocketMqProducer() + throws InterruptedException, RemotingException, MQClientException, MQBrokerException { + produceRocketMqData(); + return "rocketmq-produce-message-success"; + } + + private void produceRocketMqData() + throws RemotingException, InterruptedException, MQBrokerException, MQClientException { + DefaultMQProducer producer = new DefaultMQProducer(MessageConstant.ROCKETMQ_PRODUCE_GROUP); + producer.setNamesrvAddr(rocketMqAddress); + producer.start(); + + String messageBody = buildMessageBody(MessageConstant.MESSAGE_BODY_ROCKET); + + Message message = new Message(MessageConstant.TOPIC, MessageConstant.TAG, + messageBody.getBytes(StandardCharsets.UTF_8)); + producer.send(message); + producer.shutdown(); + } + + private String buildMessageBody(String body) { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern(MessageConstant.TIME_FORMAT); + String messageBody = body + dtf.format(LocalDateTime.now()); + return messageBody; + } +} \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..bc2d801bf5 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/rocketmq-producer-demo/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port=9057 +rocketmq.address=127.0.0.1:9876 \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml b/sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml new file mode 100644 index 0000000000..c9fd5b003f --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/pom.xml @@ -0,0 +1,68 @@ + + + + tag-transmission-test + com.huaweicloud.sermant.tagtransmission + 1.0.0 + + 4.0.0 + + tag-transmission-integration-test + + + 8 + 8 + + + + + org.apache.httpcomponents + httpclient + 4.5.13 + test + + + org.junit.jupiter + junit-jupiter + test + + + com.alibaba + fastjson + 2.0.9 + test + + + org.apache.curator + curator-recipes + 4.3.0 + test + + + commons-logging + commons-logging + 1.2 + test + + + ch.qos.logback + logback-core + 1.2.9 + test + + + ch.qos.logback + logback-classic + 1.2.9 + test + + + org.slf4j + slf4j-api + 1.7.36 + test + + + \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/src/test/java/com/huaweicloud/demo/tagtransmission/integration/TagTransmissionTest.java b/sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/src/test/java/com/huaweicloud/demo/tagtransmission/integration/TagTransmissionTest.java new file mode 100644 index 0000000000..87e1d9845d --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/src/test/java/com/huaweicloud/demo/tagtransmission/integration/TagTransmissionTest.java @@ -0,0 +1,277 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.huaweicloud.demo.tagtransmission.integration; + +import com.huaweicloud.demo.tagtransmission.integration.utils.RequestUtils; + +import com.alibaba.fastjson.JSON; + +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.ExponentialBackoffRetry; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.data.Stat; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; + +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +/** + * 流量标签透传插件测试 + * + * @author daizhenyu + * @since 2023-10-10 + **/ +public class TagTransmissionTest { + private static final Map EXACT_TAG_MAP = new HashMap<>(); + + @BeforeAll + public static void before() { + EXACT_TAG_MAP.put("id", "001"); + } + + /** + * 测试httpclient3.x版本透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "HTTPCLIENTV3") + public void testHttpClientV3() { + checkTagTransmission("http://127.0.0.1:9048/httpClientV3/testHttpClientV3", EXACT_TAG_MAP, "httpclientv3"); + } + + /** + * 测试httpclient4.x版本透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "HTTPCLIENTV4") + public void testHttpClientV4() { + checkTagTransmission("http://127.0.0.1:9049/httpClientV4/testHttpClientV4", EXACT_TAG_MAP, "httpclientv4"); + } + + /** + * 测试okhttp透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "OKHTTP") + public void testOkHttp() { + checkTagTransmission("http://127.0.0.1:9055/okHttp/testOkHttp", EXACT_TAG_MAP, "okhttp"); + } + + /** + * 测试jdkhttp和jetty服务端透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "JDKHTTP_JETTY") + public void testJdkHttpAndJetty() { + checkTagTransmission("http://127.0.0.1:9050/jdkHttp/testJdkHttpAndJetty", EXACT_TAG_MAP, "jdkhttp and jetty"); + } + + /** + * 测试jdkhttp和tomcat服务端透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "JDKHTTP_TOMCAT") + public void testJdkHttpAndTomcat() { + checkTagTransmission("http://127.0.0.1:9050/jdkHttp/testJdkHttpAndTomcat", EXACT_TAG_MAP, "jdkhttp and tomcat"); + } + + /** + * 测试alibaba dubbo透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "ALIBABA_DUBBO") + public void testAlibabaDubbo() { + checkTagTransmission("http://127.0.0.1:9041/alibabaDubbo/testAlibabaDubbo", EXACT_TAG_MAP, "alibaba dubbo"); + } + + /** + * 测试apache dubbo透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "APACHE_DUBBO") + public void testApacheDubbo() { + checkTagTransmission("http://127.0.0.1:9043/apacheDubbo/testApacheDubbo", EXACT_TAG_MAP, "apache dubbo"); + } + + /** + * 测试sofarpc透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "SOFARPC") + public void testSofaRpc() { + checkTagTransmission("http://127.0.0.1:9060/sofaRpc/testSofaRpc", EXACT_TAG_MAP, "sofarpc dubbo"); + } + + /** + * 测试servicecomb rpc透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "SERVICECOMB") + public void testServiceComb() { + checkTagTransmission("http://127.0.0.1:9058/serviceCombConsumer/testServiceCombRpc", EXACT_TAG_MAP, + "servicecomb rpc"); + } + + /** + * 测试grpc透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "GRPC") + public void testGrpc() { + checkTagTransmission("http://127.0.0.1:9046/grpc/testGrpcByStub", EXACT_TAG_MAP, "grpc stub"); + checkTagTransmission("http://127.0.0.1:9046/grpc/testGrpcByDynamicMessage", EXACT_TAG_MAP, + "grpc dynamic message"); + } + + /** + * 测试跨线程透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "CROSS_THREAD") + public void testCrossThread() { + // 测试 跨线程透传流量标签 + Map threadUrlMap = new HashMap<>(); + threadUrlMap.put("newThread", "http://127.0.0.1:9045/thread/testNewThread"); + threadUrlMap.put("executor", "http://127.0.0.1:9045/thread/testExecutor"); + threadUrlMap.put("submit", "http://127.0.0.1:9045/thread/testSubmit"); + threadUrlMap.put("schedule", "http://127.0.0.1:9045/thread/testSchedule"); + threadUrlMap.put("scheduleAtFixedRate", "http://127.0.0.1:9045/thread/testScheduleAtFixedRate"); + threadUrlMap.put("scheduleWithFixedDelay", "http://127.0.0.1:9045/thread/testScheduleWithFixedDelay"); + for (String key : threadUrlMap.keySet()) { + checkTagTransmission(threadUrlMap.get(key), EXACT_TAG_MAP, key); + } + + // 调用服务端提供的接口销毁线程池 + RequestUtils.get("http://127.0.0.1:9045/thread/shutdown", new HashMap<>()); + } + + /** + * 测试rocketmq消息中间件透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "ROCKETMQ") + public void testRocketmq() throws InterruptedException { + // 发送消息之前进行一次校验,防止误用之前的流量标签 + Optional checkTagOptional = RequestUtils.get("http://127.0.0.1:9056/rocketMqConsumer/queryRocketMqTag", EXACT_TAG_MAP); + if (checkTagOptional.isPresent() && !checkTagOptional.get().equals("")) { + Assertions.assertTrue(false, "invalid tag for rocketmq"); + } + + // 生产消息 + RequestUtils.get("http://127.0.0.1:9057/rocketMqProducer/testRocketMqProducer", EXACT_TAG_MAP); + + // sleep50秒,等待消费者消费 + Thread.sleep(50000); + checkTagTransmission("http://127.0.0.1:9056/rocketMqConsumer/queryRocketMqTag", EXACT_TAG_MAP, "rocketmq"); + } + + /** + * 测试kafka消息中间件透传流量标签 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "KAFKA") + public void testKafka() throws InterruptedException { + // 发送消息之前进行一次校验,防止误用之前的流量标签 + Optional checkTagOptional = RequestUtils.get("http://127.0.0.1:9053/kafkaConsumer/queryKafkaTag", EXACT_TAG_MAP); + if (checkTagOptional.isPresent() && !checkTagOptional.get().equals("")) { + Assertions.assertTrue(false, "invalid tag for kafka"); + } + + // 生产消息 + RequestUtils.get("http://127.0.0.1:9054/kafkaProducer/testKafkaProducer", EXACT_TAG_MAP); + + // sleep五秒,等待消费者消费 + Thread.sleep(5000); + checkTagTransmission("http://127.0.0.1:9053/kafkaConsumer/queryKafkaTag", EXACT_TAG_MAP, "kafka", "id"); + } + + /** + * 测试流量标签前缀匹配、后缀匹配和动态配置,调用tomcat-demo模块的接口完成测试 + */ + @Test + @EnabledIfSystemProperty(named = "tag.transmission.integration.test.type", matches = "CONFIG") + public void testConfig() throws Exception { + // 测试 流量标签前缀匹配 + Map prefixTagMap = new HashMap<>(); + prefixTagMap.put("x-sermant-test", "tag-test-prefix"); + checkTagTransmission("http://127.0.0.1:9052/tomcat/testConfig", prefixTagMap, "prefix", "x-sermant-test"); + + // 测试 流量标签后缀匹配 + Map suffixTagMap = new HashMap<>(); + suffixTagMap.put("tag-sermant", "tag-test-suffix"); + checkTagTransmission("http://127.0.0.1:9052/tomcat/testConfig", suffixTagMap, "suffix", "tag-sermant"); + + // 动态配置 + CuratorFramework curator = CuratorFrameworkFactory.newClient("127.0.0.1:2181", + new ExponentialBackoffRetry(1000, 3)); + curator.start(); + String nodePath = "/sermant/tag-transmission-plugin/tag-config"; + String lineSeparator = System.getProperty("line.separator"); + String oldNodeValue = "enabled: true" + lineSeparator + + "matchRule:" + lineSeparator + + " exact: [\"id\", \"name\"]" + lineSeparator + + " prefix: [\"x-sermant-\"]" + lineSeparator + + " suffix: [\"-sermant\"]"; + String newNodeValue = "enabled: true" + lineSeparator + + "matchRule:" + lineSeparator + + " exact: [\"dynamic\", \"name\"]"; + + Stat stat = curator.checkExists().forPath(nodePath); + if (stat == null) { + curator.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(nodePath, + newNodeValue.getBytes(StandardCharsets.UTF_8)); + } else { + curator.setData().forPath(nodePath, newNodeValue.getBytes(StandardCharsets.UTF_8)); + } + + // sleep三秒等待动态配置生效 + Thread.sleep(3000); + + Map dynamicTagMap = new HashMap<>(); + dynamicTagMap.put("dynamic", "tag-test-dynamic"); + Map returnDynamicTagMap = convertJson2Map( + RequestUtils.get("http://127.0.0.1:9052/tomcat/testConfig", dynamicTagMap)); + + // 切换为原来的流量标签配置 + curator.setData().forPath(nodePath, oldNodeValue.getBytes(StandardCharsets.UTF_8)); + curator.close(); + Assertions.assertEquals("tag-test-dynamic", returnDynamicTagMap.get("dynamic"), + "dynamic config transmit traffic tag failed"); + } + + private void checkTagTransmission(String url, Map tagMap, String message, String tagKey) { + Map returnTagMap = convertJson2Map(RequestUtils.get(url, + tagMap)); + Assertions.assertEquals(tagMap.get(tagKey), returnTagMap.get(tagKey), message + " transmit traffic tag failed"); + } + + private void checkTagTransmission(String url, Map tagMap, String message) { + checkTagTransmission(url, tagMap, message, "id"); + } + + private Map convertJson2Map(Optional jsonOptional) { + if (jsonOptional.isPresent()) { + return JSON.parseObject(jsonOptional.get(), Map.class); + } + return new HashMap<>(); + } +} \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/src/test/java/com/huaweicloud/demo/tagtransmission/integration/utils/RequestUtils.java b/sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/src/test/java/com/huaweicloud/demo/tagtransmission/integration/utils/RequestUtils.java new file mode 100644 index 0000000000..67015bb96b --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/tag-transmission-integration-test/src/test/java/com/huaweicloud/demo/tagtransmission/integration/utils/RequestUtils.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.huaweicloud.demo.tagtransmission.integration.utils; + +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Map; +import java.util.Optional; + +/** + * 请求工具类 + * + * @author daizhenyu + * @since 2023-10-16 + */ +public class RequestUtils { + private static final Logger LOGGER = LoggerFactory.getLogger(RequestUtils.class); + + private RequestUtils() { + } + + /** + * httpclient get方法 + * + * @param url 请求地址 + * @param headers 需要添加的header + * @return Optional 包含response的optional + */ + public static Optional get(String url, Map headers) { + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + HttpGet httpGet = new HttpGet(url); + for (String key : headers.keySet()) { + httpGet.addHeader(key, headers.get(key)); + } + try (CloseableHttpResponse response = httpClient.execute(httpGet)) { + if (response.getStatusLine().getStatusCode() == 200) { + return Optional.ofNullable(EntityUtils.toString(response.getEntity())); + } else { + LOGGER.error("Request error, the message is: {}", EntityUtils.toString(response.getEntity())); + return Optional.empty(); + } + } + } catch (IOException e) { + LOGGER.error("Request exception, the message is: {}", e.getMessage()); + return Optional.empty(); + } + } +}