mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Sentinel endpoint refactor
This commit is contained in:
parent
490d02af7e
commit
51209ca9c6
@ -17,25 +17,23 @@
|
|||||||
package org.springframework.cloud.alibaba.sentinel.endpoint;
|
package org.springframework.cloud.alibaba.sentinel.endpoint;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||||
import org.springframework.cloud.alibaba.sentinel.SentinelProperties;
|
import org.springframework.cloud.alibaba.sentinel.SentinelProperties;
|
||||||
import org.springframework.cloud.alibaba.sentinel.custom.SentinelDataSourceHandler;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
|
import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig;
|
||||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
|
import com.alibaba.csp.sentinel.config.SentinelConfig;
|
||||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
|
import com.alibaba.csp.sentinel.log.LogBase;
|
||||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRuleManager;
|
||||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
|
|
||||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager;
|
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager;
|
||||||
import com.alibaba.csp.sentinel.slots.system.SystemRule;
|
|
||||||
import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
|
import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
|
||||||
|
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Endpoint for Sentinel, contains ans properties and rules
|
* Endpoint for Sentinel, contains ans properties and rules
|
||||||
@ -48,39 +46,35 @@ public class SentinelEndpoint {
|
|||||||
private SentinelProperties sentinelProperties;
|
private SentinelProperties sentinelProperties;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SentinelDataSourceHandler dataSourceHandler;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ApplicationContext applicationContext;
|
|
||||||
|
|
||||||
@ReadOperation
|
@ReadOperation
|
||||||
public Map<String, Object> invoke() {
|
public Map<String, Object> invoke() {
|
||||||
final Map<String, Object> result = new HashMap<>();
|
final Map<String, Object> result = new HashMap<>();
|
||||||
|
if (sentinelProperties.isEnabled()) {
|
||||||
|
|
||||||
List<FlowRule> flowRules = FlowRuleManager.getRules();
|
result.put("logDir", LogBase.getLogBaseDir());
|
||||||
List<DegradeRule> degradeRules = DegradeRuleManager.getRules();
|
result.put("logUsePid", LogBase.isLogNameUsePid());
|
||||||
List<SystemRule> systemRules = SystemRuleManager.getRules();
|
result.put("blockPage", WebServletConfig.getBlockPage());
|
||||||
List<ParamFlowRule> paramFlowRules = ParamFlowRuleManager.getRules();
|
result.put("metricsFileSize", SentinelConfig.singleMetricFileSize());
|
||||||
result.put("properties", sentinelProperties);
|
result.put("metricsFileCharset", SentinelConfig.charset());
|
||||||
result.put("FlowRules", flowRules);
|
result.put("totalMetricsFileCount", SentinelConfig.totalMetricFileCount());
|
||||||
result.put("DegradeRules", degradeRules);
|
result.put("consoleServer", TransportConfig.getConsoleServer());
|
||||||
result.put("SystemRules", systemRules);
|
result.put("clientIp", TransportConfig.getHeartbeatClientIp());
|
||||||
result.put("ParamFlowRule", paramFlowRules);
|
result.put("heartbeatIntervalMs", TransportConfig.getHeartbeatIntervalMs());
|
||||||
result.put("datasources", new HashMap<String, Object>());
|
result.put("clientPort", TransportConfig.getPort());
|
||||||
dataSourceHandler.getDataSourceBeanNameList().forEach(dataSourceBeanName -> {
|
result.put("coldFactor", sentinelProperties.getFlow().getColdFactor());
|
||||||
ReadableDataSource dataSource = applicationContext.getBean(dataSourceBeanName,
|
result.put("filter", sentinelProperties.getFilter());
|
||||||
ReadableDataSource.class);
|
result.put("datasource", sentinelProperties.getDatasource());
|
||||||
try {
|
|
||||||
((HashMap) result.get("datasources")).put(dataSourceBeanName,
|
|
||||||
dataSource.loadConfig());
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
((HashMap) result.get("datasources")).put(dataSourceBeanName,
|
|
||||||
"load error: " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
final Map<String, Object> rules = new HashMap<>();
|
||||||
|
result.put("rules", rules);
|
||||||
|
rules.put("flowRules", FlowRuleManager.getRules());
|
||||||
|
rules.put("degradeRules", SystemRuleManager.getRules());
|
||||||
|
rules.put("systemRules", SystemRuleManager.getRules());
|
||||||
|
rules.put("authorityRule", AuthorityRuleManager.getRules());
|
||||||
|
rules.put("paramFlowRule", ParamFlowRuleManager.getRules());
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user