Skip to content

Commit

Permalink
support dubbo3.x rateLimiting/circuitBreaker
Browse files Browse the repository at this point in the history
Signed-off-by: chengyouling <[email protected]>
  • Loading branch information
chengyouling committed Feb 25, 2025
1 parent f682ee5 commit 52bf9aa
Show file tree
Hide file tree
Showing 9 changed files with 614 additions and 6 deletions.
15 changes: 15 additions & 0 deletions .github/actions/common/plugin-change-check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,14 @@ runs:
id: changed-dubbo-common-action
with:
paths: ./.github/actions/scenarios/dubbo/dubbo-common ./.github/actions/common/dubbo ./.github/workflows/dubbo_integration_test.yml
- uses: ktamas77/[email protected]
id: changed-dubbo3-flow-action
with:
paths: ./.github/actions/scenarios/dubbo/flow-dubbo3 ./.github/actions/common/dubbo ./.github/workflows/dubbo_integration_test.yml
- name: env dubbo3-flow-action
shell: bash
run: |
echo "enableDubbo3FlowActionChange=${{ steps.changed-dubbo3-flow-action.outputs.changed }}" >> $GITHUB_ENV
- name: env dubbo-router-action
shell: bash
run: |
Expand Down Expand Up @@ -678,6 +686,13 @@ runs:
echo "enableDubboLane=true" >> $GITHUB_ENV
echo "enableDubbo3Lane=true" >> $GITHUB_ENV
fi
# ==========dubbo3 flow is needed to test?==========
if [ ${{ env.sermantAgentCoreChanged }} == 'true' -o \
${{ env.enableDubbo3FlowActionChange }} == 'true' -o \
${{ steps.changed-common-action.outputs.changed }} == 'true' -o ${{ env.triggerPushEvent }} == 'true' -o \
${{ env.enableDubboTestChange }} == 'true' ];then
echo "enableDubbo3Flow=true" >> $GITHUB_ENV
fi
# *****************spring_integration_test_1.yml*****************
# ==========graceful is needed to test?==========
Expand Down
78 changes: 78 additions & 0 deletions .github/actions/scenarios/dubbo/dubbo3-flow/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: "Dubbo3 Flow Test"
description: "Auto test for dubbo3 flow"
runs:
using: "composite"
steps:
- name: entry
uses: ./.github/actions/common/entry
with:
log-dir: ./logs/dubbo3-flow
- name: add load rule.yaml configuration for dubbo3 flow test
shell: bash
run: |
mv -f sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/io/sermant/integration/ProviderApplication.java sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/io/sermant/integration/ProviderApplication.java.banck
mv -f sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/io/sermant/integration/Dubbo3ProviderApplication.java.banck sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/io/sermant/integration/Dubbo3ProviderApplication.java
- name: package dubbo 3.0.x tests
shell: bash
if: matrix.dubbo-version == '3-0'
run: mvn package -Ddubbo.version=3.0.${{ matrix.dubbo-versions }} -DskipTests --file sermant-integration-tests/dubbo-test/pom.xml
- name: package dubbo 3.1.x tests
shell: bash
if: matrix.dubbo-version == '3-1'
run: mvn package -Ddubbo.version=3.1.${{ matrix.dubbo-versions }} -DskipTests --file sermant-integration-tests/dubbo-test/pom.xml
- name: package dubbo 3.2.x tests
shell: bash
if: matrix.dubbo-version == '3-2'
run: mvn package -Ddubbo.version=3.2.${{ matrix.dubbo-versions }} -DskipTests --file sermant-integration-tests/dubbo-test/pom.xml
- name: start provider service
shell: bash
env:
SERVER_PORT: 28022
DUBBO_PROTOCOL_PORT: 28822
run: |
nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=dubbo-integration-provider -jar \
sermant-integration-tests/dubbo-test/dubbo-${{ env.projectPath }}-integration-provider/target/dubbo-integration-provider.jar > ${{ env.logDir }}/dubbo-provider.log 2>&1 &
- name: waiting for providers start
shell: bash
run: |
bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:28022/actuator/health 120
- name: start consumer service
shell: bash
env:
SERVER_PORT: 28020
DUBBO_PROTOCOL_PORT: 28820
run: |
nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar=appName=dubbo-integration-consumer -jar \
sermant-integration-tests/dubbo-test/dubbo-${{ env.projectPath }}-integration-consumer/target/dubbo-integration-consumer.jar > ${{ env.logDir }}/dubbo-consumer.log 2>&1 &
- name: waiting for consumers start
shell: bash
run: |
bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:28020/actuator/health 120
- name: integration test
shell: bash
env:
TEST_TYPE: dubbo3-flow
run: mvn test --file sermant-integration-tests/dubbo-test/pom.xml
- name: reset Application file
shell: bash
run: |
mv -f sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/io/sermant/integration/ProviderApplication.java.banck sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/io/sermant/integration/ProviderApplication.java
mv -f sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/io/sermant/integration/Dubbo3ProviderApplication.java sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/io/sermant/integration/Dubbo3ProviderApplication.java.banck
- name: mvn clean
shell: bash
run: mvn clean --file sermant-integration-tests/dubbo-test/pom.xml
- name: exit
if: always()
uses: ./.github/actions/common/exit
with:
processor-keyword: dubbo
- name: if failure then upload error log
uses: actions/upload-artifact@v4
if: ${{ failure() || cancelled() }}
with:
name: (test-for-dubbo3-flow)-(${{ matrix.dubbo-version }}-${{ matrix.dubbo-versions }})-logs
path: |
./*.log
./logs/**/*.log
if-no-files-found: warn
retention-days: 2
7 changes: 6 additions & 1 deletion .github/workflows/dubbo_integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
echo "enableDubboRemoval=${{env.enableDubboRemoval}}" >> $GITHUB_OUTPUT
echo "enableDubbo3Router=${{env.enableDubbo3Router}}" >> $GITHUB_OUTPUT
echo "enableDubbo3Lane=${{env.enableDubbo3Lane}}" >> $GITHUB_OUTPUT
echo "enableDubbo3Flow=${{env.enableDubbo3Flow}}" >> $GITHUB_OUTPUT
outputs:
enableDubboRouter: ${{ steps.set-outputs.outputs.enableDubboRouter }}
enableDubboMonitor: ${{ steps.set-outputs.outputs.enableDubboMonitor }}
Expand All @@ -57,6 +58,7 @@ jobs:
enableDubboRemoval: ${{ steps.set-outputs.outputs.enableDubboRemoval }}
enableDubbo3Router: ${{ steps.set-outputs.outputs.enableDubbo3Router }}
enableDubbo3Lane: ${{ steps.set-outputs.outputs.enableDubbo3Lane }}
enableDubbo3Flow: ${{ steps.set-outputs.outputs.enableDubbo3Flow }}
download-midwares-and-cache:
name: download and cache middlewares
runs-on: ubuntu-latest
Expand Down Expand Up @@ -152,7 +154,7 @@ jobs:
uses: ./.github/actions/scenarios/dubbo/removal
test-for-dubbo3:
name: Test for dubbo3.x
if: needs.set-execution-conditions.outputs.enableDubbo3Router == 'true' || needs.set-execution-conditions.outputs.enableDubbo3Lane == 'true'
if: needs.set-execution-conditions.outputs.enableDubbo3Router == 'true' || needs.set-execution-conditions.outputs.enableDubbo3Lane == 'true' || needs.set-execution-conditions.outputs.enableDubbo3Flow == 'true'
runs-on: ubuntu-latest
needs: [set-execution-conditions, download-midwares-and-cache, build-agent-and-cache ]
strategy:
Expand Down Expand Up @@ -241,3 +243,6 @@ jobs:
- name: (dubbo3.x lane) test for ${{ matrix.dubbo-version }}-${{ matrix.dubbo-versions }}
if: needs.set-execution-conditions.outputs.enableDubbo3Lane == 'true'
uses: ./.github/actions/scenarios/dubbo/lane-dubbo3
- name: (dubbo3.x flow) test for ${{ matrix.dubbo-version }}-${{ matrix.dubbo-versions }}
if: needs.set-execution-conditions.outputs.enableDubbo3Flow == 'true'
uses: ./.github/actions/scenarios/dubbo/dubbo3-flow
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

Expand Down Expand Up @@ -55,7 +57,9 @@ public String rateLimitingWithHeader(@RequestParam(name = "key") String key, @Re
try {
RpcContext.getContext().setAttachment(key, value);
RpcContext.getContext().setAttachment(key2, value2);
return flowControlService.rateLimitingWithHeader(Collections.singletonMap(key, value));
Map<String, Object> attachments = new HashMap<>();
attachments.put(key, value);
return flowControlService.rateLimitingWithHeader(attachments);
} finally {
RpcContext.getContext().remove(key);
RpcContext.getContext().remove(key2);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2025-2025 Sermant Authors. 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 io.sermant.integration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;

import io.sermant.integration.configuration.FlowRuleConfiguration;
import io.sermant.integration.controller.ConsumerController;
import io.sermant.integration.controller.FlowController;

/**
* starter
*
* @author chengyouling
* @since 2025-042-25
*/
@SpringBootApplication
@ImportResource({"classpath:dubbo/provider.xml"})
@Import({FlowRuleConfiguration.class})
@ComponentScan(excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, value = {ConsumerController.class,
FlowController.class}))
public class Dubbo3ProviderApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(Dubbo3ProviderApplication.class);

/**
* spring starter
*
* @param args args
*/
public static void main(String[] args) {
LOGGER.info("====================start=======================");
SpringApplication.run(Dubbo3ProviderApplication.class);
LOGGER.info("=====================end========================");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*

Check failure on line 1 in sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/io/sermant/integration/configuration/FlowControlExceptionHandler.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 请检查版权声明中其实年份与@SInCE中年份是否一致 Raw Output: /home/runner/work/Sermant/Sermant/./sermant-integration-tests/dubbo-test/dubbo-2-7-integration-provider/src/main/java/io/sermant/integration/configuration/FlowControlExceptionHandler.java:1:0: error: 请检查版权声明中其实年份与@SInCE中年份是否一致 (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpMultilineCheck)
* Copyright (C) 2024-2024 Sermant Authors. 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 io.sermant.integration.configuration;

import io.sermant.integration.controller.FlowController;

import org.apache.dubbo.rpc.RpcException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
* global flow control exception handling
*
* @author chengyouling
* @since 2025-02-22
*/
@ControllerAdvice(assignableTypes = {FlowController.class})
public class FlowControlExceptionHandler {
/**
* 异常处理
*
* @param exception 异常
* @return 异常结果
*/
@ExceptionHandler(RpcException.class)
public ResponseEntity<String> handleError(RpcException exception) {
return new ResponseEntity<>(exception.getMessage(), HttpStatus.OK);
}
}
Loading

0 comments on commit 52bf9aa

Please sign in to comment.