Merge pull request #482 from fizzgate/feature/v2.7.3

Feature/v2.7.3
This commit is contained in:
dxfeng10
2023-07-01 23:52:53 +08:00
committed by GitHub
9 changed files with 24 additions and 23 deletions

View File

@@ -85,6 +85,7 @@ jobs:
push: true push: true
tags: fizzgate/fizz-gateway-community:${{ steps.releaseVersion.outputs.substring }} tags: fizzgate/fizz-gateway-community:${{ steps.releaseVersion.outputs.substring }}
- name: Publish to Apache Maven Central - name: Publish to Apache Maven Central
run: mvn -X -e deploy
if: startsWith(github.ref, 'refs/tags/') if: startsWith(github.ref, 'refs/tags/')
uses: samuelmeuli/action-maven-publish@v1 uses: samuelmeuli/action-maven-publish@v1
with: with:

View File

@@ -93,7 +93,7 @@ flow-stat-sched:
queue: fizz_resource_access_stat queue: fizz_resource_access_stat
gateway: gateway:
prefix: /proxy prefix: /
aggr: aggr:
# set headers when calling the backend API # set headers when calling the backend API
proxy_set_headers: X-Real-IP,X-Forwarded-Proto,X-Forwarded-For proxy_set_headers: X-Real-IP,X-Forwarded-Proto,X-Forwarded-For

View File

@@ -52,7 +52,6 @@ import com.fizzgate.util.Consts;
import com.fizzgate.util.NettyDataBufferUtils; import com.fizzgate.util.NettyDataBufferUtils;
import com.fizzgate.util.ThreadContext; import com.fizzgate.util.ThreadContext;
import com.fizzgate.util.WebUtils; import com.fizzgate.util.WebUtils;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
/** /**

View File

@@ -360,7 +360,7 @@ public class FlowControlFilter extends FizzWebFilter {
if (hasHost) { if (hasHost) {
// String resourceId = ResourceIdUtils.buildResourceId(app, ip, node, service, path); // String resourceId = ResourceIdUtils.buildResourceId(app, ip, node, service, path);
String resourceId = ResourceIdUtils.buildResourceId(null, null, node, null, null); String resourceId = ResourceIdUtils.buildResourceId(null, null, node, null, null);
ResourceConfig resourceConfig = new ResourceConfig(resourceId, 0, 0); ResourceConfig resourceConfig = new ResourceConfig(resourceId, -1L, -1L);
resourceConfigs.add(resourceConfig); resourceConfigs.add(resourceConfig);
} }
checkRateLimitConfigAndAddTo(resourceConfigs, b, null, null, ResourceIdUtils.NODE, null, null, null); checkRateLimitConfigAndAddTo(resourceConfigs, b, null, null, ResourceIdUtils.NODE, null, null, null);
@@ -407,11 +407,11 @@ public class FlowControlFilter extends FizzWebFilter {
} else { } else {
String node = ResourceIdUtils.getNode(resource); String node = ResourceIdUtils.getNode(resource);
if (node != null && node.equals(ResourceIdUtils.NODE)) { if (node != null && node.equals(ResourceIdUtils.NODE)) {
rc = new ResourceConfig(resource, 0, 0); rc = new ResourceConfig(resource, -1L, -1L);
} }
if (defaultRateLimitConfigId != null) { if (defaultRateLimitConfigId != null) {
if (defaultRateLimitConfigId.equals(ResourceIdUtils.SERVICE_DEFAULT)) { if (defaultRateLimitConfigId.equals(ResourceIdUtils.SERVICE_DEFAULT)) {
rc = new ResourceConfig(resource, 0, 0); rc = new ResourceConfig(resource, -1L, -1L);
rateLimitConfig = resourceRateLimitConfigService.getResourceRateLimitConfig(ResourceIdUtils.SERVICE_DEFAULT_RESOURCE); rateLimitConfig = resourceRateLimitConfigService.getResourceRateLimitConfig(ResourceIdUtils.SERVICE_DEFAULT_RESOURCE);
if (rateLimitConfig != null && rateLimitConfig.isEnable()) { if (rateLimitConfig != null && rateLimitConfig.isEnable()) {
rc.setMaxCon(rateLimitConfig.concurrents); rc.setMaxCon(rateLimitConfig.concurrents);
@@ -441,7 +441,7 @@ public class FlowControlFilter extends FizzWebFilter {
} }
}*/ }*/
if (cb != null) { if (cb != null) {
rc = new ResourceConfig(resource, 0, 0); rc = new ResourceConfig(resource, -1L, -1L);
resourceConfigs.add(rc); resourceConfigs.add(rc);
} }
} }
@@ -508,7 +508,7 @@ public class FlowControlFilter extends FizzWebFilter {
private void something4(List<ResourceConfig> resourceConfigs, String app, String ip, String service) { private void something4(List<ResourceConfig> resourceConfigs, String app, String ip, String service) {
String r = ResourceIdUtils.buildResourceId(app, ip, null, service, null); String r = ResourceIdUtils.buildResourceId(app, ip, null, service, null);
ResourceConfig rc = new ResourceConfig(r, 0, 0); ResourceConfig rc = new ResourceConfig(r, -1L, -1L);
resourceConfigs.add(rc); resourceConfigs.add(rc);
} }

View File

@@ -161,10 +161,10 @@ public class FlowStat {
for (ResourceConfig resourceConfig : resourceConfigs) { for (ResourceConfig resourceConfig : resourceConfigs) {
long maxCon = resourceConfig.getMaxCon(); long maxCon = resourceConfig.getMaxCon();
long maxQPS = resourceConfig.getMaxQPS(); long maxQPS = resourceConfig.getMaxQPS();
if (maxCon > 0 || maxQPS > 0) { if (maxCon >= 0 || maxQPS >= 0) {
ResourceStat resourceStat = getResourceStat(resourceConfig.getResourceId()); ResourceStat resourceStat = getResourceStat(resourceConfig.getResourceId());
// check concurrent request // check concurrent request
if (maxCon > 0) { if (maxCon >= 0) {
long n = resourceStat.getConcurrentRequests().get(); long n = resourceStat.getConcurrentRequests().get();
if (n >= maxCon) { if (n >= maxCon) {
resourceStat.incrBlockRequestToTimeSlot(curTimeSlotId); resourceStat.incrBlockRequestToTimeSlot(curTimeSlotId);
@@ -184,7 +184,7 @@ public class FlowStat {
} }
// check QPS // check QPS
if (maxQPS > 0) { if (maxQPS >= 0) {
long total = resourceStat.getTimeSlot(curTimeSlotId).getCounter(); long total = resourceStat.getTimeSlot(curTimeSlotId).getCounter();
if (total >= maxQPS) { if (total >= maxQPS) {
resourceStat.incrBlockRequestToTimeSlot(curTimeSlotId); resourceStat.incrBlockRequestToTimeSlot(curTimeSlotId);

View File

@@ -46,14 +46,14 @@ public class ResourceConfig {
// Flow control rule // Flow control rule
//--------------------------------------------------------------------- //---------------------------------------------------------------------
/** /**
* Maximum concurrent request, zero or negative for no limit * Maximum concurrent request, negative for no limit
*/ */
private long maxCon; private long maxCon = -1L;
/** /**
* Maximum QPS, zero or negative for no limit * Maximum QPS, negative for no limit
*/ */
private long maxQPS; private long maxQPS = -1L;
//--------------------------------------------------------------------- //---------------------------------------------------------------------

View File

@@ -63,9 +63,9 @@ public class ResourceRateLimitConfig {
public byte type; public byte type;
public long qps; public long qps = -1L;
public long concurrents; public long concurrents = -1L;
public String responseType; public String responseType;

View File

@@ -23,6 +23,7 @@ import com.fizzgate.util.ReflectionUtils;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@@ -62,7 +63,7 @@ public class CallbackServiceTests {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("h1", "v1"); headers.add("h1", "v1");
DataBuffer body = null; String body = null;
CallbackConfig callbackConfig = new CallbackConfig(); CallbackConfig callbackConfig = new CallbackConfig();
callbackConfig.receivers = new ArrayList<>(); callbackConfig.receivers = new ArrayList<>();

View File

@@ -115,8 +115,8 @@ public class FlowStatTests {
// Note: use different resource ID to avoid being affected by previous test data // Note: use different resource ID to avoid being affected by previous test data
FlowRuleCase c5 = new FlowRuleCase(); FlowRuleCase c5 = new FlowRuleCase();
c5.resourceConfigs.add(new ResourceConfig("_global5", 0, 0)); c5.resourceConfigs.add(new ResourceConfig("_global5", -1L, -1L));
c5.resourceConfigs.add(new ResourceConfig("service5", 0, 0)); c5.resourceConfigs.add(new ResourceConfig("service5", -1L, -1L));
c5.resourceExpects.add(new ResourceExpect(c5.totalReqs, c5.totalReqs, c5.totalReqs, 0)); c5.resourceExpects.add(new ResourceExpect(c5.totalReqs, c5.totalReqs, c5.totalReqs, 0));
c5.resourceExpects.add(new ResourceExpect(c5.totalReqs, c5.totalReqs, c5.totalReqs, 0)); c5.resourceExpects.add(new ResourceExpect(c5.totalReqs, c5.totalReqs, c5.totalReqs, 0));
c5.expectResult = IncrRequestResult.success(); c5.expectResult = IncrRequestResult.success();
@@ -124,8 +124,8 @@ public class FlowStatTests {
// Note: use different resource ID to avoid being affected by previous test data // Note: use different resource ID to avoid being affected by previous test data
FlowRuleCase c6 = new FlowRuleCase(); FlowRuleCase c6 = new FlowRuleCase();
c6.resourceConfigs.add(new ResourceConfig("_global6", 20, 0)); c6.resourceConfigs.add(new ResourceConfig("_global6", 20, -1L));
c6.resourceConfigs.add(new ResourceConfig("service6", 20, 0)); c6.resourceConfigs.add(new ResourceConfig("service6", 20, -1L));
c6.resourceExpects.add(new ResourceExpect(20, 20, 20, c6.totalReqs - 20)); c6.resourceExpects.add(new ResourceExpect(20, 20, 20, c6.totalReqs - 20));
c6.resourceExpects.add(new ResourceExpect(20, 20, 20, 0)); c6.resourceExpects.add(new ResourceExpect(20, 20, 20, 0));
c6.expectResult = IncrRequestResult.block("_global6", BlockType.CONCURRENT_REQUEST); c6.expectResult = IncrRequestResult.block("_global6", BlockType.CONCURRENT_REQUEST);
@@ -133,8 +133,8 @@ public class FlowStatTests {
// Note: use different resource ID to avoid being affected by previous test data // Note: use different resource ID to avoid being affected by previous test data
FlowRuleCase c7 = new FlowRuleCase(); FlowRuleCase c7 = new FlowRuleCase();
c7.resourceConfigs.add(new ResourceConfig("_global7", 0, 0)); c7.resourceConfigs.add(new ResourceConfig("_global7", -1L, -1L));
c7.resourceConfigs.add(new ResourceConfig("service7", 0, 20)); c7.resourceConfigs.add(new ResourceConfig("service7", -1L, 20));
c7.resourceExpects.add(new ResourceExpect(20, 20, 20, 0)); c7.resourceExpects.add(new ResourceExpect(20, 20, 20, 0));
c7.resourceExpects.add(new ResourceExpect(20, 20, 20, c7.totalReqs - 20)); c7.resourceExpects.add(new ResourceExpect(20, 20, 20, c7.totalReqs - 20));
c7.expectResult = IncrRequestResult.block("service7", BlockType.QPS); c7.expectResult = IncrRequestResult.block("service7", BlockType.QPS);