From c411b81fd0cabeeaf1b7cbd02563e670a1ccb36d Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sat, 22 Jul 2017 23:11:43 -0700 Subject: [PATCH 01/17] Utilize parameterized logging and remove calls to toString() As suggested in the SLF4J FAQ: https://www.slf4j.org/faq.html#logging_performance parameterized logging can improve the efficiency of logging calls when logging at the specified level is disabled. In addition, per the FAQ: https://www.slf4j.org/faq.html#paramException since SLF4J 1.6.0 it is possible to use parameterized logging and also log an exception/throwable. toString() is called automatically: https://www.slf4j.org/faq.html#string_contents --- .../Archaius2VipAddressResolver.java | 6 ++-- .../java/com/netflix/appinfo/AmazonInfo.java | 2 +- .../Archaius1VipAddressResolver.java | 6 ++-- ...EurekaConfigBasedInstanceInfoProvider.java | 2 +- .../discovery/AbstractAzToRegionMapper.java | 4 +-- .../netflix/discovery/DiscoveryClient.java | 30 +++++++++---------- .../discovery/EurekaUpStatusResolver.java | 4 +-- .../discovery/endpoint/DnsResolver.java | 4 +-- .../discovery/endpoint/EndpointUtils.java | 6 ++-- .../resolver/ReloadingClusterResolver.java | 2 +- .../discovery/util/ThresholdLevelsMetric.java | 2 +- .../com/netflix/eureka/EurekaBootStrap.java | 4 +-- .../com/netflix/eureka/aws/AwsAsgUtil.java | 2 +- .../com/netflix/eureka/aws/Route53Binder.java | 4 +-- .../eureka/cluster/PeerEurekaNodes.java | 4 +-- .../cluster/ReplicationTaskProcessor.java | 5 ++-- .../registry/AbstractInstanceRegistry.java | 4 +-- .../PeerAwareInstanceRegistryImpl.java | 6 ++-- .../eureka/registry/RemoteRegionRegistry.java | 6 ++-- .../eureka/registry/ResponseCacheImpl.java | 4 +-- .../eureka/resources/InstanceResource.java | 18 +++++------ .../eureka/resources/InstancesResource.java | 2 +- .../resources/PeerReplicationResource.java | 4 +-- 23 files changed, 64 insertions(+), 67 deletions(-) diff --git a/eureka-client-archaius2/src/main/java/com/netflix/appinfo/providers/Archaius2VipAddressResolver.java b/eureka-client-archaius2/src/main/java/com/netflix/appinfo/providers/Archaius2VipAddressResolver.java index 3ff1be1190..eb6da9d5fa 100644 --- a/eureka-client-archaius2/src/main/java/com/netflix/appinfo/providers/Archaius2VipAddressResolver.java +++ b/eureka-client-archaius2/src/main/java/com/netflix/appinfo/providers/Archaius2VipAddressResolver.java @@ -36,9 +36,9 @@ public String resolveDeploymentContextBasedVipAddresses(String vipAddressMacro) String key = matcher.group(1); String value = config.getString(key, ""); - logger.debug("att:" + matcher.group()); - logger.debug(", att key:" + key); - logger.debug(", att value:" + value); + logger.debug("att:{}", matcher.group()); + logger.debug(", att key:{}", key); + logger.debug(", att value:{}", value); logger.debug(""); result = result.replaceAll("\\$\\{" + key + "\\}", value); matcher = VIP_ATTRIBUTES_PATTERN.matcher(result); diff --git a/eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java b/eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java index c4d81730f2..32bd2a733e 100644 --- a/eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java +++ b/eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java @@ -210,7 +210,7 @@ public AmazonInfo autoBuild(String namespace) { break; } catch (Throwable e) { if (config.shouldLogAmazonMetadataErrors()) { - logger.warn("Cannot get the value for the metadata key :" + key + " Reason :", e); + logger.warn("Cannot get the value for the metadata key: {} Reason :", key, e); } if (numOfRetries >= 0) { try { diff --git a/eureka-client/src/main/java/com/netflix/appinfo/providers/Archaius1VipAddressResolver.java b/eureka-client/src/main/java/com/netflix/appinfo/providers/Archaius1VipAddressResolver.java index 477e1779bc..860cf4f57e 100644 --- a/eureka-client/src/main/java/com/netflix/appinfo/providers/Archaius1VipAddressResolver.java +++ b/eureka-client/src/main/java/com/netflix/appinfo/providers/Archaius1VipAddressResolver.java @@ -26,9 +26,9 @@ public String resolveDeploymentContextBasedVipAddresses(String vipAddressMacro) String key = matcher.group(1); String value = DynamicPropertyFactory.getInstance().getStringProperty(key, "").get(); - logger.debug("att:" + matcher.group()); - logger.debug(", att key:" + key); - logger.debug(", att value:" + value); + logger.debug("att:{}", matcher.group()); + logger.debug(", att key:{}", key); + logger.debug(", att value:{}", value); logger.debug(""); result = result.replaceAll("\\$\\{" + key + "\\}", value); matcher = VIP_ATTRIBUTES_PATTERN.matcher(result); diff --git a/eureka-client/src/main/java/com/netflix/appinfo/providers/EurekaConfigBasedInstanceInfoProvider.java b/eureka-client/src/main/java/com/netflix/appinfo/providers/EurekaConfigBasedInstanceInfoProvider.java index 5e1e64c133..61305185ad 100644 --- a/eureka-client/src/main/java/com/netflix/appinfo/providers/EurekaConfigBasedInstanceInfoProvider.java +++ b/eureka-client/src/main/java/com/netflix/appinfo/providers/EurekaConfigBasedInstanceInfoProvider.java @@ -104,7 +104,7 @@ public synchronized InstanceInfo get() { // Start off with the STARTING state to avoid traffic if (!config.isInstanceEnabledOnit()) { InstanceStatus initialStatus = InstanceStatus.STARTING; - LOG.info("Setting initial instance status as: " + initialStatus); + LOG.info("Setting initial instance status as: {}", initialStatus); builder.setStatus(initialStatus); } else { LOG.info("Setting initial instance status as: {}. This may be too early for the instance to advertise " diff --git a/eureka-client/src/main/java/com/netflix/discovery/AbstractAzToRegionMapper.java b/eureka-client/src/main/java/com/netflix/discovery/AbstractAzToRegionMapper.java index 0870f155b4..8dcd32fd10 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/AbstractAzToRegionMapper.java +++ b/eureka-client/src/main/java/com/netflix/discovery/AbstractAzToRegionMapper.java @@ -59,8 +59,8 @@ public synchronized void setRegionsToFetch(String[] regionsToFetch) { if (null == availabilityZones || (availabilityZones.size() == 1 && availabilityZones.contains(DEFAULT_ZONE)) || availabilityZones.isEmpty()) { - logger.info("No availability zone information available for remote region: " + remoteRegion - + ". Now checking in the default mapping."); + logger.info("No availability zone information available for remote region: {}" + + ". Now checking in the default mapping.", remoteRegion); if (defaultRegionVsAzMap.containsKey(remoteRegion)) { Collection defaultAvailabilityZones = defaultRegionVsAzMap.get(remoteRegion); for (String defaultAvailabilityZone : defaultAvailabilityZones) { diff --git a/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java b/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java index be7b8e1f22..f546c7bbc5 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java +++ b/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java @@ -276,7 +276,7 @@ public synchronized BackupRegistry get() { if (null != backupRegistryClassName) { try { backupRegistryInstance = (BackupRegistry) Class.forName(backupRegistryClassName).newInstance(); - logger.info("Enabled backup registry of type " + backupRegistryInstance.getClass()); + logger.info("Enabled backup registry of type {}", backupRegistryInstance.getClass()); } catch (InstantiationException e) { logger.error("Error instantiating BackupRegistry.", e); } catch (IllegalAccessException e) { @@ -809,12 +809,12 @@ public Applications getApplications(String serviceUrl) { ? eurekaTransport.queryClient.getApplications() : eurekaTransport.queryClient.getVip(clientConfig.getRegistryRefreshSingleVipAddress()); if (response.getStatusCode() == 200) { - logger.debug(PREFIX + appPathIdentifier + " - refresh status: " + response.getStatusCode()); + logger.debug(PREFIX + "{} - refresh status: {}", appPathIdentifier, response.getStatusCode()); return response.getEntity(); } - logger.error(PREFIX + appPathIdentifier + " - was unable to refresh its cache! status = " + response.getStatusCode()); + logger.error(PREFIX + "{} - was unable to refresh its cache! status = {}", appPathIdentifier, response.getStatusCode()); } catch (Throwable th) { - logger.error(PREFIX + appPathIdentifier + " - was unable to refresh its cache! status = " + th.getMessage(), th); + logger.error(PREFIX + "{} - was unable to refresh its cache! status = {}", appPathIdentifier, th.getMessage(), th); } return null; } @@ -823,17 +823,15 @@ public Applications getApplications(String serviceUrl) { * Register with the eureka service by making the appropriate REST call. */ boolean register() throws Throwable { - logger.info(PREFIX + appPathIdentifier + ": registering service..."); + logger.info(PREFIX + "{}: registering service...", appPathIdentifier); EurekaHttpResponse httpResponse; try { httpResponse = eurekaTransport.registrationClient.register(instanceInfo); } catch (Exception e) { - logger.warn("{} - registration failed {}", PREFIX + appPathIdentifier, e.getMessage(), e); + logger.warn(PREFIX + "{} - registration failed {}", appPathIdentifier, e.getMessage(), e); throw e; } - if (logger.isInfoEnabled()) { - logger.info("{} - registration status: {}", PREFIX + appPathIdentifier, httpResponse.getStatusCode()); - } + logger.info(PREFIX + "{} - registration status: {}", appPathIdentifier, httpResponse.getStatusCode()); return httpResponse.getStatusCode() == 204; } @@ -844,7 +842,7 @@ boolean renew() { EurekaHttpResponse httpResponse; try { httpResponse = eurekaTransport.registrationClient.sendHeartBeat(instanceInfo.getAppName(), instanceInfo.getId(), instanceInfo, null); - logger.debug("{} - Heartbeat status: {}", PREFIX + appPathIdentifier, httpResponse.getStatusCode()); + logger.debug(PREFIX + "{} - Heartbeat status: {}", appPathIdentifier, httpResponse.getStatusCode()); if (httpResponse.getStatusCode() == 404) { REREGISTER_COUNTER.increment(); logger.info("{} - Re-registering apps/{}", PREFIX + appPathIdentifier, instanceInfo.getAppName()); @@ -857,7 +855,7 @@ boolean renew() { } return httpResponse.getStatusCode() == 200; } catch (Throwable e) { - logger.error("{} - was unable to send heartbeat!", PREFIX + appPathIdentifier, e); + logger.error(PREFIX + "{} - was unable to send heartbeat!", appPathIdentifier, e); return false; } } @@ -921,9 +919,9 @@ void unregister() { try { logger.info("Unregistering ..."); EurekaHttpResponse httpResponse = eurekaTransport.registrationClient.cancel(instanceInfo.getAppName(), instanceInfo.getId()); - logger.info(PREFIX + appPathIdentifier + " - deregister status: " + httpResponse.getStatusCode()); + logger.info(PREFIX + "{} - deregister status: {}", appPathIdentifier, httpResponse.getStatusCode()); } catch (Exception e) { - logger.error(PREFIX + appPathIdentifier + " - de-registration failed" + e.getMessage(), e); + logger.error(PREFIX + "{} - de-registration failed{}", appPathIdentifier, e.getMessage(), e); } } } @@ -969,7 +967,7 @@ private boolean fetchRegistry(boolean forceFullRegistryFetch) { applications.setAppsHashCode(applications.getReconcileHashCode()); logTotalInstances(); } catch (Throwable e) { - logger.error(PREFIX + appPathIdentifier + " - was unable to refresh its cache! status = " + e.getMessage(), e); + logger.error(PREFIX + "{} - was unable to refresh its cache! status = {}", appPathIdentifier, e.getMessage(), e); return false; } finally { if (tracer != null) { @@ -1261,7 +1259,7 @@ private void initScheduledTasks() { if (clientConfig.shouldRegisterWithEureka()) { int renewalIntervalInSecs = instanceInfo.getLeaseInfo().getRenewalIntervalInSecs(); int expBackOffBound = clientConfig.getHeartbeatExecutorExponentialBackOffBound(); - logger.info("Starting heartbeat executor: " + "renew interval is: " + renewalIntervalInSecs); + logger.info("Starting heartbeat executor: " + "renew interval is: {}", renewalIntervalInSecs); // Heartbeat timer scheduler.schedule( @@ -1487,7 +1485,7 @@ void refreshRegistry() { allAppsHashCodes.append(entry.getValue().getAppsHashCode()); } logger.debug("Completed cache refresh task for discovery. All Apps hash code is {} ", - allAppsHashCodes.toString()); + allAppsHashCodes); } } catch (Throwable e) { logger.error("Cannot fetch registry from server", e); diff --git a/eureka-client/src/main/java/com/netflix/discovery/EurekaUpStatusResolver.java b/eureka-client/src/main/java/com/netflix/discovery/EurekaUpStatusResolver.java index 31a717de02..067dfca958 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/EurekaUpStatusResolver.java +++ b/eureka-client/src/main/java/com/netflix/discovery/EurekaUpStatusResolver.java @@ -41,7 +41,7 @@ public EurekaUpStatusResolver(EurekaClient client, EventBus eventBus) { @Subscribe public void onStatusChange(StatusChangeEvent event) { - LOG.info("Eureka status changed from " + event.getPreviousStatus() + " to " + event.getStatus()); + LOG.info("Eureka status changed from {} to {}", event.getPreviousStatus(), event.getStatus()); currentStatus = event.getStatus(); counter.incrementAndGet(); } @@ -52,7 +52,7 @@ public void init() { // Must set the initial status currentStatus = client.getInstanceRemoteStatus(); - LOG.info("Initial status set to " + currentStatus); + LOG.info("Initial status set to {}", currentStatus); eventBus.registerSubscriber(this); } catch (InvalidSubscriberException e) { LOG.error("Error registring for discovery status change events.", e); diff --git a/eureka-client/src/main/java/com/netflix/discovery/endpoint/DnsResolver.java b/eureka-client/src/main/java/com/netflix/discovery/endpoint/DnsResolver.java index 0efb06dd3f..df89a30baf 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/endpoint/DnsResolver.java +++ b/eureka-client/src/main/java/com/netflix/discovery/endpoint/DnsResolver.java @@ -81,7 +81,7 @@ public static String resolve(String originalHost) { } while (targetHost == null); return targetHost; } catch (NamingException e) { - logger.warn("Cannot resolve eureka server address " + currentHost + "; returning original value " + originalHost, e); + logger.warn("Cannot resolve eureka server address {}; returning original value {}", currentHost, originalHost, e); return originalHost; } } @@ -109,7 +109,7 @@ public static List resolveARecord(String rootDomainName) { return result; } } catch (Exception e) { - logger.warn("Cannot load A-record for eureka server address " + rootDomainName, e); + logger.warn("Cannot load A-record for eureka server address {}", rootDomainName, e); return null; } return null; diff --git a/eureka-client/src/main/java/com/netflix/discovery/endpoint/EndpointUtils.java b/eureka-client/src/main/java/com/netflix/discovery/endpoint/EndpointUtils.java index d5ca6d261f..e2e24f0b44 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/endpoint/EndpointUtils.java +++ b/eureka-client/src/main/java/com/netflix/discovery/endpoint/EndpointUtils.java @@ -117,8 +117,8 @@ public static List getServiceUrlsFromDNS(EurekaClientConfig clientConfig } } if (zoneFound) { - Object[] args = {zones, instanceZone, zoneIndex}; - logger.debug("The zone index from the list {} that matches the instance zone {} is {}", args); + logger.debug("The zone index from the list {} that matches the instance zone {} is {}", + zones, instanceZone, zoneIndex); break; } zoneIndex++; @@ -362,7 +362,7 @@ private static int getZoneOffset(String myZone, boolean preferSameZone, String[] } } logger.warn("DISCOVERY: Could not pick a zone based on preferred zone settings. My zone - {}," + - " preferSameZone- {}. Defaulting to " + availZones[0], myZone, preferSameZone); + " preferSameZone - {}. Defaulting to {}", myZone, preferSameZone, availZones[0]); return 0; } diff --git a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/ReloadingClusterResolver.java b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/ReloadingClusterResolver.java index 3bec61258a..ed1ce33f90 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/ReloadingClusterResolver.java +++ b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/ReloadingClusterResolver.java @@ -109,7 +109,7 @@ public List getClusterEndpoints() { } catch (Exception e) { this.currentReloadIntervalMs = Math.min(maxReloadIntervalMs, currentReloadIntervalMs * 2); logger.warn("Cluster resolve error; keeping the current Eureka endpoints; next reload in " - + currentReloadIntervalMs / 1000 + "[sec]", e); + + "{}[sec]", currentReloadIntervalMs / 1000, e); } } return delegateRef.get().getClusterEndpoints(); diff --git a/eureka-client/src/main/java/com/netflix/discovery/util/ThresholdLevelsMetric.java b/eureka-client/src/main/java/com/netflix/discovery/util/ThresholdLevelsMetric.java index d3e0227581..c3bcbfa73d 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/util/ThresholdLevelsMetric.java +++ b/eureka-client/src/main/java/com/netflix/discovery/util/ThresholdLevelsMetric.java @@ -52,7 +52,7 @@ public ThresholdLevelsMetric(Object owner, String prefix, long[] levels) { try { DefaultMonitorRegistry.getInstance().register(gauges[i]); } catch (Throwable e) { - logger.warn("Cannot register metric " + name, e); + logger.warn("Cannot register metric {}", name, e); } } } diff --git a/eureka-core/src/main/java/com/netflix/eureka/EurekaBootStrap.java b/eureka-core/src/main/java/com/netflix/eureka/EurekaBootStrap.java index e5fcbab657..d123f78ee1 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/EurekaBootStrap.java +++ b/eureka-core/src/main/java/com/netflix/eureka/EurekaBootStrap.java @@ -239,7 +239,7 @@ protected PeerEurekaNodes getPeerEurekaNodes(PeerAwareInstanceRegistry registry, @Override public void contextDestroyed(ServletContextEvent event) { try { - logger.info("{} Shutting down Eureka Server..", new Date().toString()); + logger.info("{} Shutting down Eureka Server..", new Date()); ServletContext sc = event.getServletContext(); sc.removeAttribute(EurekaServerContext.class.getName()); @@ -249,7 +249,7 @@ public void contextDestroyed(ServletContextEvent event) { } catch (Throwable e) { logger.error("Error shutting down eureka", e); } - logger.info("{} Eureka Service is now shutdown...", new Date().toString()); + logger.info("{} Eureka Service is now shutdown...", new Date()); } /** diff --git a/eureka-core/src/main/java/com/netflix/eureka/aws/AwsAsgUtil.java b/eureka-core/src/main/java/com/netflix/eureka/aws/AwsAsgUtil.java index bf1bfeef4a..11607f1ea5 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/aws/AwsAsgUtil.java +++ b/eureka-core/src/main/java/com/netflix/eureka/aws/AwsAsgUtil.java @@ -267,7 +267,7 @@ private Credentials initializeStsSession(String asgAccount) { } private AutoScalingGroup retrieveAutoScalingGroupCrossAccount(String asgAccount, String asgName) { - logger.debug("Getting cross account ASG for asgName: " + asgName + ", asgAccount: " + asgAccount); + logger.debug("Getting cross account ASG for asgName: {}, asgAccount: {}", asgName, asgAccount); Credentials credentials = stsCredentials.get(asgAccount); diff --git a/eureka-core/src/main/java/com/netflix/eureka/aws/Route53Binder.java b/eureka-core/src/main/java/com/netflix/eureka/aws/Route53Binder.java index de1c8139ca..3f4469a01b 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/aws/Route53Binder.java +++ b/eureka-core/src/main/java/com/netflix/eureka/aws/Route53Binder.java @@ -154,7 +154,7 @@ private List toDomains(List ec2Urls) { try { domains.add(extractDomain(url)); } catch(MalformedURLException e) { - logger.error("Invalid url " + url, e); + logger.error("Invalid url {}", url, e); } } return domains; @@ -191,7 +191,7 @@ private boolean executeChangeWithRetry(Change change, HostedZone hostedZone) thr } if (firstError != null) { - logger.error("Cannot execute change " + change + " " + firstError, firstError); + logger.error("Cannot execute change {} {}", change, firstError, firstError); } return false; diff --git a/eureka-core/src/main/java/com/netflix/eureka/cluster/PeerEurekaNodes.java b/eureka-core/src/main/java/com/netflix/eureka/cluster/PeerEurekaNodes.java index e06508c7b9..45d81894a8 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/cluster/PeerEurekaNodes.java +++ b/eureka-core/src/main/java/com/netflix/eureka/cluster/PeerEurekaNodes.java @@ -107,7 +107,7 @@ public void run() { throw new IllegalStateException(e); } for (PeerEurekaNode node : peerEurekaNodes) { - logger.info("Replica node URL: " + node.getServiceUrl()); + logger.info("Replica node URL: {}", node.getServiceUrl()); } } @@ -257,7 +257,7 @@ public static String hostFromUrl(String url) { try { uri = new URI(url); } catch (URISyntaxException e) { - logger.warn("Cannot parse service URI " + url, e); + logger.warn("Cannot parse service URI {}", url, e); return null; } return uri.getHost(); diff --git a/eureka-core/src/main/java/com/netflix/eureka/cluster/ReplicationTaskProcessor.java b/eureka-core/src/main/java/com/netflix/eureka/cluster/ReplicationTaskProcessor.java index 5e7337b6b7..9c3fabe290 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/cluster/ReplicationTaskProcessor.java +++ b/eureka-core/src/main/java/com/netflix/eureka/cluster/ReplicationTaskProcessor.java @@ -57,7 +57,8 @@ public ProcessingResult process(ReplicationTask task) { logNetworkErrorSample(task, e); return ProcessingResult.TransientError; } else { - logger.error(peerId + ": " + task.getTaskName() + "Not re-trying this exception because it does not seem to be a network exception", e); + logger.error("{}: {} Not re-trying this exception because it does not seem to be a network exception", + peerId, task.getTaskName(), e); return ProcessingResult.PermanentError; } } @@ -135,7 +136,7 @@ private void handleBatchResponse(ReplicationTask task, ReplicationInstanceRespon try { task.handleFailure(response.getStatusCode(), response.getResponseEntity()); } catch (Throwable e) { - logger.error("Replication task " + task.getTaskName() + " error handler failure", e); + logger.error("Replication task {} error handler failure", task.getTaskName(), e); } } diff --git a/eureka-core/src/main/java/com/netflix/eureka/registry/AbstractInstanceRegistry.java b/eureka-core/src/main/java/com/netflix/eureka/registry/AbstractInstanceRegistry.java index 149648d8df..fccf7a0adf 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/registry/AbstractInstanceRegistry.java +++ b/eureka-core/src/main/java/com/netflix/eureka/registry/AbstractInstanceRegistry.java @@ -874,8 +874,8 @@ public Applications getApplicationDeltas() { try { write.lock(); Iterator iter = this.recentlyChangedQueue.iterator(); - logger.debug("The number of elements in the delta queue is :" - + this.recentlyChangedQueue.size()); + logger.debug("The number of elements in the delta queue is : {}", + this.recentlyChangedQueue.size()); while (iter.hasNext()) { Lease lease = iter.next().getLeaseInfo(); InstanceInfo instanceInfo = lease.getHolder(); diff --git a/eureka-core/src/main/java/com/netflix/eureka/registry/PeerAwareInstanceRegistryImpl.java b/eureka-core/src/main/java/com/netflix/eureka/registry/PeerAwareInstanceRegistryImpl.java index ac5cf8a57c..f04863f74c 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/registry/PeerAwareInstanceRegistryImpl.java +++ b/eureka-core/src/main/java/com/netflix/eureka/registry/PeerAwareInstanceRegistryImpl.java @@ -239,8 +239,8 @@ public void openForTraffic(ApplicationInfoManager applicationInfoManager, int co this.expectedNumberOfRenewsPerMin = count * 2; this.numberOfRenewsPerMinThreshold = (int) (this.expectedNumberOfRenewsPerMin * serverConfig.getRenewalPercentThreshold()); - logger.info("Got " + count + " instances from neighboring DS node"); - logger.info("Renew threshold is: " + numberOfRenewsPerMinThreshold); + logger.info("Got {} instances from neighboring DS node", count); + logger.info("Renew threshold is: {}", numberOfRenewsPerMinThreshold); this.startupTime = System.currentTimeMillis(); if (count > 0) { this.peerInstancesTransferEmptyOnStartup = false; @@ -311,7 +311,7 @@ private void primeAwsReplicas(ApplicationInfoManager applicationInfoManager) { } areAllPeerNodesPrimed = true; } catch (Throwable e) { - logger.error("Could not contact " + peerHostName, e); + logger.error("Could not contact {}", peerHostName, e); try { Thread.sleep(PRIME_PEER_NODES_RETRY_MS); } catch (InterruptedException e1) { diff --git a/eureka-core/src/main/java/com/netflix/eureka/registry/RemoteRegionRegistry.java b/eureka-core/src/main/java/com/netflix/eureka/registry/RemoteRegionRegistry.java index ae9f5f067e..e2027d70e6 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/registry/RemoteRegionRegistry.java +++ b/eureka-core/src/main/java/com/netflix/eureka/registry/RemoteRegionRegistry.java @@ -233,7 +233,7 @@ private boolean fetchRegistry() { } logTotalInstances(); } catch (Throwable e) { - logger.error("Unable to fetch registry information from the remote registry " + this.remoteRegionURL.toString(), e); + logger.error("Unable to fetch registry information from the remote registry {}", this.remoteRegionURL, e); return false; } finally { if (tracer != null) { @@ -392,7 +392,7 @@ private Applications fetchRemoteRegistry(boolean delta) { } logger.warn("Cannot get the data from {} : {}", this.remoteRegionURL, httpStatus); } catch (Throwable t) { - logger.error("Can't get a response from " + this.remoteRegionURL, t); + logger.error("Can't get a response from {}", this.remoteRegionURL, t); } } else { ClientResponse response = null; @@ -409,7 +409,7 @@ private Applications fetchRemoteRegistry(boolean delta) { } logger.warn("Cannot get the data from {} : {}", this.remoteRegionURL, httpStatus); } catch (Throwable t) { - logger.error("Can't get a response from " + this.remoteRegionURL, t); + logger.error("Can't get a response from {}", this.remoteRegionURL, t); } finally { closeResponse(response); } diff --git a/eureka-core/src/main/java/com/netflix/eureka/registry/ResponseCacheImpl.java b/eureka-core/src/main/java/com/netflix/eureka/registry/ResponseCacheImpl.java index a445a0f632..d716484f4f 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/registry/ResponseCacheImpl.java +++ b/eureka-core/src/main/java/com/netflix/eureka/registry/ResponseCacheImpl.java @@ -356,7 +356,7 @@ Value getValue(final Key key, boolean useReadOnlyCache) { payload = readWriteCacheMap.get(key); } } catch (Throwable t) { - logger.error("Cannot get value for key :" + key, t); + logger.error("Cannot get value for key : {}", key, t); } return payload; } @@ -439,7 +439,7 @@ private Value generatePayload(Key key) { payload = getPayLoad(key, getApplicationsForVip(key, registry)); break; default: - logger.error("Unidentified entity type: " + key.getEntityType() + " found in the cache key."); + logger.error("Unidentified entity type: {} found in the cache key.", key.getEntityType()); payload = ""; break; } diff --git a/eureka-core/src/main/java/com/netflix/eureka/resources/InstanceResource.java b/eureka-core/src/main/java/com/netflix/eureka/resources/InstanceResource.java index a764f3a4a5..7d9aa36465 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/resources/InstanceResource.java +++ b/eureka-core/src/main/java/com/netflix/eureka/resources/InstanceResource.java @@ -131,7 +131,7 @@ public Response renewLease( } else { response = Response.ok().build(); } - logger.debug("Found (Renew): {} - {}; reply status={}" + app.getName(), id, response.getStatus()); + logger.debug("Found (Renew): {} - {}; reply status={}", app.getName(), id, response.getStatus()); return response; } @@ -171,12 +171,10 @@ public Response statusUpdate( "true".equals(isReplication)); if (isSuccess) { - logger.info("Status updated: " + app.getName() + " - " + id - + " - " + newStatus); + logger.info("Status updated: {} - {} - {}", app.getName(), id, newStatus); return Response.ok().build(); } else { - logger.warn("Unable to update status: " + app.getName() + " - " - + id + " - " + newStatus); + logger.warn("Unable to update status: {} - {} - {}", app.getName(), id, newStatus); return Response.serverError().build(); } } catch (Throwable e) { @@ -215,10 +213,10 @@ public Response deleteStatusUpdate( newStatus, lastDirtyTimestamp, "true".equals(isReplication)); if (isSuccess) { - logger.info("Status override removed: " + app.getName() + " - " + id); + logger.info("Status override removed: {} - {}", app.getName(), id); return Response.ok().build(); } else { - logger.warn("Unable to remove status override: " + app.getName() + " - " + id); + logger.warn("Unable to remove status override: {} - {}", app.getName(), id); return Response.serverError().build(); } } catch (Throwable e) { @@ -261,7 +259,7 @@ public Response updateMetadata(@Context UriInfo uriInfo) { registry.register(instanceInfo, false); return Response.ok().build(); } catch (Throwable e) { - logger.error("Error updating metadata for instance " + id, e); + logger.error("Error updating metadata for instance {}", id, e); return Response.serverError().build(); } @@ -283,10 +281,10 @@ public Response cancelLease( "true".equals(isReplication)); if (isSuccess) { - logger.debug("Found (Cancel): " + app.getName() + " - " + id); + logger.debug("Found (Cancel): {} - {}", app.getName(), id); return Response.ok().build(); } else { - logger.info("Not Found (Cancel): " + app.getName() + " - " + id); + logger.info("Not Found (Cancel): {} - {}", app.getName(), id); return Response.status(Status.NOT_FOUND).build(); } } diff --git a/eureka-core/src/main/java/com/netflix/eureka/resources/InstancesResource.java b/eureka-core/src/main/java/com/netflix/eureka/resources/InstancesResource.java index 6df52ce6d3..18b60340cd 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/resources/InstancesResource.java +++ b/eureka-core/src/main/java/com/netflix/eureka/resources/InstancesResource.java @@ -65,7 +65,7 @@ public Response getById(@PathParam("version") String version, if (list != null && list.size() > 0) { return Response.ok(list.get(0)).build(); } else { - logger.info("Not Found: " + id); + logger.info("Not Found: {}", id); return Response.status(Status.NOT_FOUND).build(); } } diff --git a/eureka-core/src/main/java/com/netflix/eureka/resources/PeerReplicationResource.java b/eureka-core/src/main/java/com/netflix/eureka/resources/PeerReplicationResource.java index eb206fa2da..9d64249fcf 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/resources/PeerReplicationResource.java +++ b/eureka-core/src/main/java/com/netflix/eureka/resources/PeerReplicationResource.java @@ -85,8 +85,8 @@ public Response batchReplication(ReplicationList replicationList) { batchResponse.addResponse(dispatch(instanceInfo)); } catch (Exception e) { batchResponse.addResponse(new ReplicationInstanceResponse(Status.INTERNAL_SERVER_ERROR.getStatusCode(), null)); - logger.error(instanceInfo.getAction() + " request processing failed for batch item " - + instanceInfo.getAppName() + '/' + instanceInfo.getId(), e); + logger.error("{} request processing failed for batch item {}/{}", + instanceInfo.getAction(), instanceInfo.getAppName(), instanceInfo.getId(), e); } } return Response.ok(batchResponse).build(); From 7561954d0e23b7c474ad835e11e0441a9757b394 Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sat, 22 Jul 2017 23:13:00 -0700 Subject: [PATCH 02/17] Fix misspellings --- .../src/main/java/com/netflix/eureka/aws/EIPManager.java | 2 +- .../java/com/netflix/eureka/registry/RemoteRegionRegistry.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eureka-core/src/main/java/com/netflix/eureka/aws/EIPManager.java b/eureka-core/src/main/java/com/netflix/eureka/aws/EIPManager.java index cf5fd77f9f..64a95dc2ad 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/aws/EIPManager.java +++ b/eureka-core/src/main/java/com/netflix/eureka/aws/EIPManager.java @@ -62,7 +62,7 @@ * *

* This binding mechanism gravitates towards one eureka server per zone for - * resilience.Atleast one elastic ip should be slotted for each eureka server in + * resilience. At least one elastic ip should be slotted for each eureka server in * a zone. If more than eureka server is launched per zone and there are not * enough elastic ips slotted, the server tries to pick a free EIP slotted for other * zones and if it still cannot find a free EIP, waits and keeps trying. diff --git a/eureka-core/src/main/java/com/netflix/eureka/registry/RemoteRegionRegistry.java b/eureka-core/src/main/java/com/netflix/eureka/registry/RemoteRegionRegistry.java index e2027d70e6..b651acf1df 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/registry/RemoteRegionRegistry.java +++ b/eureka-core/src/main/java/com/netflix/eureka/registry/RemoteRegionRegistry.java @@ -420,7 +420,7 @@ private Applications fetchRemoteRegistry(boolean delta) { /** * Reconciles the delta information fetched to see if the hashcodes match. * - * @param delta - the delta information fetched previously for reconcililation. + * @param delta - the delta information fetched previously for reconciliation. * @param reconcileHashCode - the hashcode for comparison. * @return - response * @throws Throwable From f7d01cbf70d553a449583ef6cf6f3d1ae591ed39 Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sat, 22 Jul 2017 23:15:12 -0700 Subject: [PATCH 03/17] Correct an SLF4J logger call Add one missing '{}'. --- .../com/netflix/eureka/aws/ElasticNetworkInterfaceBinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eureka-core/src/main/java/com/netflix/eureka/aws/ElasticNetworkInterfaceBinder.java b/eureka-core/src/main/java/com/netflix/eureka/aws/ElasticNetworkInterfaceBinder.java index 94f9a6394c..f8893426ad 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/aws/ElasticNetworkInterfaceBinder.java +++ b/eureka-core/src/main/java/com/netflix/eureka/aws/ElasticNetworkInterfaceBinder.java @@ -168,7 +168,7 @@ public Integer apply(NetworkInterface networkInterface) { ); if (result.getNetworkInterfaces().isEmpty()) { - logger.info("No ip is free to be associated with this instance. Candidate ips are: {} for zone: ", ips, myZone); + logger.info("No ip is free to be associated with this instance. Candidate ips are: {} for zone: {}", ips, myZone); } else { NetworkInterface selected = ipsOrder.min(result.getNetworkInterfaces()); ec2Service.attachNetworkInterface( From b6c97d95600b1bc17bc7116c56ab601ceeed5808 Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sat, 22 Jul 2017 23:18:11 -0700 Subject: [PATCH 04/17] Remove some redundant isDebugEnabled() checks SLF4J already performs these checks. --- .../discovery/shared/resolver/StaticClusterResolver.java | 4 +--- .../discovery/shared/resolver/aws/ConfigClusterResolver.java | 4 +--- .../shared/resolver/aws/ZoneAffinityClusterResolver.java | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/StaticClusterResolver.java b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/StaticClusterResolver.java index 23730d9eca..a978361fcd 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/StaticClusterResolver.java +++ b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/StaticClusterResolver.java @@ -43,9 +43,7 @@ public StaticClusterResolver(String region, T... eurekaEndpoints) { public StaticClusterResolver(String region, List eurekaEndpoints) { this.eurekaEndpoints = eurekaEndpoints; this.region = region; - if (logger.isDebugEnabled()) { - logger.debug("Fixed resolver configuration: {}", eurekaEndpoints); - } + logger.debug("Fixed resolver configuration: {}", eurekaEndpoints); } @Override diff --git a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/aws/ConfigClusterResolver.java b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/aws/ConfigClusterResolver.java index 14bbfab80e..0bc9fcaf54 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/aws/ConfigClusterResolver.java +++ b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/aws/ConfigClusterResolver.java @@ -86,9 +86,7 @@ private List getClusterEndpointsFromConfig() { } } - if (logger.isDebugEnabled()) { - logger.debug("Config resolved to {}", endpoints); - } + logger.debug("Config resolved to {}", endpoints); if (endpoints.isEmpty()) { logger.error("Cannot resolve to any endpoints from provided configuration: {}", serviceUrls); diff --git a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/aws/ZoneAffinityClusterResolver.java b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/aws/ZoneAffinityClusterResolver.java index 5d5dbff8f6..3bdf030975 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/aws/ZoneAffinityClusterResolver.java +++ b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/aws/ZoneAffinityClusterResolver.java @@ -63,9 +63,7 @@ public List getClusterEndpoints() { Collections.reverse(randomizedList); } - if (logger.isDebugEnabled()) { - logger.debug("Local zone={}; resolved to: {}", myZone, randomizedList); - } + logger.debug("Local zone={}; resolved to: {}", myZone, randomizedList); return randomizedList; } From 44d1419bb0e689b9ba99f2837e2789054dc6783c Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sun, 20 Aug 2017 18:19:51 -0400 Subject: [PATCH 05/17] Delete malformed background-color CSS style --- eureka-resources/src/main/resources/css/main.css | 1 - 1 file changed, 1 deletion(-) diff --git a/eureka-resources/src/main/resources/css/main.css b/eureka-resources/src/main/resources/css/main.css index 45177d1db4..b65ad65e1d 100644 --- a/eureka-resources/src/main/resources/css/main.css +++ b/eureka-resources/src/main/resources/css/main.css @@ -146,7 +146,6 @@ tr.odd { span.hlist { padding-right: 10px; margin-right: 10px; - #background-color: #ffffcc; border-right: solid 2px #224499; } From d3f490cf809dbde6146586745d6853691eb8c4e1 Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sun, 20 Aug 2017 18:20:23 -0400 Subject: [PATCH 06/17] Remove a redundant isDebugEnabled() check --- .../com/netflix/eureka/transport/JerseyReplicationClient.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/eureka-core/src/main/java/com/netflix/eureka/transport/JerseyReplicationClient.java b/eureka-core/src/main/java/com/netflix/eureka/transport/JerseyReplicationClient.java index c1980d4065..71399339da 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/transport/JerseyReplicationClient.java +++ b/eureka-core/src/main/java/com/netflix/eureka/transport/JerseyReplicationClient.java @@ -78,9 +78,7 @@ public EurekaHttpResponse sendHeartBeat(String appName, String id, } return anEurekaHttpResponse(response.getStatus(), infoFromPeer).type(MediaType.APPLICATION_JSON_TYPE).build(); } finally { - if (logger.isDebugEnabled()) { - logger.debug("[heartbeat] Jersey HTTP PUT {}; statusCode={}", urlPath, response == null ? "N/A" : response.getStatus()); - } + logger.debug("[heartbeat] Jersey HTTP PUT {}; statusCode={}", urlPath, response == null ? "N/A" : response.getStatus()); if (response != null) { response.close(); } From ad81a1140f351ec19165cb94d5aa668cfc08a932 Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sun, 20 Aug 2017 18:21:16 -0400 Subject: [PATCH 07/17] Utilize parameterized logging As suggested in the SLF4J FAQ: https://www.slf4j.org/faq.html#logging_performance .. parameterized logging can improve the efficiency of logger calls when logging at the specified level is disabled. According to the Constant Expressions section of the JLS, enum variants are unfortunately not constant, and thus this is actually a string concatenation. This change was suggested by SLF4J Helper for NetBeans IDE: http://plugins.netbeans.org/plugin/72557/ --- .../java/com/netflix/appinfo/RefreshableAmazonInfoProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eureka-client/src/main/java/com/netflix/appinfo/RefreshableAmazonInfoProvider.java b/eureka-client/src/main/java/com/netflix/appinfo/RefreshableAmazonInfoProvider.java index 1501e1f5aa..315da28177 100644 --- a/eureka-client/src/main/java/com/netflix/appinfo/RefreshableAmazonInfoProvider.java +++ b/eureka-client/src/main/java/com/netflix/appinfo/RefreshableAmazonInfoProvider.java @@ -45,7 +45,7 @@ private static AmazonInfo init(AmazonInfoConfig amazonInfoConfig, FallbackAddres .newBuilder() .withAmazonInfoConfig(amazonInfoConfig) .autoBuild(amazonInfoConfig.getNamespace()); - logger.info("Datacenter is: " + DataCenterInfo.Name.Amazon); + logger.info("Datacenter is: {}", DataCenterInfo.Name.Amazon); } catch (Throwable e) { logger.error("Cannot initialize amazon info :", e); throw new RuntimeException(e); From 5f3c0b18016326530da987335ab16e3655cca8b2 Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sun, 20 Aug 2017 18:28:32 -0400 Subject: [PATCH 08/17] Utilize varargs syntax in calling debug() --- .../netflix/eureka/registry/ResponseCacheImpl.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/eureka-core/src/main/java/com/netflix/eureka/registry/ResponseCacheImpl.java b/eureka-core/src/main/java/com/netflix/eureka/registry/ResponseCacheImpl.java index d716484f4f..4833ee7f50 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/registry/ResponseCacheImpl.java +++ b/eureka-core/src/main/java/com/netflix/eureka/registry/ResponseCacheImpl.java @@ -173,8 +173,8 @@ public void run() { logger.debug("Updating the client cache from response cache"); for (Key key : readOnlyCacheMap.keySet()) { if (logger.isDebugEnabled()) { - Object[] args = {key.getEntityType(), key.getName(), key.getVersion(), key.getType()}; - logger.debug("Updating the client cache from response cache for key : {} {} {} {}", args); + logger.debug("Updating the client cache from response cache for key : {} {} {} {}", + key.getEntityType(), key.getName(), key.getVersion(), key.getType()); } try { CurrentRequestVersion.set(key.getVersion()); @@ -452,10 +452,9 @@ private Value generatePayload(Key key) { } private static Applications getApplicationsForVip(Key key, AbstractInstanceRegistry registry) { - Object[] args = {key.getEntityType(), key.getName(), key.getVersion(), key.getType()}; logger.debug( "Retrieving applications from registry for key : {} {} {} {}", - args); + key.getEntityType(), key.getName(), key.getVersion(), key.getType()); Applications toReturn = new Applications(); Applications applications = registry.getApplications(); for (Application application : applications.getRegisteredApplications()) { @@ -485,11 +484,10 @@ private static Applications getApplicationsForVip(Key key, AbstractInstanceRegis } } toReturn.setAppsHashCode(toReturn.getReconcileHashCode()); - args = new Object[]{key.getEntityType(), key.getName(), key.getVersion(), key.getType(), - toReturn.getReconcileHashCode()}; logger.debug( "Retrieved applications from registry for key : {} {} {} {}, reconcile hashcode: {}", - args); + key.getEntityType(), key.getName(), key.getVersion(), key.getType(), + toReturn.getReconcileHashCode()); return toReturn; } From d03299d7dda34fd9b83ed363605a5976a6774a12 Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sun, 8 Oct 2017 17:03:56 -0500 Subject: [PATCH 09/17] Check that logging is enabled before invoking Arrays.toString() As this is potentially expensive, make sure that the String value will be used. --- .../discovery/AbstractAzToRegionMapper.java | 4 +++- .../discovery/endpoint/EndpointUtils.java | 20 +++++++++++++------ .../com/netflix/eureka/aws/AwsAsgUtil.java | 4 +++- .../registry/AbstractInstanceRegistry.java | 12 +++++++---- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/eureka-client/src/main/java/com/netflix/discovery/AbstractAzToRegionMapper.java b/eureka-client/src/main/java/com/netflix/discovery/AbstractAzToRegionMapper.java index 8dcd32fd10..7cef22356f 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/AbstractAzToRegionMapper.java +++ b/eureka-client/src/main/java/com/netflix/discovery/AbstractAzToRegionMapper.java @@ -52,7 +52,9 @@ protected AbstractAzToRegionMapper(EurekaClientConfig clientConfig) { public synchronized void setRegionsToFetch(String[] regionsToFetch) { if (null != regionsToFetch) { this.regionsToFetch = regionsToFetch; - logger.info("Fetching availability zone to region mapping for regions {}", Arrays.toString(regionsToFetch)); + if (logger.isInfoEnabled()) { + logger.info("Fetching availability zone to region mapping for regions {}", Arrays.toString(regionsToFetch)); + } availabilityZoneVsRegion.clear(); for (String remoteRegion : regionsToFetch) { Set availabilityZones = getZonesForARegion(remoteRegion); diff --git a/eureka-client/src/main/java/com/netflix/discovery/endpoint/EndpointUtils.java b/eureka-client/src/main/java/com/netflix/discovery/endpoint/EndpointUtils.java index e2e24f0b44..7a04ae449b 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/endpoint/EndpointUtils.java +++ b/eureka-client/src/main/java/com/netflix/discovery/endpoint/EndpointUtils.java @@ -124,8 +124,10 @@ public static List getServiceUrlsFromDNS(EurekaClientConfig clientConfig zoneIndex++; } if (zoneIndex >= zones.size()) { - logger.warn("No match for the zone {} in the list of available zones {}", - instanceZone, Arrays.toString(zones.toArray())); + if (logger.isWarnEnabled()) { + logger.warn("No match for the zone {} in the list of available zones {}", + instanceZone, Arrays.toString(zones.toArray())); + } } else { // Rearrange the zones with the instance zone first for (int i = 0; i < zoneIndex; i++) { @@ -159,8 +161,10 @@ public static List getServiceUrlsFromDNS(EurekaClientConfig clientConfig randomizer.randomize(serviceUrls); serviceUrls.add(0, primaryServiceUrl); - logger.debug("This client will talk to the following serviceUrls in order : {} ", - Arrays.toString(serviceUrls.toArray())); + if (logger.isDebugEnabled()) { + logger.debug("This client will talk to the following serviceUrls in order : {} ", + Arrays.toString(serviceUrls.toArray())); + } return serviceUrls; } @@ -180,7 +184,9 @@ public static List getServiceUrlsFromConfig(EurekaClientConfig clientCon availZones = new String[1]; availZones[0] = DEFAULT_ZONE; } - logger.debug("The availability zone for the given region {} are {}", region, Arrays.toString(availZones)); + if (logger.isDebugEnabled()) { + logger.debug("The availability zone for the given region {} are {}", region, Arrays.toString(availZones)); + } int myZoneOffset = getZoneOffset(instanceZone, preferSameZone, availZones); List serviceUrls = clientConfig.getEurekaServerServiceUrls(availZones[myZoneOffset]); @@ -222,7 +228,9 @@ public static Map> getServiceUrlsMapFromConfig(EurekaClient availZones = new String[1]; availZones[0] = DEFAULT_ZONE; } - logger.debug("The availability zone for the given region {} are {}", region, Arrays.toString(availZones)); + if (logger.isDebugEnabled()) { + logger.debug("The availability zone for the given region {} are {}", region, Arrays.toString(availZones)); + } int myZoneOffset = getZoneOffset(instanceZone, preferSameZone, availZones); String zone = availZones[myZoneOffset]; diff --git a/eureka-core/src/main/java/com/netflix/eureka/aws/AwsAsgUtil.java b/eureka-core/src/main/java/com/netflix/eureka/aws/AwsAsgUtil.java index 11607f1ea5..a3e288aa3c 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/aws/AwsAsgUtil.java +++ b/eureka-core/src/main/java/com/netflix/eureka/aws/AwsAsgUtil.java @@ -373,7 +373,9 @@ public void run() { try { // First get the active ASG names Set cacheKeys = getCacheKeys(); - logger.debug("Trying to refresh the keys for {}", Arrays.toString(cacheKeys.toArray())); + if (logger.isDebugEnabled()) { + logger.debug("Trying to refresh the keys for {}", Arrays.toString(cacheKeys.toArray())); + } for (CacheKey key : cacheKeys) { try { asgCache.refresh(key); diff --git a/eureka-core/src/main/java/com/netflix/eureka/registry/AbstractInstanceRegistry.java b/eureka-core/src/main/java/com/netflix/eureka/registry/AbstractInstanceRegistry.java index fccf7a0adf..85c394b296 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/registry/AbstractInstanceRegistry.java +++ b/eureka-core/src/main/java/com/netflix/eureka/registry/AbstractInstanceRegistry.java @@ -149,8 +149,10 @@ protected void initRemoteRegionRegistry() throws MalformedURLException { allKnownRemoteRegions[remoteRegionArrayIndex++] = remoteRegionUrlWithName.getKey(); } } - logger.info("Finished initializing remote region registries. All known remote regions: {}", - Arrays.toString(allKnownRemoteRegions)); + if (logger.isInfoEnabled()) { + logger.info("Finished initializing remote region registries. All known remote regions: {}", + Arrays.toString(allKnownRemoteRegions)); + } } @Override @@ -733,8 +735,10 @@ public Applications getApplicationsFromMultipleRegions(String[] remoteRegions) { boolean includeRemoteRegion = null != remoteRegions && remoteRegions.length != 0; - logger.debug("Fetching applications registry with remote regions: {}, Regions argument {}", - includeRemoteRegion, Arrays.toString(remoteRegions)); + if (logger.isDebugEnabled()) { + logger.debug("Fetching applications registry with remote regions: {}, Regions argument {}", + includeRemoteRegion, Arrays.toString(remoteRegions)); + } if (includeRemoteRegion) { GET_ALL_WITH_REMOTE_REGIONS_CACHE_MISS.increment(); From 9cc90a8c5f2475aac416e1f18ebb5874291233d4 Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sun, 8 Oct 2017 17:06:34 -0500 Subject: [PATCH 10/17] Remove a redundant isDebugEnabled() check --- .../shared/resolver/aws/DnsTxtRecordClusterResolver.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/aws/DnsTxtRecordClusterResolver.java b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/aws/DnsTxtRecordClusterResolver.java index a793b2e9fc..cfd0ca64a4 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/aws/DnsTxtRecordClusterResolver.java +++ b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/aws/DnsTxtRecordClusterResolver.java @@ -110,9 +110,7 @@ public String getRegion() { @Override public List getClusterEndpoints() { List eurekaEndpoints = resolve(region, rootClusterDNS, extractZoneFromDNS, port, isSecure, relativeUri); - if (logger.isDebugEnabled()) { - logger.debug("Resolved {} to {}", rootClusterDNS, eurekaEndpoints); - } + logger.debug("Resolved {} to {}", rootClusterDNS, eurekaEndpoints); return eurekaEndpoints; } From f6b924cd221644ffa67c1bec5ec5f5ea590a1cce Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sun, 8 Oct 2017 17:07:08 -0500 Subject: [PATCH 11/17] Fix an incorrect SLF4J logger call This issue was found by SLF4J Helper for NetBeans IDE: http://plugins.netbeans.org/plugin/72557/ --- .../com/netflix/discovery/util/DeserializerStringCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eureka-client/src/main/java/com/netflix/discovery/util/DeserializerStringCache.java b/eureka-client/src/main/java/com/netflix/discovery/util/DeserializerStringCache.java index 879bd0fb5c..bfb08a667c 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/util/DeserializerStringCache.java +++ b/eureka-client/src/main/java/com/netflix/discovery/util/DeserializerStringCache.java @@ -149,7 +149,7 @@ public static void clear(DeserializationContext context, CacheScope scope) { withCache(context, cache -> { if (scope == CacheScope.GLOBAL_SCOPE) { if (logEnabled) - logger.debug("clearing global-level serialization cache", cache.globalCache.size()); + logger.debug("clearing global-level serialization cache with size {}", cache.globalCache.size()); cache.globalCache.clear(); } if (logEnabled) From 7d0271cbad7899058fd1679f8c597edb80f068d9 Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Mon, 6 Nov 2017 12:03:45 -0500 Subject: [PATCH 12/17] Fix an incorrect SLF4J logger call This issue was found by SLF4J Helper for NetBeans IDE: http://plugins.netbeans.org/plugin/72557/ --- .../src/main/java/com/netflix/discovery/DiscoveryClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java b/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java index f546c7bbc5..b0407b30fa 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java +++ b/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java @@ -426,7 +426,7 @@ public synchronized BackupRegistry get() { throw new IllegalStateException("Registration error at startup. Invalid server response."); } } catch (Throwable th) { - logger.error("Registration error at startup.", th.getMessage()); + logger.error("Registration error at startup: {}", th.getMessage()); throw new IllegalStateException(th); } } From 6b6a9201b8d08e397bbeecdee6a48afc1332e28c Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Mon, 6 Nov 2017 12:19:45 -0500 Subject: [PATCH 13/17] Move the concatenation of constant variable PREFIX into the format string The result is still a constant expression per section 15.28 of the JLS, so a runtime string concatenation is avoided. --- .../src/main/java/com/netflix/discovery/DiscoveryClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java b/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java index b0407b30fa..34656a974b 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java +++ b/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java @@ -845,7 +845,7 @@ boolean renew() { logger.debug(PREFIX + "{} - Heartbeat status: {}", appPathIdentifier, httpResponse.getStatusCode()); if (httpResponse.getStatusCode() == 404) { REREGISTER_COUNTER.increment(); - logger.info("{} - Re-registering apps/{}", PREFIX + appPathIdentifier, instanceInfo.getAppName()); + logger.info(PREFIX + "{} - Re-registering apps/{}", appPathIdentifier, instanceInfo.getAppName()); long timestamp = instanceInfo.setIsDirtyWithTime(); boolean success = register(); if (success) { From 6dfe4ab9bbfa5aad03958f54aa2c436c75f83a69 Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Mon, 6 Nov 2017 13:25:22 -0600 Subject: [PATCH 14/17] Remove redundant calls to is*Enabled() --- .../src/main/java/com/netflix/appinfo/InstanceInfo.java | 2 +- .../discovery/shared/resolver/DnsClusterResolver.java | 4 +--- .../discovery/shared/resolver/ReloadingClusterResolver.java | 6 ++---- .../com/netflix/discovery/util/DeserializerStringCache.java | 4 +--- .../src/main/java/com/netflix/discovery/util/ServoUtil.java | 4 +--- .../netflix/eureka/transport/Jersey2ReplicationClient.java | 4 +--- 6 files changed, 7 insertions(+), 17 deletions(-) diff --git a/eureka-client/src/main/java/com/netflix/appinfo/InstanceInfo.java b/eureka-client/src/main/java/com/netflix/appinfo/InstanceInfo.java index 51168fbb68..59d0018e53 100644 --- a/eureka-client/src/main/java/com/netflix/appinfo/InstanceInfo.java +++ b/eureka-client/src/main/java/com/netflix/appinfo/InstanceInfo.java @@ -319,7 +319,7 @@ public static InstanceStatus toEnum(String s) { return InstanceStatus.valueOf(s.toUpperCase()); } catch (IllegalArgumentException e) { // ignore and fall through to unknown - if (logger.isDebugEnabled()) logger.debug("illegal argument supplied to InstanceStatus.valueOf: {}, defaulting to {}", s, UNKNOWN); + logger.debug("illegal argument supplied to InstanceStatus.valueOf: {}, defaulting to {}", s, UNKNOWN); } } return UNKNOWN; diff --git a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/DnsClusterResolver.java b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/DnsClusterResolver.java index 63581b9884..5369f6e1a0 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/DnsClusterResolver.java +++ b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/DnsClusterResolver.java @@ -51,9 +51,7 @@ public DnsClusterResolver(DnsService dnsService, String region, String rootClust } else { this.eurekaEndpoints = DefaultEndpoint.createForServerList(addresses, port, isSecure, relativeUri); } - if (logger.isDebugEnabled()) { - logger.debug("Resolved {} to {}", rootClusterDNS, eurekaEndpoints); - } + logger.debug("Resolved {} to {}", rootClusterDNS, eurekaEndpoints); } @Override diff --git a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/ReloadingClusterResolver.java b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/ReloadingClusterResolver.java index ed1ce33f90..52efe15d6d 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/ReloadingClusterResolver.java +++ b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/ReloadingClusterResolver.java @@ -101,10 +101,8 @@ public List getClusterEndpoints() { if (newDelegate != null) { delegateRef.set(newDelegate); lastReloadTimestamp = System.currentTimeMillis(); - if (logger.isInfoEnabled()) { - logger.info("Reload endpoints differ from the original list; next reload in {}[sec], Loaded endpoints={}", - currentReloadIntervalMs / 1000, newDelegate.getClusterEndpoints()); - } + logger.info("Reload endpoints differ from the original list; next reload in {}[sec], Loaded endpoints={}", + currentReloadIntervalMs / 1000, newDelegate.getClusterEndpoints()); } } catch (Exception e) { this.currentReloadIntervalMs = Math.min(maxReloadIntervalMs, currentReloadIntervalMs * 2); diff --git a/eureka-client/src/main/java/com/netflix/discovery/util/DeserializerStringCache.java b/eureka-client/src/main/java/com/netflix/discovery/util/DeserializerStringCache.java index bfb08a667c..a09dcad49a 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/util/DeserializerStringCache.java +++ b/eureka-client/src/main/java/com/netflix/discovery/util/DeserializerStringCache.java @@ -271,9 +271,7 @@ public String apply(final String stringValue, CacheScope cacheScope) { if (stringValue != null && (lengthLimit < 0 || stringValue.length() <= lengthLimit)) { return (String) (cacheScope == CacheScope.GLOBAL_SCOPE ? globalCache : applicationCache) .computeIfAbsent(CharBuffer.wrap(stringValue), s -> { - if (logger.isTraceEnabled()) - logger.trace(" (string) writing new interned value {} into {} cache scope", stringValue, - cacheScope); + logger.trace(" (string) writing new interned value {} into {} cache scope", stringValue, cacheScope); return stringValue; }); } diff --git a/eureka-client/src/main/java/com/netflix/discovery/util/ServoUtil.java b/eureka-client/src/main/java/com/netflix/discovery/util/ServoUtil.java index 05a86f014a..c799a9cc94 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/util/ServoUtil.java +++ b/eureka-client/src/main/java/com/netflix/discovery/util/ServoUtil.java @@ -38,9 +38,7 @@ public static boolean register(Monitor monitor) { DefaultMonitorRegistry.getInstance().register(monitor); } catch (Exception e) { logger.warn("Cannot register monitor {}", monitor.getConfig().getName()); - if (logger.isDebugEnabled()) { - logger.debug(e.getMessage(), e); - } + logger.debug(e.getMessage(), e); return false; } return true; diff --git a/eureka-core-jersey2/src/main/java/com/netflix/eureka/transport/Jersey2ReplicationClient.java b/eureka-core-jersey2/src/main/java/com/netflix/eureka/transport/Jersey2ReplicationClient.java index a762f93dcc..e768b0fbfe 100644 --- a/eureka-core-jersey2/src/main/java/com/netflix/eureka/transport/Jersey2ReplicationClient.java +++ b/eureka-core-jersey2/src/main/java/com/netflix/eureka/transport/Jersey2ReplicationClient.java @@ -78,9 +78,7 @@ public EurekaHttpResponse sendHeartBeat(String appName, String id, } return anEurekaHttpResponse(response.getStatus(), infoFromPeer).type(MediaType.APPLICATION_JSON_TYPE).build(); } finally { - if (logger.isDebugEnabled()) { - logger.debug("[heartbeat] Jersey HTTP PUT {}; statusCode={}", urlPath, response == null ? "N/A" : response.getStatus()); - } + logger.debug("[heartbeat] Jersey HTTP PUT {}; statusCode={}", urlPath, response == null ? "N/A" : response.getStatus()); if (response != null) { response.close(); } From 15e3d1870eebe96a962091bcb2dcfe4e6fdb99eb Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Mon, 6 Nov 2017 18:19:36 -0600 Subject: [PATCH 15/17] Remove calls to Arrays.toString() that are passed to a logger call SLF4J "natively" supports logging arrays: https://github.com/qos-ch/slf4j/blob/0c189f9882f3167e2dadd9f2eeb115caa2ad9629/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java#L263 --- .../netflix/discovery/AbstractAzToRegionMapper.java | 5 +---- .../netflix/discovery/endpoint/EndpointUtils.java | 13 ++++--------- .../eureka/registry/AbstractInstanceRegistry.java | 13 ++++--------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/eureka-client/src/main/java/com/netflix/discovery/AbstractAzToRegionMapper.java b/eureka-client/src/main/java/com/netflix/discovery/AbstractAzToRegionMapper.java index 7cef22356f..49c8e19e79 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/AbstractAzToRegionMapper.java +++ b/eureka-client/src/main/java/com/netflix/discovery/AbstractAzToRegionMapper.java @@ -1,7 +1,6 @@ package com.netflix.discovery; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -52,9 +51,7 @@ protected AbstractAzToRegionMapper(EurekaClientConfig clientConfig) { public synchronized void setRegionsToFetch(String[] regionsToFetch) { if (null != regionsToFetch) { this.regionsToFetch = regionsToFetch; - if (logger.isInfoEnabled()) { - logger.info("Fetching availability zone to region mapping for regions {}", Arrays.toString(regionsToFetch)); - } + logger.info("Fetching availability zone to region mapping for regions {}", (Object) regionsToFetch); availabilityZoneVsRegion.clear(); for (String remoteRegion : regionsToFetch) { Set availabilityZones = getZonesForARegion(remoteRegion); diff --git a/eureka-client/src/main/java/com/netflix/discovery/endpoint/EndpointUtils.java b/eureka-client/src/main/java/com/netflix/discovery/endpoint/EndpointUtils.java index 7a04ae449b..f1660371e8 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/endpoint/EndpointUtils.java +++ b/eureka-client/src/main/java/com/netflix/discovery/endpoint/EndpointUtils.java @@ -6,7 +6,6 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -126,7 +125,7 @@ public static List getServiceUrlsFromDNS(EurekaClientConfig clientConfig if (zoneIndex >= zones.size()) { if (logger.isWarnEnabled()) { logger.warn("No match for the zone {} in the list of available zones {}", - instanceZone, Arrays.toString(zones.toArray())); + instanceZone, zones.toArray()); } } else { // Rearrange the zones with the instance zone first @@ -163,7 +162,7 @@ public static List getServiceUrlsFromDNS(EurekaClientConfig clientConfig if (logger.isDebugEnabled()) { logger.debug("This client will talk to the following serviceUrls in order : {} ", - Arrays.toString(serviceUrls.toArray())); + (Object) serviceUrls.toArray()); } return serviceUrls; } @@ -184,9 +183,7 @@ public static List getServiceUrlsFromConfig(EurekaClientConfig clientCon availZones = new String[1]; availZones[0] = DEFAULT_ZONE; } - if (logger.isDebugEnabled()) { - logger.debug("The availability zone for the given region {} are {}", region, Arrays.toString(availZones)); - } + logger.debug("The availability zone for the given region {} are {}", region, availZones); int myZoneOffset = getZoneOffset(instanceZone, preferSameZone, availZones); List serviceUrls = clientConfig.getEurekaServerServiceUrls(availZones[myZoneOffset]); @@ -228,9 +225,7 @@ public static Map> getServiceUrlsMapFromConfig(EurekaClient availZones = new String[1]; availZones[0] = DEFAULT_ZONE; } - if (logger.isDebugEnabled()) { - logger.debug("The availability zone for the given region {} are {}", region, Arrays.toString(availZones)); - } + logger.debug("The availability zone for the given region {} are {}", region, availZones); int myZoneOffset = getZoneOffset(instanceZone, preferSameZone, availZones); String zone = availZones[myZoneOffset]; diff --git a/eureka-core/src/main/java/com/netflix/eureka/registry/AbstractInstanceRegistry.java b/eureka-core/src/main/java/com/netflix/eureka/registry/AbstractInstanceRegistry.java index 85c394b296..32b3f71ae3 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/registry/AbstractInstanceRegistry.java +++ b/eureka-core/src/main/java/com/netflix/eureka/registry/AbstractInstanceRegistry.java @@ -20,7 +20,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -149,10 +148,8 @@ protected void initRemoteRegionRegistry() throws MalformedURLException { allKnownRemoteRegions[remoteRegionArrayIndex++] = remoteRegionUrlWithName.getKey(); } } - if (logger.isInfoEnabled()) { - logger.info("Finished initializing remote region registries. All known remote regions: {}", - Arrays.toString(allKnownRemoteRegions)); - } + logger.info("Finished initializing remote region registries. All known remote regions: {}", + (Object) allKnownRemoteRegions); } @Override @@ -735,10 +732,8 @@ public Applications getApplicationsFromMultipleRegions(String[] remoteRegions) { boolean includeRemoteRegion = null != remoteRegions && remoteRegions.length != 0; - if (logger.isDebugEnabled()) { - logger.debug("Fetching applications registry with remote regions: {}, Regions argument {}", - includeRemoteRegion, Arrays.toString(remoteRegions)); - } + logger.debug("Fetching applications registry with remote regions: {}, Regions argument {}", + includeRemoteRegion, remoteRegions); if (includeRemoteRegion) { GET_ALL_WITH_REMOTE_REGIONS_CACHE_MISS.increment(); From d66bdc01329768bf5c90f657a629e9d82bd5df9d Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sun, 12 Nov 2017 15:18:02 -0600 Subject: [PATCH 16/17] Fix a typo --- .../discovery/util/DeserializerStringCache.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/eureka-client/src/main/java/com/netflix/discovery/util/DeserializerStringCache.java b/eureka-client/src/main/java/com/netflix/discovery/util/DeserializerStringCache.java index a09dcad49a..f8786be943 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/util/DeserializerStringCache.java +++ b/eureka-client/src/main/java/com/netflix/discovery/util/DeserializerStringCache.java @@ -36,7 +36,7 @@ public enum CacheScope { } private static final Logger logger = LoggerFactory.getLogger(DeserializerStringCache.class); - private static final boolean logEnabled = logger.isTraceEnabled(); + private static final boolean debugLogEnabled = logger.isDebugEnabled(); private static final String ATTR_STRING_CACHE = "deserInternCache"; private static final int LENGTH_LIMIT = 256; private static final int LRU_LIMIT = 1024 * 40; @@ -118,11 +118,11 @@ public static void clear(ObjectReader reader) { public static void clear(ObjectReader reader, final CacheScope scope) { withCache(reader, cache -> { if (scope == CacheScope.GLOBAL_SCOPE) { - if (logEnabled) + if (debugLogEnabled) logger.debug("clearing global-level cache with size {}", cache.globalCache.size()); cache.globalCache.clear(); } - if (logEnabled) + if (debugLogEnabled) logger.debug("clearing app-level serialization cache with size {}", cache.applicationCache.size()); cache.applicationCache.clear(); return null; @@ -148,11 +148,11 @@ public static void clear(DeserializationContext context) { public static void clear(DeserializationContext context, CacheScope scope) { withCache(context, cache -> { if (scope == CacheScope.GLOBAL_SCOPE) { - if (logEnabled) + if (debugLogEnabled) logger.debug("clearing global-level serialization cache with size {}", cache.globalCache.size()); cache.globalCache.clear(); } - if (logEnabled) + if (debugLogEnabled) logger.debug("clearing app-level serialization cache with size {}", cache.applicationCache.size()); cache.applicationCache.clear(); return null; From 2e0c8d635ed6b7a232d2b3f10b4f82b4911bb1fc Mon Sep 17 00:00:00 2001 From: Daniel Trebbien Date: Sun, 12 Nov 2017 15:28:11 -0600 Subject: [PATCH 17/17] Restore is*Enabled() checks that guard against any computation being performed unnecessarily --- .../main/java/com/netflix/discovery/DiscoveryClient.java | 4 +++- .../discovery/shared/resolver/ReloadingClusterResolver.java | 6 ++++-- .../src/main/java/com/netflix/discovery/util/ServoUtil.java | 4 +++- .../netflix/eureka/transport/Jersey2ReplicationClient.java | 4 +++- .../netflix/eureka/transport/JerseyReplicationClient.java | 4 +++- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java b/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java index 34656a974b..37487404e4 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java +++ b/eureka-client/src/main/java/com/netflix/discovery/DiscoveryClient.java @@ -831,7 +831,9 @@ boolean register() throws Throwable { logger.warn(PREFIX + "{} - registration failed {}", appPathIdentifier, e.getMessage(), e); throw e; } - logger.info(PREFIX + "{} - registration status: {}", appPathIdentifier, httpResponse.getStatusCode()); + if (logger.isInfoEnabled()) { + logger.info(PREFIX + "{} - registration status: {}", appPathIdentifier, httpResponse.getStatusCode()); + } return httpResponse.getStatusCode() == 204; } diff --git a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/ReloadingClusterResolver.java b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/ReloadingClusterResolver.java index 52efe15d6d..ed1ce33f90 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/ReloadingClusterResolver.java +++ b/eureka-client/src/main/java/com/netflix/discovery/shared/resolver/ReloadingClusterResolver.java @@ -101,8 +101,10 @@ public List getClusterEndpoints() { if (newDelegate != null) { delegateRef.set(newDelegate); lastReloadTimestamp = System.currentTimeMillis(); - logger.info("Reload endpoints differ from the original list; next reload in {}[sec], Loaded endpoints={}", - currentReloadIntervalMs / 1000, newDelegate.getClusterEndpoints()); + if (logger.isInfoEnabled()) { + logger.info("Reload endpoints differ from the original list; next reload in {}[sec], Loaded endpoints={}", + currentReloadIntervalMs / 1000, newDelegate.getClusterEndpoints()); + } } } catch (Exception e) { this.currentReloadIntervalMs = Math.min(maxReloadIntervalMs, currentReloadIntervalMs * 2); diff --git a/eureka-client/src/main/java/com/netflix/discovery/util/ServoUtil.java b/eureka-client/src/main/java/com/netflix/discovery/util/ServoUtil.java index c799a9cc94..05a86f014a 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/util/ServoUtil.java +++ b/eureka-client/src/main/java/com/netflix/discovery/util/ServoUtil.java @@ -38,7 +38,9 @@ public static boolean register(Monitor monitor) { DefaultMonitorRegistry.getInstance().register(monitor); } catch (Exception e) { logger.warn("Cannot register monitor {}", monitor.getConfig().getName()); - logger.debug(e.getMessage(), e); + if (logger.isDebugEnabled()) { + logger.debug(e.getMessage(), e); + } return false; } return true; diff --git a/eureka-core-jersey2/src/main/java/com/netflix/eureka/transport/Jersey2ReplicationClient.java b/eureka-core-jersey2/src/main/java/com/netflix/eureka/transport/Jersey2ReplicationClient.java index e768b0fbfe..a762f93dcc 100644 --- a/eureka-core-jersey2/src/main/java/com/netflix/eureka/transport/Jersey2ReplicationClient.java +++ b/eureka-core-jersey2/src/main/java/com/netflix/eureka/transport/Jersey2ReplicationClient.java @@ -78,7 +78,9 @@ public EurekaHttpResponse sendHeartBeat(String appName, String id, } return anEurekaHttpResponse(response.getStatus(), infoFromPeer).type(MediaType.APPLICATION_JSON_TYPE).build(); } finally { - logger.debug("[heartbeat] Jersey HTTP PUT {}; statusCode={}", urlPath, response == null ? "N/A" : response.getStatus()); + if (logger.isDebugEnabled()) { + logger.debug("[heartbeat] Jersey HTTP PUT {}; statusCode={}", urlPath, response == null ? "N/A" : response.getStatus()); + } if (response != null) { response.close(); } diff --git a/eureka-core/src/main/java/com/netflix/eureka/transport/JerseyReplicationClient.java b/eureka-core/src/main/java/com/netflix/eureka/transport/JerseyReplicationClient.java index 71399339da..c1980d4065 100644 --- a/eureka-core/src/main/java/com/netflix/eureka/transport/JerseyReplicationClient.java +++ b/eureka-core/src/main/java/com/netflix/eureka/transport/JerseyReplicationClient.java @@ -78,7 +78,9 @@ public EurekaHttpResponse sendHeartBeat(String appName, String id, } return anEurekaHttpResponse(response.getStatus(), infoFromPeer).type(MediaType.APPLICATION_JSON_TYPE).build(); } finally { - logger.debug("[heartbeat] Jersey HTTP PUT {}; statusCode={}", urlPath, response == null ? "N/A" : response.getStatus()); + if (logger.isDebugEnabled()) { + logger.debug("[heartbeat] Jersey HTTP PUT {}; statusCode={}", urlPath, response == null ? "N/A" : response.getStatus()); + } if (response != null) { response.close(); }