use of org.apache.skywalking.oap.server.configuration.api.ConfigTable in project skywalking by apache.
the class ZookeeperConfigWatcherRegister method readConfig.
@Override
public Optional<ConfigTable> readConfig(Set<String> keys) {
ConfigTable table = new ConfigTable();
keys.forEach(s -> {
ChildData data = this.childrenCache.getCurrentData(this.prefix + s);
String itemValue = null;
if (data != null && data.getData() != null) {
itemValue = new String(data.getData(), StandardCharsets.UTF_8);
}
table.add(new ConfigTable.ConfigItem(s, itemValue));
});
return Optional.of(table);
}
use of org.apache.skywalking.oap.server.configuration.api.ConfigTable in project skywalking by apache.
the class GRPCConfigWatcherRegister method readConfig.
@Override
public Optional<ConfigTable> readConfig(Set<String> keys) {
ConfigTable table = new ConfigTable();
try {
ConfigurationRequest.Builder builder = ConfigurationRequest.newBuilder().setClusterName(settings.getClusterName());
if (uuid != null) {
builder.setUuid(uuid);
}
ConfigurationResponse response = stub.call(builder.build());
String responseUuid = response.getUuid();
if (Objects.equals(uuid, responseUuid)) {
// If UUID matched, the config table is expected as empty.
return Optional.empty();
}
response.getConfigTableList().forEach(config -> {
final String name = config.getName();
if (keys.contains(name)) {
table.add(new ConfigTable.ConfigItem(name, config.getValue()));
}
});
this.uuid = responseUuid;
} catch (Exception e) {
log.error("Remote config center [{}] is not available.", settings, e);
}
return Optional.of(table);
}
use of org.apache.skywalking.oap.server.configuration.api.ConfigTable in project skywalking by apache.
the class EtcdConfigWatcherRegister method readConfig.
@Override
public Optional<ConfigTable> readConfig(final Set<String> keys) {
ConfigTable table = new ConfigTable();
keys.forEach(e -> {
try {
GetResponse response = client.get(ByteSequence.from(e, Charset.defaultCharset())).get();
if (0 == response.getCount()) {
table.add(new ConfigTable.ConfigItem(e, null));
} else {
response.getKvs().forEach(kv -> table.add(new ConfigTable.ConfigItem(kv.getKey().toString(Charset.defaultCharset()), kv.getValue().toString(Charset.defaultCharset()))));
}
} catch (Exception exp) {
throw new EtcdConfigException("Failed to read configuration", exp);
}
});
return Optional.of(table);
}
use of org.apache.skywalking.oap.server.configuration.api.ConfigTable in project skywalking by apache.
the class ConfigmapConfigWatcherRegisterTest method readConfigWhenConfigMapDataIsNull.
@Test
public void readConfigWhenConfigMapDataIsNull() throws Exception {
Map<String, String> configMapData = new HashMap<>();
PowerMockito.doReturn(configMapData).when(informer).configMapData();
Optional<ConfigTable> optionalConfigTable = register.readConfig(new HashSet<String>() {
{
add("key1");
}
});
Assert.assertTrue(optionalConfigTable.isPresent());
ConfigTable configTable = optionalConfigTable.get();
Assert.assertEquals(configTable.getItems().size(), 1);
Assert.assertEquals(configTable.getItems().get(0).getName(), "key1");
Assert.assertNull(configTable.getItems().get(0).getValue());
}
use of org.apache.skywalking.oap.server.configuration.api.ConfigTable in project skywalking by apache.
the class ConfigmapConfigWatcherRegisterTest method readConfigWhenInformerWork.
@Test
public void readConfigWhenInformerWork() throws Exception {
Map<String, String> configMapData = this.readMockConfigMapData();
PowerMockito.doReturn(configMapData).when(informer).configMapData();
Optional<ConfigTable> optionalConfigTable = register.readConfig(new HashSet<String>() {
{
add("agent-analyzer.default.slowDBAccessThreshold");
add("alarm.default.alarm-settings");
add("core.default.apdexThreshold");
add("agent-analyzer.default.uninstrumentedGateways");
}
});
Assert.assertTrue(optionalConfigTable.isPresent());
ConfigTable configTable = optionalConfigTable.get();
List<String> list = configTable.getItems().stream().map(ConfigTable.ConfigItem::getValue).filter(Objects::nonNull).collect(Collectors.toList());
Assert.assertEquals(list.size(), 4);
}
Aggregations