Synch'ed EMS core with source repos.

Change-Id: I6a38d46e5b15d224dc8e6dbddd5112a4e9243113
This commit is contained in:
ipatini 2024-05-23 15:24:20 +03:00
parent c9f396591e
commit c0e8627b92
4 changed files with 43 additions and 13 deletions

View File

@ -111,4 +111,15 @@ public class ClientInstallationProperties implements InitializingBean {
// ----------------------------------------------------
private List<Class<InstallationContextProcessorPlugin>> installationContextProcessorPlugins = Collections.emptyList();
// ----------------------------------------------------
private K8sClientInstallationProperties k8s = new K8sClientInstallationProperties();
@Slf4j
@Data
@Configuration
public static class K8sClientInstallationProperties {
private Map<String,String> extraEnvVars = new LinkedHashMap<>();
}
}

View File

@ -26,6 +26,7 @@ import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
import static gr.iccs.imu.ems.common.k8s.K8sClient.getConfig;
@ -53,6 +54,7 @@ public class K8sClientInstaller implements ClientInstallerPlugin {
private String additionalCredentials; // Those specified in EMS_CLIENT_ADDITIONAL_BROKER_CREDENTIALS, plus one generated
private String brokerUsername;
private String brokerPassword;
private String extraEnvVars;
@Builder
public K8sClientInstaller(ClientInstallationTask task, long taskCounter, ClientInstallationProperties properties,
@ -65,6 +67,7 @@ public class K8sClientInstaller implements ClientInstallerPlugin {
this.passwordUtil = passwordUtil;
initializeAdditionalCredentials();
initializeExtraEnvVars();
}
private void initializeAdditionalCredentials() {
@ -80,6 +83,21 @@ public class K8sClientInstaller implements ClientInstallerPlugin {
additionalCredentials = sb.toString();
}
private void initializeExtraEnvVars() {
extraEnvVars = "";
if (properties.getK8s()==null) return;
if (properties.getK8s().getExtraEnvVars()==null) return;
String str = properties.getK8s().getExtraEnvVars().entrySet()
.stream().filter(e -> StringUtils.isNotBlank(e.getKey()))
.map(e -> String.format("""
- name: "%s"
value: "%s"
""", e.getKey().trim(), e.getValue()))
.collect(Collectors.joining("\n"));
log.info("K8sClientInstaller: Extra Env.Vars:\n{}", str);
extraEnvVars = str;
}
@Override
public boolean executeTask() {
boolean success = true;
@ -160,7 +178,8 @@ public class K8sClientInstaller implements ClientInstallerPlugin {
"EMS_CLIENT_CONFIG_MAP_NAME", getConfig("EMS_CLIENT_CONFIG_MAP_NAME", EMS_CLIENT_CONFIG_MAP_NAME_DEFAULT),
"EMS_CLIENT_ADDITIONAL_BROKER_CREDENTIALS", additionalCredentials,
"EMS_CLIENT_KEYSTORE_SECRET", getConfig("EMS_CLIENT_KEYSTORE_SECRET", ""),
"EMS_CLIENT_TRUSTSTORE_SECRET", getConfig("EMS_CLIENT_TRUSTSTORE_SECRET", "")
"EMS_CLIENT_TRUSTSTORE_SECRET", getConfig("EMS_CLIENT_TRUSTSTORE_SECRET", ""),
"EMS_CLIENT_EXTRA_ENV_VARS", extraEnvVars
);
log.debug("K8sClientInstaller: values: {}", values);

View File

@ -144,6 +144,7 @@ spec:
configMapKeyRef:
name: "${EMS_CLIENT_CONFIG_MAP_NAME}"
key: BAGUETTE_SERVER_PASSWORD
${EMS_CLIENT_EXTRA_ENV_VARS}
ports:
- name: openwire
containerPort: 61616

View File

@ -277,8 +277,8 @@ public class K8sNetdataCollector implements Collector, InitializingBean {
log.info("K8sNetdataCollector: Collecting Netdata metric '{}.{}' into '{}', every {} {}",
context, dimensions, destinationName, period, unit.name().toLowerCase());
});
log.trace("K8sNetdataCollector: doStart(): scheduledFuturesList={}", scheduledFuturesList);
log.debug("K8sNetdataCollector: doStart(): END");
log.trace("K8sNetdataCollector: doStart(): scheduledFuturesList={}", scheduledFuturesList);
log.debug("K8sNetdataCollector: doStart(): END");
}
private String get(Map<String,Object> map, String key, String defaultValue) {
@ -302,20 +302,19 @@ public class K8sNetdataCollector implements Collector, InitializingBean {
apiVer, urlSuffix, port, aggregation, destination, component);
// Get nodes to scrape
Set nodesToScrape = collectorContext.getNodesWithoutClient();
log.debug("K8sNetdataCollector: collectData(): nodes-to-scrape={}", nodesToScrape);
if (nodesToScrape == null || nodesToScrape.isEmpty()) {
//Set nodesToScrape = collectorContext.getNodesWithoutClient();
String address = System.getenv("NODE_ADDRESS");
log.debug("K8sNetdataCollector: collectData(): Netdata node-to-scrape={}", address);
if (StringUtils.isBlank(address)) {
long endTm = System.currentTimeMillis();
log.debug("K8sNetdataCollector: collectData(): END: No nodes to scrape: duration={}ms", endTm - startTm);
log.debug("K8sNetdataCollector: collectData(): END: No Netdata node to scrape: duration={}ms", endTm - startTm);
return;
}
// Scrape nodes
nodesToScrape.forEach(address -> {
String url = String.format("http://%s:%d%s", address, port, urlSuffix);
log.warn("K8sNetdataCollector: collectData(): Scraping node: {}", url);
collectDataFromNode(apiVer, url, aggregation, destination, component, address!=null ? address.toString() : null);
});
// Scrape Netdata node
String url = String.format("http://%s:%d%s", address, port, urlSuffix);
log.debug("K8sNetdataCollector: collectData(): Scraping Netdata node: {}", url);
collectDataFromNode(apiVer, url, aggregation, destination, component, address!=null ? address.toString() : null);
long endTm = System.currentTimeMillis();
log.debug("K8sNetdataCollector: collectData(): END: duration={}ms", endTm-startTm);