Fix that the dynamic configuration is deleted on the server side but does not take effect on the agent. (#6255)
Co-authored-by: 吴晟 Wu Sheng <wu.sheng@foxmail.com>
This commit is contained in:
parent
9268b987af
commit
52c438b9c3
|
|
@ -18,15 +18,18 @@
|
|||
|
||||
package org.apache.skywalking.apm.agent.core.conf.dynamic;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import io.grpc.Channel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.Getter;
|
||||
import org.apache.skywalking.apm.agent.core.boot.BootService;
|
||||
|
|
@ -128,12 +131,13 @@ public class ConfigurationDiscoveryService implements BootService, GRPCChannelLi
|
|||
*/
|
||||
public void handleConfigurationDiscoveryCommand(ConfigurationDiscoveryCommand configurationDiscoveryCommand) {
|
||||
final String responseUuid = configurationDiscoveryCommand.getUuid();
|
||||
final List<KeyStringValuePair> config = configurationDiscoveryCommand.getConfig();
|
||||
|
||||
if (responseUuid != null && Objects.equals(this.uuid, responseUuid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<KeyStringValuePair> config = readConfig(configurationDiscoveryCommand);
|
||||
|
||||
config.forEach(property -> {
|
||||
String propertyKey = property.getKey();
|
||||
WatcherHolder holder = register.get(propertyKey);
|
||||
|
|
@ -168,6 +172,30 @@ public class ConfigurationDiscoveryService implements BootService, GRPCChannelLi
|
|||
LOGGER.trace("Current configurations after the sync, configurations:{}", register.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the registered dynamic configuration, compare it with the dynamic configuration information returned by the
|
||||
* service, and complete the dynamic configuration that has been deleted on the OAP.
|
||||
*
|
||||
* @param configurationDiscoveryCommand Describe dynamic configuration information
|
||||
* @return Adapted dynamic configuration information
|
||||
*/
|
||||
private List<KeyStringValuePair> readConfig(ConfigurationDiscoveryCommand configurationDiscoveryCommand) {
|
||||
Map<String, KeyStringValuePair> commandConfigs = configurationDiscoveryCommand.getConfig()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
KeyStringValuePair::getKey,
|
||||
Function.identity()
|
||||
));
|
||||
List<KeyStringValuePair> configList = Lists.newArrayList();
|
||||
for (final String name : register.keys()) {
|
||||
KeyStringValuePair command = commandConfigs.getOrDefault(name, KeyStringValuePair.newBuilder()
|
||||
.setKey(name)
|
||||
.build());
|
||||
configList.add(command);
|
||||
}
|
||||
return configList;
|
||||
}
|
||||
|
||||
/**
|
||||
* get agent dynamic config through gRPC.
|
||||
*/
|
||||
|
|
@ -213,6 +241,10 @@ public class ConfigurationDiscoveryService implements BootService, GRPCChannelLi
|
|||
return register.get(name);
|
||||
}
|
||||
|
||||
public Set<String> keys() {
|
||||
return register.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
ArrayList<String> registerTableDescription = new ArrayList<>(register.size());
|
||||
|
|
|
|||
|
|
@ -18,22 +18,29 @@
|
|||
|
||||
package org.apache.skywalking.oap.server.recevier.configuration.discovery;
|
||||
|
||||
import java.io.StringReader;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher;
|
||||
import org.apache.skywalking.oap.server.core.Const;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleProvider;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* AgentConfigurationsWatcher used to handle dynamic configuration changes.
|
||||
*/
|
||||
public class AgentConfigurationsWatcher extends ConfigChangeWatcher {
|
||||
private volatile String settingsString;
|
||||
private volatile AgentConfigurationsTable agentConfigurationsTable;
|
||||
private final AgentConfigurations emptyAgentConfigurations;
|
||||
|
||||
public AgentConfigurationsWatcher(ModuleProvider provider) {
|
||||
super(ConfigurationDiscoveryModule.NAME, provider, "agentConfigurations");
|
||||
this.settingsString = Const.EMPTY_STRING;
|
||||
this.agentConfigurationsTable = new AgentConfigurationsTable();
|
||||
this.emptyAgentConfigurations = new AgentConfigurations(
|
||||
null, new HashMap<>(), DigestUtils.sha512Hex("EMPTY")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -54,7 +61,20 @@ public class AgentConfigurationsWatcher extends ConfigChangeWatcher {
|
|||
return settingsString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get service dynamic configuration information, if there is no dynamic configuration information, return to empty
|
||||
* dynamic configuration to prevent the server from deleted the dynamic configuration, but it does not take effect
|
||||
* on the agent side.
|
||||
*
|
||||
* @param service Service name to be queried
|
||||
* @return Service dynamic configuration information
|
||||
*/
|
||||
public AgentConfigurations getAgentConfigurations(String service) {
|
||||
return agentConfigurationsTable.getAgentConfigurationsCache().get(service);
|
||||
AgentConfigurations agentConfigurations = agentConfigurationsTable.getAgentConfigurationsCache().get(service);
|
||||
if (null == agentConfigurations) {
|
||||
return emptyAgentConfigurations;
|
||||
} else {
|
||||
return agentConfigurations;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue