Release v2.2.0-beta5

This commit is contained in:
hongqiaowei
2021-06-28 17:01:56 +08:00
parent 384d3efb0d
commit 1e1b023ed5
11 changed files with 36 additions and 28 deletions

View File

@@ -12,7 +12,7 @@
<groupId>com.fizzgate</groupId>
<artifactId>fizz-bootstrap</artifactId>
<version>2.2.0-beta4</version>
<version>2.2.0-beta5</version>
<properties>
<java.version>1.8</java.version>

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>fizz-gateway-community</artifactId>
<groupId>com.fizzgate</groupId>
<version>2.2.0-beta4</version>
<version>2.2.0-beta5</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -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';

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>fizz-gateway-community</artifactId>
<groupId>com.fizzgate</groupId>
<version>2.2.0-beta4</version>
<version>2.2.0-beta5</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -165,7 +165,7 @@ public class FlowControlFilter extends FizzWebFilter {
private List<ResourceConfig> 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<ResourceConfig> 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) {

View File

@@ -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 {

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>fizz-gateway-community</artifactId>
<groupId>com.fizzgate</groupId>
<version>2.2.0-beta4</version>
<version>2.2.0-beta5</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>fizz-gateway-community</artifactId>
<groupId>com.fizzgate</groupId>
<version>2.2.0-beta4</version>
<version>2.2.0-beta5</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -31,7 +31,7 @@
<artifactId>fizz-gateway-community</artifactId>
<name>${project.artifactId}</name>
<description>fizz gateway community</description>
<version>2.2.0-beta4</version>
<version>2.2.0-beta5</version>
<packaging>pom</packaging>
<modules>
<module>fizz-common</module>