From 8206c2c923b9369d93b6c24ddf730077a95ec40c Mon Sep 17 00:00:00 2001 From: Bill Gray Date: Mon, 9 May 2016 15:21:29 -0600 Subject: [PATCH] reduce logging on ConfigWatch connection failure fixes gh-181 --- .../cloud/consul/config/ConfigWatch.java | 16 ++++++++++++---- .../config/ConsulPropertySourceLocator.java | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConfigWatch.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConfigWatch.java index 4b7b27e8..a5109761 100644 --- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConfigWatch.java +++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConfigWatch.java @@ -34,6 +34,7 @@ import org.springframework.scheduling.annotation.Scheduled; import lombok.Data; import lombok.extern.apachecommons.CommonsLog; +import org.springframework.util.ReflectionUtils; /** * @author Spencer Gibb @@ -47,6 +48,7 @@ public class ConfigWatch implements Closeable, ApplicationEventPublisherAware { private AtomicBoolean running = new AtomicBoolean(false); private ApplicationEventPublisher publisher; private HashMap consulIndexes = new HashMap<>(); + private Boolean initialized = false; public ConfigWatch(ConsulConfigProperties properties, List contexts, ConsulClient consul) { this.properties = properties; @@ -64,7 +66,7 @@ public class ConfigWatch implements Closeable, ApplicationEventPublisherAware { this.running.compareAndSet(false, true); } - @Scheduled(fixedDelayString = "${spring.cloud.consul.config.watch.delay:100}") + @Scheduled(fixedDelayString = "${spring.cloud.consul.config.watch.delay:1000}") public void watchConfigKeyValues() { if (this.running.get()) { for (String context : this.contexts) { @@ -92,14 +94,20 @@ public class ConfigWatch implements Closeable, ApplicationEventPublisherAware { } } catch (Exception e) { - if (this.properties.isFailFast()) { - log.error("Error initializing listener for context " + context, e); + // only fail fast on the initial query, otherwise just log the error + if (!initialized && this.properties.isFailFast()) { + log.error("Fail fast is set and there was an error reading configuration from consul."); + ReflectionUtils.rethrowRuntimeException(e); } else if (log.isTraceEnabled()) { - log.trace("Failfast is true. Error initializing listener for context " + context, e); + log.trace("Error querying consul Key/Values for context '" + context + "'", e); + } else if (log.isWarnEnabled()) { + // simplified one line log message in the event of an agent failure + log.warn("Error querying consul Key/Values for context '" + context + "'. Message: " + e.getMessage()); } } } } + initialized = true; } @Override diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocator.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocator.java index c1ce00b9..12703867 100644 --- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocator.java +++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocator.java @@ -117,6 +117,7 @@ public class ConsulPropertySourceLocator implements PropertySourceLocator { } } catch (Exception e) { if (this.properties.isFailFast()) { + log.error("Fail fast is set and there was an error reading configuration from consul."); ReflectionUtils.rethrowRuntimeException(e); } else { log.warn("Unable to load consul config from "+ propertySourceContext, e);