Skip to content

Commit

Permalink
feat: restore circuitbreaker fallback & ratelimit add custom response (
Browse files Browse the repository at this point in the history
…#120)

* 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
  • Loading branch information
andrewshan authored Aug 15, 2024
1 parent 3c8c88a commit 54fc56d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 32 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ source/python/dist
source/rust/polaris-specification/target
venv
debug/
target/
target/
# Maven ignore
.flattened-pom.xml
19 changes: 18 additions & 1 deletion api/v1/fault_tolerance/circuitbreaker.proto
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ message CircuitBreakerRule {
// priority rules priority
uint32 priority = 30 [ json_name = "priority" ];
// 熔断规则标签数据
map<string, string> metadata = 31;
map<string, string> metadata = 31 [ json_name = "metadata" ];
}

// the condition to judge an input invocation as an error
Expand Down Expand Up @@ -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;
}
17 changes: 0 additions & 17 deletions api/v1/model/model.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
14 changes: 6 additions & 8 deletions api/v1/traffic_manage/lossless.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, MatchString> 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<string, string> metadata = 10;
map<string, string> metadata = 9 [ json_name = "metadata" ];
}

message LosslessOnline {
Expand Down
9 changes: 7 additions & 2 deletions api/v1/traffic_manage/ratelimit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> metadata = 29;
map<string, string> metadata = 29 [ json_name = "metadata" ];
}

message MatchArgument {
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions source/java/build-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
mvn clean install
mv pom.xml.bak pom.xml
popd

rm -rf ${java_source_dir}/proto

2 changes: 1 addition & 1 deletion source/java/polaris-specification-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</modules>

<properties>
<revision>2.0.0.0-SNAPSHOT</revision>
<revision>##VERSION##</revision>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down

0 comments on commit 54fc56d

Please sign in to comment.