add flow statistic and rate limit config (#29)
add flow statistic and rate limit config
This commit is contained in:
@@ -86,3 +86,10 @@ stat:
|
||||
send-log:
|
||||
# switch for push log data
|
||||
open: true
|
||||
sched:
|
||||
executors: 2
|
||||
flowControl: true
|
||||
flow-stat-sched:
|
||||
cron: 2/10 * * * * ?
|
||||
dest: redis
|
||||
queue: fizz_resource_access_stat
|
||||
@@ -138,16 +138,16 @@ public class RateLimitTests {
|
||||
|
||||
long incrTime = DateTimeUtils.toMillis("2021-01-08 21:28:42.000", Constants.DatetimePattern.DP23);
|
||||
boolean success = flowStat.incrRequest("resourceX", incrTime, Long.MAX_VALUE, Long.MAX_VALUE);
|
||||
System.err.println("incrTime: " + incrTime + ", success: " + success);
|
||||
// System.err.println("incrTime: " + incrTime + ", success: " + success);
|
||||
|
||||
long startTimeSlot = DateTimeUtils.toMillis("2021-01-08 21:28:41.000", Constants.DatetimePattern.DP23);
|
||||
long endTimeSlot = DateTimeUtils.toMillis("2021-01-08 21:28:44.000", Constants.DatetimePattern.DP23);
|
||||
|
||||
List<ResourceTimeWindowStat> resourceTimeWindowStats = flowStat.getResourceTimeWindowStats(null, startTimeSlot, endTimeSlot, 3);
|
||||
if (resourceTimeWindowStats == null || resourceTimeWindowStats.isEmpty()) {
|
||||
System.err.println(toDP19(startTimeSlot) + " - " + toDP19(endTimeSlot) + " no flow stat data");
|
||||
// System.err.println(toDP19(startTimeSlot) + " - " + toDP19(endTimeSlot) + " no flow stat data");
|
||||
} else {
|
||||
System.err.println(JacksonUtils.writeValueAsString(resourceTimeWindowStats));
|
||||
// System.err.println(JacksonUtils.writeValueAsString(resourceTimeWindowStats));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,6 +160,6 @@ public class RateLimitTests {
|
||||
FlowStat flowStat = new FlowStat();
|
||||
boolean success = flowStat.incrRequest("resourceX", 1610181704000l, Long.MAX_VALUE, Long.MAX_VALUE);
|
||||
List<ResourceTimeWindowStat> r = flowStat.getResourceTimeWindowStats("resourceX", 1610181681000l, 1610181711000l, 30);
|
||||
System.err.println("r: " + JacksonUtils.writeValueAsString(r));
|
||||
// System.err.println("r: " + JacksonUtils.writeValueAsString(r));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,17 @@
|
||||
package we.stats.ratelimit;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.event.annotation.BeforeTestMethod;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import we.redis.RedisProperties;
|
||||
import we.redis.RedisServerConfiguration;
|
||||
import we.redis.RedisTemplateConfiguration;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
@@ -51,22 +45,13 @@ public class ResourceRateLimitConfigServiceTests {
|
||||
|
||||
@Test
|
||||
void initTest() throws Throwable {
|
||||
// System.err.println(redisProperties);
|
||||
// System.err.println(stringRedisTemplate);
|
||||
// System.err.println(reactiveStringRedisTemplate);
|
||||
|
||||
// stringRedisTemplate.opsForValue().set("name", "F-22");
|
||||
// Thread.sleep(2000);
|
||||
// String name = stringRedisTemplate.opsForValue().get("name");
|
||||
// assertEquals(name, "F-22");
|
||||
// System.err.println(name);
|
||||
|
||||
// stringRedisTemplate.opsForHash().put("fizz_rate_limit", "2", "{\"concurrents\":100,\"enable\":1,\"id\":2,\"isDeleted\":0,\"resource\":\"service_default\",\"type\":2}");
|
||||
// resourceRateLimitConfigService.init();
|
||||
// ResourceRateLimitConfig resourceRateLimitConfig = resourceRateLimitConfigService.getResourceRateLimitConfig("service_default");
|
||||
//
|
||||
stringRedisTemplate.opsForHash().put("fizz_rate_limit", "2", "{\"concurrents\":66,\"enable\":1,\"id\":2,\"isDeleted\":0,\"resource\":\"service_default\",\"type\":2}");
|
||||
resourceRateLimitConfigService.init();
|
||||
ResourceRateLimitConfig resourceRateLimitConfig = resourceRateLimitConfigService.getResourceRateLimitConfig("service_default");
|
||||
assertEquals(resourceRateLimitConfig.concurrents, 66);
|
||||
// System.err.println(resourceRateLimitConfig);
|
||||
// System.err.println("init test end");
|
||||
// Thread.currentThread().join();
|
||||
Thread.sleep(4000);
|
||||
// System.err.println("init test end");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user