From 54fc56dbc55dfb50612e646084211c4cc71aaa48 Mon Sep 17 00:00:00 2001 From: andrew shan <45474304+andrewshan@users.noreply.github.com> Date: Thu, 15 Aug 2024 15:02:58 +0800 Subject: [PATCH] feat: restore circuitbreaker fallback & ratelimit add custom response (#120) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add ratelimit spec & remove temporary proto files * Update version to 1.5.3-SNAPSHOT * fix: change maxAmount to max_amount * feat: add lossless rule specification * feat: lossless支持lables过滤 * feat: restore circuitbreaker fallback & ratelimit add custom response * fix: add json_name * fix: customResponse to custom_response --- .gitignore | 4 +++- api/v1/fault_tolerance/circuitbreaker.proto | 19 ++++++++++++++++++- api/v1/model/model.proto | 17 ----------------- api/v1/traffic_manage/lossless.proto | 14 ++++++-------- api/v1/traffic_manage/ratelimit.proto | 9 +++++++-- source/java/build-mac.sh | 12 ++++++++++-- .../java/polaris-specification-test/pom.xml | 2 +- 7 files changed, 45 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 741d6ed0..3983cd57 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ source/python/dist source/rust/polaris-specification/target venv debug/ -target/ \ No newline at end of file +target/ +# Maven ignore +.flattened-pom.xml \ No newline at end of file diff --git a/api/v1/fault_tolerance/circuitbreaker.proto b/api/v1/fault_tolerance/circuitbreaker.proto index b1d23bdc..4852142e 100644 --- a/api/v1/fault_tolerance/circuitbreaker.proto +++ b/api/v1/fault_tolerance/circuitbreaker.proto @@ -286,7 +286,7 @@ message CircuitBreakerRule { // priority rules priority uint32 priority = 30 [ json_name = "priority" ]; // 熔断规则标签数据 - map metadata = 31; + map metadata = 31 [ json_name = "metadata" ]; } // the condition to judge an input invocation as an error @@ -336,4 +336,21 @@ message BlockConfig { repeated ErrorCondition error_conditions = 3 [ json_name = "error_conditions" ]; // trigger condition to trigger circuitbreaking repeated TriggerCondition trigger_conditions = 4 [ json_name = "trigger_conditions" ]; +} + +// fallback config +message FallbackConfig { + bool enable = 1; + FallbackResponse response = 2; +} + +// fallback response +message FallbackResponse { + int32 code = 1; + message MessageHeader { + string key = 1; + string value = 2; + } + repeated MessageHeader headers = 2; + string body = 3; } \ No newline at end of file diff --git a/api/v1/model/model.proto b/api/v1/model/model.proto index d31ab786..b24d8547 100644 --- a/api/v1/model/model.proto +++ b/api/v1/model/model.proto @@ -68,21 +68,4 @@ message API { string method = 2 [ json_name = "method" ]; // API的路径,支持多种匹配方式 MatchString path = 3 [ json_name = "path" ]; -} - -// fallback config -message FallbackConfig { - bool enable = 1; - FallbackResponse response = 2; -} - -// fallback response -message FallbackResponse { - int32 code = 1; - message MessageHeader { - string key = 1; - string value = 2; - } - repeated MessageHeader headers = 2; - string body = 3; } \ No newline at end of file diff --git a/api/v1/traffic_manage/lossless.proto b/api/v1/traffic_manage/lossless.proto index 92d793e0..624c10b7 100644 --- a/api/v1/traffic_manage/lossless.proto +++ b/api/v1/traffic_manage/lossless.proto @@ -18,20 +18,18 @@ message LosslessRule { string service = 2 [ json_name = "service" ]; // namespace for rule belongs to string namespace = 3 [ json_name = "namespace" ]; - // match rules by labels - map labels = 4 [ json_name = "labels" ]; // revision routing version - string revision = 5 [ json_name = "revision" ]; + string revision = 4 [ json_name = "revision" ]; // ctime create time of the rules - string ctime = 6 [ json_name = "ctime" ]; + string ctime = 5 [ json_name = "ctime" ]; // mtime modify time of the rules - string mtime = 7 [ json_name = "mtime" ]; + string mtime = 6 [ json_name = "mtime" ]; // configuration for lossless online - LosslessOnline losslessOnline = 8 [ json_name = "lossless_online" ]; + LosslessOnline losslessOnline = 7 [ json_name = "lossless_online" ]; // configuration for lossless offline - LosslessOffline losslessOffline = 9 [ json_name = "lossless_offline" ]; + LosslessOffline losslessOffline = 8 [ json_name = "lossless_offline" ]; // rule labels - map metadata = 10; + map metadata = 9 [ json_name = "metadata" ]; } message LosslessOnline { diff --git a/api/v1/traffic_manage/ratelimit.proto b/api/v1/traffic_manage/ratelimit.proto index bc83cadc..8ac3bd9e 100644 --- a/api/v1/traffic_manage/ratelimit.proto +++ b/api/v1/traffic_manage/ratelimit.proto @@ -97,9 +97,9 @@ message Rule { // amount for concurrency rate-limit ConcurrencyAmount concurrencyAmount = 27 [ json_name = "concurrency_amount" ]; // fallback configuration - FallbackConfig fallbackConfig = 28 [ json_name = "fallback_config" ]; + CustomResponse customResponse = 28 [ json_name = "custom_response" ]; // 限流规则标签数据 - map metadata = 29; + map metadata = 29 [ json_name = "metadata" ]; } message MatchArgument { @@ -132,6 +132,11 @@ message ConcurrencyAmount { uint32 maxAmount = 1 [ json_name = "max_amount" ]; } +// custom response text when limited +message CustomResponse { + string body = 3 [ json_name = "body" ]; +} + // 分布式限流服务集群 message RateLimitCluster { google.protobuf.StringValue service = 1; diff --git a/source/java/build-mac.sh b/source/java/build-mac.sh index b5495c96..e883d739 100644 --- a/source/java/build-mac.sh +++ b/source/java/build-mac.sh @@ -26,7 +26,6 @@ traffic_manage_dir=${workdir}/api/v1/traffic_manage fault_tolerance_dir=${workdir}/api/v1/fault_tolerance config_manage_dir=${workdir}/api/v1/config_manage security_dir=${workdir}/api/v1/security - java_root_dir=${workdir}/source/java/polaris-specification java_test_root_dir=${workdir}/source/java/polaris-specification-test java_source_dir=${java_root_dir}/src/main @@ -45,8 +44,17 @@ cp ${traffic_manage_dir}/ratelimiter/*.proto ${java_source_dir}/proto/ version=`cat ${workdir}/VERSION` echo $version pushd ${java_root_dir} +cp pom.xml pom.xml.bak sed -i "" "s/##VERSION##/${version}/g" pom.xml +mvn clean install +mv pom.xml.bak pom.xml popd pushd ${java_test_root_dir} +cp pom.xml pom.xml.bak sed -i "" "s/##VERSION##/${version}/g" pom.xml -popd \ No newline at end of file +mvn clean install +mv pom.xml.bak pom.xml +popd + +rm -rf ${java_source_dir}/proto + diff --git a/source/java/polaris-specification-test/pom.xml b/source/java/polaris-specification-test/pom.xml index 37e5159e..4642814e 100644 --- a/source/java/polaris-specification-test/pom.xml +++ b/source/java/polaris-specification-test/pom.xml @@ -14,7 +14,7 @@ - 2.0.0.0-SNAPSHOT + ##VERSION## 8 8 UTF-8