Release v2.2.0-beta5
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
<groupId>com.fizzgate</groupId>
|
<groupId>com.fizzgate</groupId>
|
||||||
<artifactId>fizz-bootstrap</artifactId>
|
<artifactId>fizz-bootstrap</artifactId>
|
||||||
<version>2.2.0-beta4</version>
|
<version>2.2.0-beta5</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>fizz-gateway-community</artifactId>
|
<artifactId>fizz-gateway-community</artifactId>
|
||||||
<groupId>com.fizzgate</groupId>
|
<groupId>com.fizzgate</groupId>
|
||||||
<version>2.2.0-beta4</version>
|
<version>2.2.0-beta5</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public final class Constants {
|
|||||||
public static final char RIGHT_SQUARE_BRACKET = ']';
|
public static final char RIGHT_SQUARE_BRACKET = ']';
|
||||||
public static final char LEFT_BRACE = '{';
|
public static final char LEFT_BRACE = '{';
|
||||||
public static final char RIGHT_BRACE = '}';
|
public static final char RIGHT_BRACE = '}';
|
||||||
|
public static final char SQUARE = '^';
|
||||||
|
|
||||||
public static final char LF = '\n';
|
public static final char LF = '\n';
|
||||||
public static final char TAB = '\t';
|
public static final char TAB = '\t';
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>fizz-gateway-community</artifactId>
|
<artifactId>fizz-gateway-community</artifactId>
|
||||||
<groupId>com.fizzgate</groupId>
|
<groupId>com.fizzgate</groupId>
|
||||||
<version>2.2.0-beta4</version>
|
<version>2.2.0-beta5</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ public class FlowControlFilter extends FizzWebFilter {
|
|||||||
|
|
||||||
private List<ResourceConfig> getFlowControlConfigs(String app, String ip, String node, String service, String path) {
|
private List<ResourceConfig> getFlowControlConfigs(String app, String ip, String node, String service, String path) {
|
||||||
if (log.isDebugEnabled()) {
|
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);
|
List<ResourceConfig> resourceConfigs = new ArrayList<>(9);
|
||||||
StringBuilder b = ThreadContext.getStringBuilder();
|
StringBuilder b = ThreadContext.getStringBuilder();
|
||||||
@@ -240,7 +240,7 @@ public class FlowControlFilter extends FizzWebFilter {
|
|||||||
prev = resourceConfigs.get(sz - 1).getResourceId();
|
prev = resourceConfigs.get(sz - 1).getResourceId();
|
||||||
prevPrev = resourceConfigs.get(sz - 2).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);
|
String app = ResourceRateLimitConfig.getApp(prev);
|
||||||
if (app == null) {
|
if (app == null) {
|
||||||
something4(resourceConfigs, rateLimitConfig.app, null, 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);
|
String ip = ResourceRateLimitConfig.getIp(prev);
|
||||||
if (ip == null) {
|
if (ip == null) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package we.stats.ratelimit;
|
package we.stats.ratelimit;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import we.util.Constants;
|
import we.util.Constants;
|
||||||
import we.util.JacksonUtils;
|
import we.util.JacksonUtils;
|
||||||
import we.util.Utils;
|
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;
|
private String resourceId = null;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public String getResourceId() {
|
public String getResourceId() {
|
||||||
if (resourceId == null) {
|
if (resourceId == null) {
|
||||||
resourceId =
|
resourceId =
|
||||||
(app == null ? "" : app) + '@' +
|
(app == null ? "" : app) + '^' +
|
||||||
(ip == null ? "" : ip) + '@' +
|
(ip == null ? "" : ip) + '^' +
|
||||||
(node == null ? "" : node) + '@' +
|
(node == null ? "" : node) + '^' +
|
||||||
(service == null ? "" : service) + '@' +
|
(service == null ? "" : service) + '^' +
|
||||||
(path == null ? "" : path)
|
(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) {
|
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(app == null ? Constants.Symbol.EMPTY : app) .append(Constants.Symbol.SQUARE);
|
||||||
b.append(ip == null ? Constants.Symbol.EMPTY : ip) .append(Constants.Symbol.AT);
|
b.append(ip == null ? Constants.Symbol.EMPTY : ip) .append(Constants.Symbol.SQUARE);
|
||||||
b.append(node == null ? Constants.Symbol.EMPTY : node) .append(Constants.Symbol.AT);
|
b.append(node == null ? Constants.Symbol.EMPTY : node) .append(Constants.Symbol.SQUARE);
|
||||||
b.append(service == null ? Constants.Symbol.EMPTY : service) .append(Constants.Symbol.AT);
|
b.append(service == null ? Constants.Symbol.EMPTY : service) .append(Constants.Symbol.SQUARE);
|
||||||
b.append(path == null ? Constants.Symbol.EMPTY : path);
|
b.append(path == null ? Constants.Symbol.EMPTY : path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getApp(String resource) {
|
public static String getApp(String resource) {
|
||||||
int i = resource.indexOf(Constants.Symbol.AT);
|
int i = resource.indexOf(Constants.Symbol.SQUARE);
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
@@ -154,7 +161,7 @@ public class ResourceRateLimitConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getIp(String resource) {
|
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)) {
|
if (extract.equals(Constants.Symbol.EMPTY)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -162,7 +169,7 @@ public class ResourceRateLimitConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getNode(String resource) {
|
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)) {
|
if (extract.equals(Constants.Symbol.EMPTY)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -170,7 +177,7 @@ public class ResourceRateLimitConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getService(String resource) {
|
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)) {
|
if (extract.equals(Constants.Symbol.EMPTY)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -178,7 +185,7 @@ public class ResourceRateLimitConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getPath(String resource) {
|
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) {
|
if (i == resource.length() - 1) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class ResourceRateLimitConfigServiceTests {
|
|||||||
assertEquals(resourceRateLimitConfig.concurrents, 66);
|
assertEquals(resourceRateLimitConfig.concurrents, 66);
|
||||||
// System.err.println(resourceRateLimitConfig);
|
// System.err.println(resourceRateLimitConfig);
|
||||||
// Thread.currentThread().join();
|
// Thread.currentThread().join();
|
||||||
resourceRateLimitConfig = resourceRateLimitConfigService.getResourceRateLimitConfig("xapp@@@yservice@");
|
resourceRateLimitConfig = resourceRateLimitConfigService.getResourceRateLimitConfig("xapp^^^yservice^");
|
||||||
assertEquals(resourceRateLimitConfig.concurrents, 88);
|
assertEquals(resourceRateLimitConfig.concurrents, 88);
|
||||||
|
|
||||||
Thread.sleep(4000);
|
Thread.sleep(4000);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class ResourceRateLimitConfigTests {
|
|||||||
String resourceRateLimitConfigJson = "{\"concurrents\":1000,\"enable\":1,\"id\":1,\"isDeleted\":0,\"qps\":500, \"type\":1, \"resource\":\"_global\" }";
|
String resourceRateLimitConfigJson = "{\"concurrents\":1000,\"enable\":1,\"id\":1,\"isDeleted\":0,\"qps\":500, \"type\":1, \"resource\":\"_global\" }";
|
||||||
ResourceRateLimitConfig c = JacksonUtils.readValue(resourceRateLimitConfigJson, ResourceRateLimitConfig.class);
|
ResourceRateLimitConfig c = JacksonUtils.readValue(resourceRateLimitConfigJson, ResourceRateLimitConfig.class);
|
||||||
String resourceId = c.getResourceId();
|
String resourceId = c.getResourceId();
|
||||||
assertEquals("@@_global@@", resourceId);
|
assertEquals("^^_global^^", resourceId);
|
||||||
|
|
||||||
String node = ResourceRateLimitConfig.getNode(resourceId);
|
String node = ResourceRateLimitConfig.getNode(resourceId);
|
||||||
assertEquals("_global", node);
|
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\" }";
|
resourceRateLimitConfigJson = "{\"concurrents\":1000,\"enable\":1,\"id\":1,\"isDeleted\":0,\"qps\":500, \"type\":2, \"resource\":\"service_default\" }";
|
||||||
c = JacksonUtils.readValue(resourceRateLimitConfigJson, ResourceRateLimitConfig.class);
|
c = JacksonUtils.readValue(resourceRateLimitConfigJson, ResourceRateLimitConfig.class);
|
||||||
resourceId = c.getResourceId();
|
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\" }";
|
resourceRateLimitConfigJson = "{\"concurrents\":1000,\"enable\":1,\"id\":1,\"isDeleted\":0,\"qps\":500, \"type\":3, \"resource\":\"xservice\" }";
|
||||||
c = JacksonUtils.readValue(resourceRateLimitConfigJson, ResourceRateLimitConfig.class);
|
c = JacksonUtils.readValue(resourceRateLimitConfigJson, ResourceRateLimitConfig.class);
|
||||||
resourceId = c.getResourceId();
|
resourceId = c.getResourceId();
|
||||||
assertEquals("@@@xservice@", resourceId);
|
assertEquals("^^^xservice^", resourceId);
|
||||||
|
|
||||||
resourceId = ResourceRateLimitConfig.buildResourceId(null, null, ResourceRateLimitConfig.NODE, null, null);
|
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);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>fizz-gateway-community</artifactId>
|
<artifactId>fizz-gateway-community</artifactId>
|
||||||
<groupId>com.fizzgate</groupId>
|
<groupId>com.fizzgate</groupId>
|
||||||
<version>2.2.0-beta4</version>
|
<version>2.2.0-beta5</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>fizz-gateway-community</artifactId>
|
<artifactId>fizz-gateway-community</artifactId>
|
||||||
<groupId>com.fizzgate</groupId>
|
<groupId>com.fizzgate</groupId>
|
||||||
<version>2.2.0-beta4</version>
|
<version>2.2.0-beta5</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -31,7 +31,7 @@
|
|||||||
<artifactId>fizz-gateway-community</artifactId>
|
<artifactId>fizz-gateway-community</artifactId>
|
||||||
<name>${project.artifactId}</name>
|
<name>${project.artifactId}</name>
|
||||||
<description>fizz gateway community</description>
|
<description>fizz gateway community</description>
|
||||||
<version>2.2.0-beta4</version>
|
<version>2.2.0-beta5</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
<module>fizz-common</module>
|
<module>fizz-common</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user