Skip to content

Commit

Permalink
Fixed a bug in PrometheusCollector2.checkConfig(). A few changes in l…
Browse files Browse the repository at this point in the history
…og messages. (#31)
  • Loading branch information
ipatini authored Aug 19, 2024
1 parent 4615878 commit a2b540b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ protected synchronized void setClientConfiguration(String configStr) {

// Update collectors' configurations
Map<String, List<Map<String, Serializable>>> collectorConfigs = clientConfiguration.getCollectorConfigurations();
log.debug("collectorConfigs={}", collectorConfigs);
applicationContext.getBean(BaguetteClient.class).getCollectorsList().forEach(collector -> {
List<Map<String, Serializable>> cc = collectorConfigs.get(collector.getName());
if (cc!=null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ private boolean checkConfig(Map<String, Serializable> config) {
String type = configMap.getOrDefault("type", "").toString();
if (! getName().equalsIgnoreCase(type)) errors.add(String.format("Type mismatch. Expected '%s' but found '%s'", getName(), type));

int port = Integer.parseInt( configMap.getOrDefault("port", "0").toString() );
if (port<=0) errors.add("No or invalid port provided: "+port);
int port = Integer.parseInt( configMap.getOrDefault("port", DEFAULT_PROMETHEUS_PORT).toString() );
if (port<=0 || port>=65536) errors.add("Invalid port provided: "+port);

String prometheusMetric = configMap.getOrDefault("metric", "").toString();
if (StringUtils.isBlank(prometheusMetric)) errors.add("No prometheus metric provided");
Expand Down Expand Up @@ -257,7 +257,7 @@ private void scrapeEndpoint(String urlPattern, String prometheusMetric, String d
// Scrape nodes and process responses
nodes.forEach(node -> {
String url = urlPattern.formatted(node);
log.trace("Collectors::{}: scrapeEndpoint: Scraping node: {} -- Endpoint: {}", collectorId, node, url);
log.info("Collectors::{}: scrapeEndpoint: Scraping node: {} -- Endpoint: {}", collectorId, node, url);

// Scrape endpoint
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void afterPropertiesSet() throws Exception {
Instant initDelay = Instant.now().plus(properties.getInitDelay());
Duration period = properties.getPeriod();
taskScheduler.scheduleAtFixedRate(this::doWatch, initDelay, period);
log.info("K8sPodWatcher: Enabled (running every {}sec, init-delay={})", period, properties.getInitDelay());
log.info("K8sPodWatcher: Enabled (running every {}, init-delay={})", period, properties.getInitDelay());
} else {
log.info("K8sPodWatcher: Disabled (to enable set 'k8s-watcher.enable' property or K8S_WATCHER_ENABLED env. var. to true)");
}
Expand Down Expand Up @@ -121,7 +121,7 @@ private void doWatch() {

Set<Serializable> oldPodSet = csc.getClientConfiguration().getNodesWithoutClient();
Set<Serializable> newPodSet = otherPods.stream().map(K8sClient.PodEntry::podIP).collect(Collectors.toSet());
log.trace("K8sPodWatcher: EMS client: {} @{} -- Old pod set: {} -- New pod set: {}", clientId, hostIp, oldPodSet, newPodSet);
log.info("K8sPodWatcher: EMS client: {} @{} -- Old pod set: {} -- New pod set: {}", clientId, hostIp, oldPodSet, newPodSet);
csc.getClientConfiguration().setNodesWithoutClient(newPodSet);
log.trace("K8sPodWatcher: EMS client: {} @{} -- Sending configuration to EMS client", clientId, hostIp);
csc.sendClientConfiguration();
Expand Down

0 comments on commit a2b540b

Please sign in to comment.