bugfix: optimize ratelimit actuator. (#420)

pull/437/head
weihubeats 3 years ago committed by GitHub
parent 70236a705a
commit 74f4433e75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,3 +1,4 @@
# Change Log
---
- [Bugfix: optimize ratelimit actuator](https://github.com/Tencent/spring-cloud-tencent/pull/420)

@ -22,11 +22,16 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import com.tencent.cloud.common.util.JacksonUtils;
import com.tencent.cloud.polaris.context.ServiceRuleManager;
import com.tencent.cloud.polaris.ratelimit.config.PolarisRateLimitProperties;
import com.tencent.polaris.client.pb.RateLimitProto;
import com.tencent.polaris.client.pb.RoutingProto;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
@ -42,6 +47,8 @@ import org.springframework.util.CollectionUtils;
@Endpoint(id = "polaris-ratelimit")
public class PolarisRateLimitRuleEndpoint {
private static final Logger LOG = LoggerFactory.getLogger(PolarisRateLimitRuleEndpoint.class);
private final ServiceRuleManager serviceRuleManager;
private final PolarisRateLimitProperties polarisRateLimitProperties;
@ -76,26 +83,15 @@ public class PolarisRateLimitRuleEndpoint {
}
for (RateLimitProto.Rule rule : rateLimit.getRulesList()) {
Map<String, Object> ruleMap = new HashMap<>();
ruleMap.put("id", rule.getId());
ruleMap.put("priority", rule.getPriority());
ruleMap.put("resource", rule.getResource());
ruleMap.put("type", rule.getType());
ruleMap.put("labels", rule.getLabelsMap());
ruleMap.put("amounts", rule.getAmountsList());
ruleMap.put("action", rule.getAction());
ruleMap.put("disable", rule.getDisable());
ruleMap.put("report", rule.getReport());
ruleMap.put("create_time", rule.getCtime());
ruleMap.put("modify_time", rule.getMtime());
ruleMap.put("revision", rule.getRevision());
ruleMap.put("service_token", rule.getServiceToken());
ruleMap.put("adjuster", rule.getAdjuster());
ruleMap.put("regex_combine", rule.getRegexCombine());
ruleMap.put("amount_mode", rule.getAmountMode());
ruleMap.put("failover", rule.getFailover());
ruleMap.put("cluster", rule.getCluster());
rateLimitRule.add(ruleMap);
String ruleJson = "";
try {
ruleJson = JsonFormat.printer().print(rule);
}
catch (InvalidProtocolBufferException e) {
LOG.error("rule to Json failed. check rule {}.", rule, e);
throw new RuntimeException("Json failed.", e);
}
rateLimitRule.add(JacksonUtils.deserialize2Map(ruleJson));
}
return rateLimitRule;
}

Loading…
Cancel
Save