Skip to content

Commit

Permalink
去掉灰度Actuator接口,提升性能
Browse files Browse the repository at this point in the history
  • Loading branch information
HaojunRen committed Nov 30, 2019
1 parent 63bbf0a commit da18787
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 119 deletions.
5 changes: 0 additions & 5 deletions discovery-console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,24 @@
* @version 1.0
*/

import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.client.RestTemplate;

import com.nepxion.discovery.common.handler.RestErrorHandler;
import com.nepxion.discovery.console.authentication.AuthenticationResource;
import com.nepxion.discovery.console.authentication.AuthenticationResourceImpl;
import com.nepxion.discovery.console.endpoint.ConsoleEndpoint;

@Configuration
@Import({ SwaggerConfiguration.class, CorsRegistryConfiguration.class })
public class ConsoleAutoConfiguration {
@ConditionalOnClass(RestControllerEndpoint.class)
protected static class ConsoleEndpointConfiguration {
@Bean
public ConsoleEndpoint consoleEndpoint() {
return new ConsoleEndpoint();
}

@Bean
public RestTemplate consoleRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new RestErrorHandler());

return restTemplate;
}

@Bean
@ConditionalOnMissingBean
public AuthenticationResource authenticationResource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -43,6 +40,7 @@
import com.nepxion.discovery.common.entity.InstanceEntity;
import com.nepxion.discovery.common.entity.InstanceEntityWrapper;
import com.nepxion.discovery.common.entity.UserEntity;
import com.nepxion.discovery.common.handler.RestErrorHandler;
import com.nepxion.discovery.console.adapter.ConfigAdapter;
import com.nepxion.discovery.console.authentication.AuthenticationResource;
import com.nepxion.discovery.console.rest.ConfigClearRestInvoker;
Expand All @@ -55,8 +53,6 @@
@RestController
@RequestMapping(path = "/console")
@Api(tags = { "控制台接口" })
@RestControllerEndpoint(id = "console")
@ManagedResource(description = "Console Endpoint")
public class ConsoleEndpoint {
private static final Logger LOG = LoggerFactory.getLogger(ConsoleEndpoint.class);

Expand All @@ -69,175 +65,158 @@ public class ConsoleEndpoint {
private ConfigAdapter configAdapter;

@Autowired
private AuthenticationResource authenticationResource;

private RestTemplate consoleRestTemplate;

@Autowired
private AuthenticationResource authenticationResource;
public ConsoleEndpoint() {
consoleRestTemplate = new RestTemplate();
consoleRestTemplate.setErrorHandler(new RestErrorHandler());
}

@RequestMapping(path = "/authenticate", method = RequestMethod.POST)
@ApiOperation(value = "登录认证", notes = "", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> authenticate(@RequestBody @ApiParam(value = "UserEntity实例", required = true) UserEntity userEntity) {
return executeAuthenticate(userEntity);
}

@RequestMapping(path = "/discovery-type", method = RequestMethod.GET)
@ApiOperation(value = "获取注册发现中心类型", notes = "", response = ResponseEntity.class, httpMethod = "GET")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> discoveryType() {
return getDiscoveryType();
}

@RequestMapping(path = "/config-type", method = RequestMethod.GET)
@ApiOperation(value = "获取配置中心类型", notes = "", response = ResponseEntity.class, httpMethod = "GET")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> configType() {
return getConfigType();
}

@RequestMapping(path = "/groups", method = RequestMethod.GET)
@ApiOperation(value = "获取服务注册中心的服务组名列表", notes = "", response = List.class, httpMethod = "GET")
@ResponseBody
@ManagedOperation
public List<String> groups() {
return getGroups();
}

@RequestMapping(path = "/services", method = RequestMethod.GET)
@ApiOperation(value = "获取服务注册中心的服务名列表", notes = "", response = List.class, httpMethod = "GET")
@ResponseBody
@ManagedOperation
public List<String> services() {
return getServices();
}

@RequestMapping(path = "/instances/{serviceId}", method = RequestMethod.GET)
@ApiOperation(value = "获取服务注册中心的服务实例列表", notes = "", response = List.class, httpMethod = "GET")
@ResponseBody
@ManagedOperation
public List<ServiceInstance> instances(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId) {
return getInstances(serviceId);
}

@RequestMapping(path = "/instance-list/{serviceId}", method = RequestMethod.GET)
@ApiOperation(value = "获取服务注册中心的服务实例列表(精简数据)", notes = "", response = List.class, httpMethod = "GET")
@ResponseBody
@ManagedOperation
public List<InstanceEntity> instanceList(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId) {
return getInstanceList(serviceId);
}

@RequestMapping(path = "/instance-map", method = RequestMethod.POST)
@ApiOperation(value = "获取服务注册中心的服务实例的Map(精简数据)", notes = "服务组名列表", response = Map.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public Map<String, List<InstanceEntity>> instanceMap(@RequestBody @ApiParam(value = "服务组名列表,传入空列则可以获取全部服务实例数据", required = true) List<String> groups) {
return getInstanceMap(groups);
}

@RequestMapping(path = "/remote-config/update/{group}/{serviceId}", method = RequestMethod.POST)
@ApiOperation(value = "推送更新规则配置信息到远程配置中心", notes = "", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> remoteConfigUpdate(@PathVariable(value = "group") @ApiParam(value = "组名", required = true) String group, @PathVariable(value = "serviceId") @ApiParam(value = "服务名。当全局推送模式下,服务名必须由组名来代替", required = true) String serviceId, @RequestBody @ApiParam(value = "规则配置内容,XML格式", required = true) String config) {
return executeRemoteConfigUpdate(group, serviceId, config);
}

@RequestMapping(path = "/remote-config/clear/{group}/{serviceId}", method = RequestMethod.POST)
@ApiOperation(value = "清除规则配置信息到远程配置中心", notes = "", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> remoteConfigClear(@PathVariable(value = "group") @ApiParam(value = "组名", required = true) String group, @PathVariable(value = "serviceId") @ApiParam(value = "服务名。当全局推送模式下,服务名必须由组名来代替", required = true) String serviceId) {
return executeRemoteConfigClear(group, serviceId);
}

@RequestMapping(path = "/remote-config/view/{group}/{serviceId}", method = RequestMethod.GET)
@ApiOperation(value = "查看远程配置中心的规则配置信息", notes = "", response = ResponseEntity.class, httpMethod = "GET")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> remoteConfigView(@PathVariable(value = "group") @ApiParam(value = "组名", required = true) String group, @PathVariable(value = "serviceId") @ApiParam(value = "服务名。当全局推送模式下,服务名必须由组名来代替", required = true) String serviceId) {
return executeRemoteConfigView(group, serviceId);
}

@RequestMapping(path = "/config/update-async/{serviceId}", method = RequestMethod.POST)
@ApiOperation(value = "批量异步推送更新规则配置信息", notes = "", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> configUpdateAsync(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId, @RequestBody @ApiParam(value = "规则配置内容,XML格式", required = true) String config) {
return executeConfigUpdate(serviceId, config, true);
}

@RequestMapping(path = "/config/update-sync/{serviceId}", method = RequestMethod.POST)
@ApiOperation(value = "批量同步推送更新规则配置信息", notes = "", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> configUpdateSync(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId, @RequestBody @ApiParam(value = "规则配置内容,XML格式", required = true) String config) {
return executeConfigUpdate(serviceId, config, false);
}

@RequestMapping(path = "/config/clear-async/{serviceId}", method = RequestMethod.POST)
@ApiOperation(value = "批量异步清除更新的规则配置信息", notes = "", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> configClearAsync(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId) {
return executeConfigClear(serviceId, true);
}

@RequestMapping(path = "/config/clear-sync/{serviceId}", method = RequestMethod.POST)
@ApiOperation(value = "批量同步清除更新的规则配置信息", notes = "", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> configClearSync(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId) {
return executeConfigClear(serviceId, false);
}

@RequestMapping(path = "/version/update-async/{serviceId}", method = RequestMethod.POST)
@ApiOperation(value = "批量异步更新服务的动态版本", notes = "根据指定的localVersion更新服务的dynamicVersion。如果输入的localVersion不匹配服务的localVersion,则忽略;如果如果输入的localVersion为空,则直接更新服务的dynamicVersion", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> versionUpdateAsync(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId, @RequestBody @ApiParam(value = "版本号,格式为[dynamicVersion]或者[dynamicVersion];[localVersion]", required = true) String version) {
return executeVersionUpdate(serviceId, version, true);
}

@RequestMapping(path = "/version/update-sync/{serviceId}", method = RequestMethod.POST)
@ApiOperation(value = "批量同步更新服务的动态版本", notes = "根据指定的localVersion更新服务的dynamicVersion。如果输入的localVersion不匹配服务的localVersion,则忽略;如果如果输入的localVersion为空,则直接更新服务的dynamicVersion", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> versionUpdateSync(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId, @RequestBody @ApiParam(value = "版本号,格式为[dynamicVersion]或者[dynamicVersion];[localVersion]", required = true) String version) {
return executeVersionUpdate(serviceId, version, false);
}

@RequestMapping(path = "/version/clear-async/{serviceId}", method = RequestMethod.POST)
@ApiOperation(value = "批量异步清除服务的动态版本", notes = "根据指定的localVersion清除服务的dynamicVersion。如果输入的localVersion不匹配服务的localVersion,则忽略;如果如果输入的localVersion为空,则直接清除服务的dynamicVersion", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> versionClearAsync(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId, @RequestBody(required = false) @ApiParam(value = "版本号,指localVersion,可以为空") String version) {
return executeVersionClear(serviceId, version, true);
}

@RequestMapping(path = "/version/clear-sync/{serviceId}", method = RequestMethod.POST)
@ApiOperation(value = "批量同步清除服务的动态版本", notes = "根据指定的localVersion清除服务的dynamicVersion。如果输入的localVersion不匹配服务的localVersion,则忽略;如果如果输入的localVersion为空,则直接清除服务的dynamicVersion", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> versionClearSync(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId, @RequestBody(required = false) @ApiParam(value = "版本号,指localVersion,可以为空") String version) {
return executeVersionClear(serviceId, version, false);
}

@RequestMapping(path = "/sentinel/update/{serviceId}/{ruleType}", method = RequestMethod.POST)
@ApiOperation(value = "更新哨兵规则列表", notes = "哨兵规则类型取值: flow | degrade | authority | system | param-flow", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> sentinelUpdate(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId, @PathVariable(value = "ruleType") @ApiParam(value = "哨兵规则类型", required = true) String ruleType, @RequestBody @ApiParam(value = "哨兵规则内容,JSON格式", required = true) String rule) {
return executeSentinelUpdate(serviceId, ruleType, rule);
}

@RequestMapping(path = "/sentinel/clear/{serviceId}/{ruleType}", method = RequestMethod.POST)
@ApiOperation(value = "清除哨兵规则列表", notes = "哨兵规则类型取值: flow | degrade | authority | system | param-flow", response = ResponseEntity.class, httpMethod = "POST")
@ResponseBody
@ManagedOperation
public ResponseEntity<?> sentinelClear(@PathVariable(value = "serviceId") @ApiParam(value = "服务名", required = true) String serviceId, @PathVariable(value = "ruleType") @ApiParam(value = "哨兵规则类型", required = true) String ruleType) {
return executeSentinelClear(serviceId, ruleType);
}
Expand Down
5 changes: 0 additions & 5 deletions discovery-plugin-admin-center/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* @version 1.0
*/

import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
Expand All @@ -29,7 +28,6 @@
@Configuration
@Import(SwaggerConfiguration.class)
public class AdminAutoConfiguration {
@ConditionalOnClass(RestControllerEndpoint.class)
protected static class AdminEndpointConfiguration {
@Bean
public ConfigEndpoint configEndpoint() {
Expand All @@ -52,15 +50,15 @@ public GitEndpoint gitEndpoint() {
}
}

@ConditionalOnClass({ RestControllerEndpoint.class, FlowRule.class })
@ConditionalOnClass({ FlowRule.class })
protected static class SentinelCoreEndpointConfiguration {
@Bean
public SentinelCoreEndpoint sentinelCoreEndpoint() {
return new SentinelCoreEndpoint();
}
}

@ConditionalOnClass({ RestControllerEndpoint.class, ParamFlowRule.class })
@ConditionalOnClass({ ParamFlowRule.class })
protected static class SentinelParamEndpointConfiguration {
@Bean
public SentinelParamEndpoint sentinelParamEndpoint() {
Expand Down
Loading

0 comments on commit da18787

Please sign in to comment.