Skip to content

Commit

Permalink
将服务黑名单开关服务改为统一通过开关配置
Browse files Browse the repository at this point in the history
  • Loading branch information
luanwenfei-venus committed Apr 3, 2023
1 parent 2675bdd commit de99f4a
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 125 deletions.
33 changes: 18 additions & 15 deletions sermant-agentcore/sermant-agentcore-config/config/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ agent.config.isEnhanceBootStrapEnable=false
agent.config.ignoredPrefixes=com.huawei.sermant,com.huaweicloud.sermant
agent.config.ignoredInterfaces=org.springframework.cglib.proxy.Factory
agent.config.combineStrategy=ALL
agent.config.serviceBlackList=com.huaweicloud.sermant.implement.service.heartbeat.HeartbeatServiceImpl,com.huaweicloud.sermant.implement.service.send.netty.NettyGatewayClient,com.huaweicloud.sermant.implement.service.tracing.TracingServiceImpl
agent.config.serviceInjectList=com.huawei.discovery.service.lb.filter.NopInstanceFilter,com.huawei.discovery.service.lb.DiscoveryManager,com.huawei.discovery.service.util.ApplyUtil,com.huawei.discovery.service.lb.cache.InstanceCacheManager

# agent service config
agent.service.heartbeat.enable=false
agent.service.gateway.enable=false
agent.service.tracing.enable=false
agent.service.visibility.enable=false
agent.service.inject.enable=true
agent.service.monitor.enable=false
agent.service.dynamic.config.enable=true

# event config
event.config.enable=false
event.config.offerWarnLog=false
event.config.offerErrorLog=false
event.config.sendInterval=30000
event.config.offerInterval=300000
event.enable=false
event.offerWarnLog=false
event.offerErrorLog=false
event.sendInterval=30000
event.offerInterval=300000

# dynamic config
dynamic.config.timeoutValue=30000
Expand All @@ -28,18 +36,13 @@ dynamic.config.enableAuth=false
# heartbeat config
heartbeat.interval=30000

#backend config
backend.nettyIp=127.0.0.1
backend.nettyPort=6888
backend.httpIp=127.0.0.1
backend.httpPort=8900
# gateway config
gateway.nettyIp=127.0.0.1
gateway.nettyPort=6888

# service meta config
service.meta.application=default
service.meta.version=1.0.0
service.meta.project=default
service.meta.environment=
service.meta.zone=

# service visibility config
visibility.service.enableStart=false
service.meta.zone=
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ agent.config.isEnhanceBootStrapEnable=false
agent.config.ignoredPrefixes=com.huawei.sermant,com.huaweicloud.sermant
agent.config.ignoredInterfaces=org.springframework.cglib.proxy.Factory
agent.config.combineStrategy=ALL
agent.config.serviceBlackList=com.huaweicloud.sermant.implement.service.heartbeat.HeartbeatServiceImpl,com.huaweicloud.sermant.implement.service.send.netty.NettyGatewayClient,com.huaweicloud.sermant.implement.service.tracing.TracingServiceImpl
agent.config.serviceInjectList=com.huawei.discovery.service.lb.filter.NopInstanceFilter,com.huawei.discovery.service.lb.DiscoveryManager
agent.config.serviceInjectList=com.huawei.discovery.service.lb.filter.NopInstanceFilter,com.huawei.discovery.service.lb.DiscoveryManager,com.huawei.discovery.service.util.ApplyUtil,com.huawei.discovery.service.lb.cache.InstanceCacheManager

# agent service config
agent.service.heartbeat.enable=true
agent.service.gateway.enable=true
agent.service.tracing.enable=true
agent.service.visibility.enable=true
agent.service.inject.enable=true
agent.service.monitor.enable=true
agent.service.dynamic.config.enable=true

# event config
event.config.enable=false
event.config.offerWarnLog=false
event.config.offerErrorLog=false
event.config.sendInterval=30000
event.config.offerInterval=300000
event.enable=false
event.offerWarnLog=false
event.offerErrorLog=false
event.sendInterval=30000
event.offerInterval=300000

# dynamic config
dynamic.config.timeoutValue=30000
Expand All @@ -28,15 +36,13 @@ dynamic.config.enableAuth=false
# heartbeat config
heartbeat.interval=30000

#backend config
backend.nettyIp=127.0.0.1
backend.nettyPort=6888
backend.httpIp=127.0.0.1
backend.httpPort=8900
# gateway config
gateway.nettyIp=127.0.0.1
gateway.nettyPort=6888

# service meta config
service.meta.application=default
service.meta.version=1.0.0
service.meta.project=default
service.meta.environment=
service.meta.zone=
service.meta.zone=
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author luanwenfei
* @since 2023-03-08
*/
@ConfigTypeKey("event.config")
@ConfigTypeKey("event")
public class EventConfig implements BaseConfig {
/**
* 默认事件发送时间间隔
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ public class AgentConfig implements BaseConfig {
*/
private CombineStrategy combineStrategy = CombineStrategy.ALL;

/**
* agent服务黑名单
*/
private Set<String> serviceBlackList = Collections.emptySet();

/**
* 拦截插件服务名单
*/
Expand Down Expand Up @@ -113,14 +108,6 @@ public void setEnhancedClassOutputPath(String enhancedClassOutputPath) {
this.enhancedClassOutputPath = enhancedClassOutputPath;
}

public Set<String> getServiceBlackList() {
return serviceBlackList;
}

public void setServiceBlackList(Set<String> serviceBlackList) {
this.serviceBlackList = serviceBlackList;
}

public Set<String> getServiceInjectList() {
return serviceInjectList;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.huaweicloud.sermant.core.service;

import com.huaweicloud.sermant.core.config.common.BaseConfig;
import com.huaweicloud.sermant.core.config.common.ConfigFieldKey;
import com.huaweicloud.sermant.core.config.common.ConfigTypeKey;

/**
* Agent核心服务的通用配置
*
* @author luanwenfei
* @since 2023-04-01
*/
@ConfigTypeKey("agent.service")
public class ServiceConfig implements BaseConfig {
@ConfigFieldKey("heartbeat.enable")
private boolean heartBeatEnable = false;

@ConfigFieldKey("gateway.enable")
private boolean gatewayEnable = false;

@ConfigFieldKey("tracing.enable")
private boolean tracingEnable = false;

@ConfigFieldKey("visibility.enable")
private boolean visibilityEnable = false;

@ConfigFieldKey("inject.enable")
private boolean injectEnable = false;

@ConfigFieldKey("monitor.enable")
private boolean monitorEnable = false;

@ConfigFieldKey("dynamic.config.enable")
private boolean dynamicConfigEnable = false;

public boolean isHeartBeatEnable() {
return heartBeatEnable;
}

public void setHeartBeatEnable(boolean heartBeatEnable) {
this.heartBeatEnable = heartBeatEnable;
}

public boolean isGatewayEnable() {
return gatewayEnable;
}

public void setGatewayEnable(boolean gatewayEnable) {
this.gatewayEnable = gatewayEnable;
}

public boolean isTracingEnable() {
return tracingEnable;
}

public void setTracingEnable(boolean tracingEnable) {
this.tracingEnable = tracingEnable;
}

public boolean isVisibilityEnable() {
return visibilityEnable;
}

public void setVisibilityEnable(boolean visibilityEnable) {
this.visibilityEnable = visibilityEnable;
}

public boolean isInjectEnable() {
return injectEnable;
}

public void setInjectEnable(boolean injectEnable) {
this.injectEnable = injectEnable;
}

public boolean isMonitorEnable() {
return monitorEnable;
}

public void setMonitorEnable(boolean monitorEnable) {
this.monitorEnable = monitorEnable;
}

public boolean isDynamicConfigEnable() {
return dynamicConfigEnable;
}

public void setDynamicConfigEnable(boolean dynamicConfigEnable) {
this.dynamicConfigEnable = dynamicConfigEnable;
}

/**
* 通过服务的类名来检查该类型服务是否开启
*
* @param serviceName 服务名
* @return 是否开启了该服务
*/
public boolean checkServiceEnable(String serviceName) {
if ("com.huaweicloud.sermant.implement.service.heartbeat.HeartbeatServiceImpl".equals(serviceName)) {
return isHeartBeatEnable();
}
if ("com.huaweicloud.sermant.implement.service.send.netty.NettyGatewayClient".equals(serviceName)) {
return isGatewayEnable();
}
if ("com.huaweicloud.sermant.implement.service.dynamicconfig.BufferedDynamicConfigService".equals(
serviceName)) {
return isDynamicConfigEnable();
}
if ("com.huaweicloud.sermant.implement.service.tracing.TracingServiceImpl".equals(serviceName)) {
return isTracingEnable();
}
if ("com.huaweicloud.sermant.implement.service.visibility.VisibilityServiceImpl".equals(serviceName)) {
return isVisibilityEnable();
}
if ("com.huaweicloud.sermant.implement.service.inject.InjectServiceImpl".equals(serviceName)) {
return isInjectEnable();
}
if ("com.huaweicloud.sermant.implement.service.monitor.RegistryServiceImpl".equals(serviceName)) {
return isMonitorEnable();
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.huaweicloud.sermant.core.event.EventManager;
import com.huaweicloud.sermant.core.event.collector.FrameworkEventCollector;
import com.huaweicloud.sermant.core.exception.DupServiceException;
import com.huaweicloud.sermant.core.plugin.agent.config.AgentConfig;
import com.huaweicloud.sermant.core.utils.SpiLoadUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -59,9 +58,9 @@ public class ServiceManager {
private static final Map<String, BaseService> SERVICES = new HashMap<String, BaseService>();

/**
* agent配置
* Agent核心服务配置
*/
private static final AgentConfig AGENT_CONFIG = ConfigManager.getConfig(AgentConfig.class);
private static final ServiceConfig SERVICE_CONFIG = ConfigManager.getConfig(ServiceConfig.class);

/**
* Constructor.
Expand All @@ -76,8 +75,8 @@ public static void initServices() {
ArrayList<String> startServiceArray = new ArrayList<>();
for (final BaseService service : ServiceLoader.load(BaseService.class,
ClassLoaderManager.getFrameworkClassLoader())) {
if (!AGENT_CONFIG.getServiceBlackList().contains(service.getClass().getName())
&& loadService(service, service.getClass(), BaseService.class)) {
if (SERVICE_CONFIG.checkServiceEnable(service.getClass().getName()) && loadService(service,
service.getClass(), BaseService.class)) {
service.start();
startServiceArray.add(service.getClass().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@
import com.huaweicloud.sermant.core.config.common.ConfigTypeKey;

/**
* Backend配置
* gateway配置
*
* @author luanwenfei
* @since 2022-03-24
*/
@ConfigTypeKey("backend")
public class BackendConfig implements BaseConfig {
@ConfigTypeKey("gateway")
public class GatewayConfig implements BaseConfig {
private String nettyIp;

private int nettyPort;

private String httpIp;

private int httpPort;

public String getNettyIp() {
return nettyIp;
}
Expand All @@ -50,20 +46,4 @@ public int getNettyPort() {
public void setNettyPort(int nettyPort) {
this.nettyPort = nettyPort;
}

public String getHttpIp() {
return httpIp;
}

public void setHttpIp(String httpIp) {
this.httpIp = httpIp;
}

public int getHttpPort() {
return httpPort;
}

public void setHttpPort(int httpPort) {
this.httpPort = httpPort;
}
}
Loading

0 comments on commit de99f4a

Please sign in to comment.