From 1e1b023ed5862182b1b75a1768d5fd0b27517e67 Mon Sep 17 00:00:00 2001 From: hongqiaowei Date: Mon, 28 Jun 2021 17:01:56 +0800 Subject: [PATCH] Release v2.2.0-beta5 --- fizz-bootstrap/pom.xml | 2 +- fizz-common/pom.xml | 2 +- .../src/main/java/we/util/Constants.java | 1 + fizz-core/pom.xml | 2 +- .../java/we/filter/FlowControlFilter.java | 6 ++-- .../ratelimit/ResourceRateLimitConfig.java | 33 +++++++++++-------- .../ResourceRateLimitConfigServiceTests.java | 2 +- .../ResourceRateLimitConfigTests.java | 10 +++--- fizz-plugin/pom.xml | 2 +- fizz-spring-boot-starter/pom.xml | 2 +- pom.xml | 2 +- 11 files changed, 36 insertions(+), 28 deletions(-) diff --git a/fizz-bootstrap/pom.xml b/fizz-bootstrap/pom.xml index 1fdddd3..8cc05e1 100644 --- a/fizz-bootstrap/pom.xml +++ b/fizz-bootstrap/pom.xml @@ -12,7 +12,7 @@ com.fizzgate fizz-bootstrap - 2.2.0-beta4 + 2.2.0-beta5 1.8 diff --git a/fizz-common/pom.xml b/fizz-common/pom.xml index 0f3b5cf..cba3f59 100644 --- a/fizz-common/pom.xml +++ b/fizz-common/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.2.0-beta4 + 2.2.0-beta5 ../pom.xml 4.0.0 diff --git a/fizz-common/src/main/java/we/util/Constants.java b/fizz-common/src/main/java/we/util/Constants.java index eba2a52..398e358 100644 --- a/fizz-common/src/main/java/we/util/Constants.java +++ b/fizz-common/src/main/java/we/util/Constants.java @@ -52,6 +52,7 @@ public final class Constants { public static final char RIGHT_SQUARE_BRACKET = ']'; public static final char LEFT_BRACE = '{'; public static final char RIGHT_BRACE = '}'; + public static final char SQUARE = '^'; public static final char LF = '\n'; public static final char TAB = '\t'; diff --git a/fizz-core/pom.xml b/fizz-core/pom.xml index 8d6e0d9..58fc7a7 100644 --- a/fizz-core/pom.xml +++ b/fizz-core/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.2.0-beta4 + 2.2.0-beta5 ../pom.xml 4.0.0 diff --git a/fizz-core/src/main/java/we/filter/FlowControlFilter.java b/fizz-core/src/main/java/we/filter/FlowControlFilter.java index 6cecf7a..90481e1 100644 --- a/fizz-core/src/main/java/we/filter/FlowControlFilter.java +++ b/fizz-core/src/main/java/we/filter/FlowControlFilter.java @@ -165,7 +165,7 @@ public class FlowControlFilter extends FizzWebFilter { private List getFlowControlConfigs(String app, String ip, String node, String service, String path) { if (log.isDebugEnabled()) { - log.debug("get flow control config by app={}, ip={}, node={}, service={}, path={}", app, ip, node, service, path); + log.debug("get flow control configs by app={}, ip={}, node={}, service={}, path={}", app, ip, node, service, path); } List resourceConfigs = new ArrayList<>(9); StringBuilder b = ThreadContext.getStringBuilder(); @@ -240,7 +240,7 @@ public class FlowControlFilter extends FizzWebFilter { prev = resourceConfigs.get(sz - 1).getResourceId(); prevPrev = resourceConfigs.get(sz - 2).getResourceId(); - if (rateLimitConfig.type == ResourceRateLimitConfig.Type.APP) { + if (rateLimitConfig.type == ResourceRateLimitConfig.Type.APP && rateLimitConfig.path != null) { String app = ResourceRateLimitConfig.getApp(prev); if (app == null) { something4(resourceConfigs, rateLimitConfig.app, null, null); @@ -255,7 +255,7 @@ public class FlowControlFilter extends FizzWebFilter { } } - } else if (rateLimitConfig.type == ResourceRateLimitConfig.Type.IP) { + } else if (rateLimitConfig.type == ResourceRateLimitConfig.Type.IP && rateLimitConfig.path != null) { String ip = ResourceRateLimitConfig.getIp(prev); if (ip == null) { diff --git a/fizz-core/src/main/java/we/stats/ratelimit/ResourceRateLimitConfig.java b/fizz-core/src/main/java/we/stats/ratelimit/ResourceRateLimitConfig.java index 58a499c..039b6e2 100644 --- a/fizz-core/src/main/java/we/stats/ratelimit/ResourceRateLimitConfig.java +++ b/fizz-core/src/main/java/we/stats/ratelimit/ResourceRateLimitConfig.java @@ -18,6 +18,7 @@ package we.stats.ratelimit; import com.fasterxml.jackson.annotation.JsonIgnore; +import org.apache.commons.lang3.StringUtils; import we.util.Constants; import we.util.JacksonUtils; import we.util.Utils; @@ -114,16 +115,22 @@ public class ResourceRateLimitConfig { } } + public void setPath(String p) { + if (StringUtils.isNotBlank(p)) { + path = p; + } + } + private String resourceId = null; @JsonIgnore public String getResourceId() { if (resourceId == null) { resourceId = - (app == null ? "" : app) + '@' + - (ip == null ? "" : ip) + '@' + - (node == null ? "" : node) + '@' + - (service == null ? "" : service) + '@' + + (app == null ? "" : app) + '^' + + (ip == null ? "" : ip) + '^' + + (node == null ? "" : node) + '^' + + (service == null ? "" : service) + '^' + (path == null ? "" : path) ; } @@ -137,15 +144,15 @@ public class ResourceRateLimitConfig { } public static void buildResourceIdTo(StringBuilder b, String app, String ip, String node, String service, String path) { - b.append(app == null ? Constants.Symbol.EMPTY : app) .append(Constants.Symbol.AT); - b.append(ip == null ? Constants.Symbol.EMPTY : ip) .append(Constants.Symbol.AT); - b.append(node == null ? Constants.Symbol.EMPTY : node) .append(Constants.Symbol.AT); - b.append(service == null ? Constants.Symbol.EMPTY : service) .append(Constants.Symbol.AT); + b.append(app == null ? Constants.Symbol.EMPTY : app) .append(Constants.Symbol.SQUARE); + b.append(ip == null ? Constants.Symbol.EMPTY : ip) .append(Constants.Symbol.SQUARE); + b.append(node == null ? Constants.Symbol.EMPTY : node) .append(Constants.Symbol.SQUARE); + b.append(service == null ? Constants.Symbol.EMPTY : service) .append(Constants.Symbol.SQUARE); b.append(path == null ? Constants.Symbol.EMPTY : path); } public static String getApp(String resource) { - int i = resource.indexOf(Constants.Symbol.AT); + int i = resource.indexOf(Constants.Symbol.SQUARE); if (i == 0) { return null; } else { @@ -154,7 +161,7 @@ public class ResourceRateLimitConfig { } public static String getIp(String resource) { - String extract = Utils.extract(resource, Constants.Symbol.AT, 1); + String extract = Utils.extract(resource, Constants.Symbol.SQUARE, 1); if (extract.equals(Constants.Symbol.EMPTY)) { return null; } @@ -162,7 +169,7 @@ public class ResourceRateLimitConfig { } public static String getNode(String resource) { - String extract = Utils.extract(resource, Constants.Symbol.AT, 2); + String extract = Utils.extract(resource, Constants.Symbol.SQUARE, 2); if (extract.equals(Constants.Symbol.EMPTY)) { return null; } @@ -170,7 +177,7 @@ public class ResourceRateLimitConfig { } public static String getService(String resource) { - String extract = Utils.extract(resource, Constants.Symbol.AT, 3); + String extract = Utils.extract(resource, Constants.Symbol.SQUARE, 3); if (extract.equals(Constants.Symbol.EMPTY)) { return null; } @@ -178,7 +185,7 @@ public class ResourceRateLimitConfig { } public static String getPath(String resource) { - int i = resource.lastIndexOf(Constants.Symbol.AT); + int i = resource.lastIndexOf(Constants.Symbol.SQUARE); if (i == resource.length() - 1) { return null; } else { diff --git a/fizz-core/src/test/java/we/stats/ratelimit/ResourceRateLimitConfigServiceTests.java b/fizz-core/src/test/java/we/stats/ratelimit/ResourceRateLimitConfigServiceTests.java index 8c2bce0..ae758bd 100644 --- a/fizz-core/src/test/java/we/stats/ratelimit/ResourceRateLimitConfigServiceTests.java +++ b/fizz-core/src/test/java/we/stats/ratelimit/ResourceRateLimitConfigServiceTests.java @@ -57,7 +57,7 @@ public class ResourceRateLimitConfigServiceTests { assertEquals(resourceRateLimitConfig.concurrents, 66); // System.err.println(resourceRateLimitConfig); // Thread.currentThread().join(); - resourceRateLimitConfig = resourceRateLimitConfigService.getResourceRateLimitConfig("xapp@@@yservice@"); + resourceRateLimitConfig = resourceRateLimitConfigService.getResourceRateLimitConfig("xapp^^^yservice^"); assertEquals(resourceRateLimitConfig.concurrents, 88); Thread.sleep(4000); diff --git a/fizz-core/src/test/java/we/stats/ratelimit/ResourceRateLimitConfigTests.java b/fizz-core/src/test/java/we/stats/ratelimit/ResourceRateLimitConfigTests.java index 80aaac2..2a2fab0 100644 --- a/fizz-core/src/test/java/we/stats/ratelimit/ResourceRateLimitConfigTests.java +++ b/fizz-core/src/test/java/we/stats/ratelimit/ResourceRateLimitConfigTests.java @@ -23,7 +23,7 @@ public class ResourceRateLimitConfigTests { String resourceRateLimitConfigJson = "{\"concurrents\":1000,\"enable\":1,\"id\":1,\"isDeleted\":0,\"qps\":500, \"type\":1, \"resource\":\"_global\" }"; ResourceRateLimitConfig c = JacksonUtils.readValue(resourceRateLimitConfigJson, ResourceRateLimitConfig.class); String resourceId = c.getResourceId(); - assertEquals("@@_global@@", resourceId); + assertEquals("^^_global^^", resourceId); String node = ResourceRateLimitConfig.getNode(resourceId); assertEquals("_global", node); @@ -31,17 +31,17 @@ public class ResourceRateLimitConfigTests { resourceRateLimitConfigJson = "{\"concurrents\":1000,\"enable\":1,\"id\":1,\"isDeleted\":0,\"qps\":500, \"type\":2, \"resource\":\"service_default\" }"; c = JacksonUtils.readValue(resourceRateLimitConfigJson, ResourceRateLimitConfig.class); resourceId = c.getResourceId(); - assertEquals("@@@service_default@", resourceId); + assertEquals("^^^service_default^", resourceId); resourceRateLimitConfigJson = "{\"concurrents\":1000,\"enable\":1,\"id\":1,\"isDeleted\":0,\"qps\":500, \"type\":3, \"resource\":\"xservice\" }"; c = JacksonUtils.readValue(resourceRateLimitConfigJson, ResourceRateLimitConfig.class); resourceId = c.getResourceId(); - assertEquals("@@@xservice@", resourceId); + assertEquals("^^^xservice^", resourceId); resourceId = ResourceRateLimitConfig.buildResourceId(null, null, ResourceRateLimitConfig.NODE, null, null); - assertEquals("@@_global@@", resourceId); + assertEquals("^^_global^^", resourceId); resourceId = ResourceRateLimitConfig.buildResourceId(null, "192.168.1.1", null, "xservice", null); - assertEquals("@192.168.1.1@@xservice@", resourceId); + assertEquals("^192.168.1.1^^xservice^", resourceId); } } diff --git a/fizz-plugin/pom.xml b/fizz-plugin/pom.xml index 6ee10a4..8591649 100644 --- a/fizz-plugin/pom.xml +++ b/fizz-plugin/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.2.0-beta4 + 2.2.0-beta5 ../pom.xml 4.0.0 diff --git a/fizz-spring-boot-starter/pom.xml b/fizz-spring-boot-starter/pom.xml index 3045428..f9860b0 100644 --- a/fizz-spring-boot-starter/pom.xml +++ b/fizz-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.2.0-beta4 + 2.2.0-beta5 ../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 8f2926e..10f503a 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ fizz-gateway-community ${project.artifactId} fizz gateway community - 2.2.0-beta4 + 2.2.0-beta5 pom fizz-common