Skip to content

Commit

Permalink
Merge pull request apolloconfig#674 from nobodyiam/reduce-client-dup-log
Browse files Browse the repository at this point in the history
add rate limit control for no config warning
  • Loading branch information
lepdou authored Jul 31, 2017
2 parents dc3c2ba + 328eac8 commit bbca841
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.RateLimiter;


/**
Expand All @@ -31,6 +32,7 @@ public class DefaultConfig extends AbstractConfig implements RepositoryChangeLis
private Properties m_resourceProperties;
private AtomicReference<Properties> m_configProperties;
private ConfigRepository m_configRepository;
private RateLimiter m_warnLogRateLimiter;

/**
* Constructor.
Expand All @@ -43,6 +45,7 @@ public DefaultConfig(String namespace, ConfigRepository configRepository) {
m_resourceProperties = loadFromResource(m_namespace);
m_configRepository = configRepository;
m_configProperties = new AtomicReference<>();
m_warnLogRateLimiter = RateLimiter.create(0.017); // 1 warning log output per minute
initialize();
}

Expand Down Expand Up @@ -84,9 +87,8 @@ public String getProperty(String key, String defaultValue) {
value = (String) m_resourceProperties.get(key);
}

if (value == null && m_configProperties.get() == null) {
logger.warn("Could not load config for namespace {} from Apollo, please check whether the configs are released " +
"in Apollo! Return default value now!", m_namespace);
if (value == null && m_configProperties.get() == null && m_warnLogRateLimiter.tryAcquire()) {
logger.warn("Could not load config for namespace {} from Apollo, please check whether the configs are released in Apollo! Return default value now!", m_namespace);
}

return value == null ? defaultValue : value;
Expand Down

0 comments on commit bbca841

Please sign in to comment.