Skip to content

Commit

Permalink
Merge pull request #1526 from Netflix/josh/guava2x
Browse files Browse the repository at this point in the history
replace servo with spectator
  • Loading branch information
cancecen authored May 31, 2024
2 parents 3a63288 + 10ba1fd commit 9b3df32
Show file tree
Hide file tree
Showing 45 changed files with 552 additions and 700 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ allprojects {
apacheHttpClientVersion = '4.5.3'
commonsConfigurationVersion = '1.10'
jsr305Version = '3.0.2'
servoVersion = '0.12.21'
spectatorVersion = '1.7.3'
slf4jVersion = '1.7.36'
archaiusVersion = '0.7.6'
jacksonVersion = '2.10.5'
jacksonDatabindVersion = '2.10.5.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.netflix.appinfo;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;

import com.google.common.collect.Sets;
import com.netflix.archaius.api.Config;
import com.netflix.archaius.api.annotations.ConfigurationSource;
import com.netflix.discovery.CommonConstants;
Expand Down Expand Up @@ -125,7 +125,8 @@ public String getASGName() {
public Map<String, String> getMetadataMap() {
Map<String, String> meta = new HashMap<>();
InternalPrefixedConfig metadataConfig = new InternalPrefixedConfig(configInstance, namespace, INSTANCE_METADATA_PREFIX);
for (String key : Sets.newHashSet(metadataConfig.getKeys())) {
for (Iterator<String> it = metadataConfig.getKeys(); it.hasNext(); ) {
String key = it.next();
String value = metadataConfig.getString(key, null);
// only add the metadata if the value is present
if (value != null && !value.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import static com.netflix.discovery.util.DiscoveryBuildInfo.buildVersion;

import com.netflix.discovery.util.SpectatorUtil;
import com.netflix.spectator.api.Counter;
import com.netflix.spectator.api.Timer;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyStore;
Expand Down Expand Up @@ -36,12 +39,6 @@
import com.netflix.discovery.converters.wrappers.DecoderWrapper;
import com.netflix.discovery.converters.wrappers.EncoderWrapper;
import com.netflix.discovery.provider.DiscoveryJerseyProvider;
import com.netflix.servo.monitor.BasicCounter;
import com.netflix.servo.monitor.BasicTimer;
import com.netflix.servo.monitor.Counter;
import com.netflix.servo.monitor.MonitorConfig;
import com.netflix.servo.monitor.Monitors;
import com.netflix.servo.monitor.Stopwatch;

/**
* @author Tomasz Bak
Expand Down Expand Up @@ -324,24 +321,18 @@ private PoolingHttpClientConnectionManager createCustomSslCM() {
private class ConnectionCleanerTask implements Runnable {

private final int connectionIdleTimeout;
private final BasicTimer executionTimeStats;
private final Timer executionTimeStats;
private final Counter cleanupFailed;

private ConnectionCleanerTask(int connectionIdleTimeout) {
this.connectionIdleTimeout = connectionIdleTimeout;
MonitorConfig.Builder monitorConfigBuilder = MonitorConfig.builder("Eureka-Connection-Cleaner-Time");
executionTimeStats = new BasicTimer(monitorConfigBuilder.build());
cleanupFailed = new BasicCounter(MonitorConfig.builder("Eureka-Connection-Cleaner-Failure").build());
try {
Monitors.registerObject(this);
} catch (Exception e) {
s_logger.error("Unable to register with servo.", e);
}
executionTimeStats = SpectatorUtil.timer("Eureka-Connection-Cleaner-Time", null, ConnectionCleanerTask.class);
cleanupFailed = SpectatorUtil.counter("Eureka-Connection-Cleaner-Failure", null, ConnectionCleanerTask.class);
}

@Override
public void run() {
Stopwatch start = executionTimeStats.start();
long monotonicTime = SpectatorUtil.time(executionTimeStats);
try {
HttpClientConnectionManager cm = (HttpClientConnectionManager) jerseyClient
.getConfiguration()
Expand All @@ -351,11 +342,8 @@ public void run() {
s_logger.error("Cannot clean connections", e);
cleanupFailed.increment();
} finally {
if (null != start) {
start.stop();
}
SpectatorUtil.record(executionTimeStats, monotonicTime);
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.netflix.appinfo.MyDataCenterInstanceConfig;
import com.netflix.discovery.DefaultEurekaClientConfig;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.shared.transport.EurekaHttpClient;
import com.netflix.discovery.util.InstanceInfoGenerator;
import com.netflix.eureka.DefaultEurekaServerConfig;
import com.netflix.eureka.EurekaServerContext;
Expand Down
6 changes: 4 additions & 2 deletions eureka-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ configurations.all {
}

dependencies {
api "com.netflix.netflix-commons:netflix-eventbus:0.3.0"
implementation "com.netflix.netflix-commons:netflix-eventbus:0.3.0"
api 'com.thoughtworks.xstream:xstream:1.4.19'
api "com.netflix.archaius:archaius-core:${archaiusVersion}"
api 'jakarta.ws.rs:jakarta.ws.rs-api:3.0.0'
api 'jakarta.inject:jakarta.inject-api:2.0.1'
api 'jakarta.annotation:jakarta.annotation-api:2.1.0'
api "com.netflix.servo:servo-core:${servoVersion}"
api "com.netflix.spectator:spectator-api:${spectatorVersion}"
api "org.slf4j:slf4j-api:${slf4jVersion}"
implementation "javax.annotation:javax.annotation-api:1.2"
// compile "com.sun.jersey:jersey-core:${jerseyVersion}"
// compile "com.sun.jersey:jersey-client:${jerseyVersion}"
// compile "com.sun.jersey.contribs:jersey-apache-client4:${jerseyVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import com.google.common.base.Supplier;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -31,13 +27,7 @@ public abstract class AbstractAzToRegionMapper implements AzToRegionMapper {
* any availability zone mapping, we will use these defaults. OTOH, if the remote region has any mapping defaults
* will not be used.
*/
private final Multimap<String, String> defaultRegionVsAzMap =
Multimaps.newListMultimap(new HashMap<String, Collection<String>>(), new Supplier<List<String>>() {
@Override
public List<String> get() {
return new ArrayList<String>();
}
});
private final ConcurrentHashMap<String, List<String>> defaultRegionVsAzMap = new ConcurrentHashMap<>();

private final Map<String, String> availabilityZoneVsRegion = new ConcurrentHashMap<String, String>();
private String[] regionsToFetch;
Expand Down Expand Up @@ -128,20 +118,28 @@ protected String parseAzToGetRegion(String availabilityZone) {
}

private void populateDefaultAZToRegionMap() {
defaultRegionVsAzMap.put("us-east-1", "us-east-1a");
defaultRegionVsAzMap.put("us-east-1", "us-east-1c");
defaultRegionVsAzMap.put("us-east-1", "us-east-1d");
defaultRegionVsAzMap.put("us-east-1", "us-east-1e");

defaultRegionVsAzMap.put("us-west-1", "us-west-1a");
defaultRegionVsAzMap.put("us-west-1", "us-west-1c");

defaultRegionVsAzMap.put("us-west-2", "us-west-2a");
defaultRegionVsAzMap.put("us-west-2", "us-west-2b");
defaultRegionVsAzMap.put("us-west-2", "us-west-2c");

defaultRegionVsAzMap.put("eu-west-1", "eu-west-1a");
defaultRegionVsAzMap.put("eu-west-1", "eu-west-1b");
defaultRegionVsAzMap.put("eu-west-1", "eu-west-1c");
final ArrayList<String> east = new ArrayList<>();
east.add("us-east-1a");
east.add("us-east-1c");
east.add("us-east-1d");
east.add("us-east-1e");
defaultRegionVsAzMap.put("us-east-1", east);

final ArrayList<String> west1 = new ArrayList<>();
west1.add("us-west-1a");
west1.add("us-west-1c");
defaultRegionVsAzMap.put("us-west-1", west1);

final ArrayList<String> west2 = new ArrayList<>();
defaultRegionVsAzMap.put("us-west-2", west2);
west2.add("us-west-2a");
west2.add("us-west-2b");
west2.add("us-west-2c");

final ArrayList<String> euwest1 = new ArrayList<>();
euwest1.add("eu-west-1a");
euwest1.add("eu-west-1b");
euwest1.add("eu-west-1c");
defaultRegionVsAzMap.put("eu-west-1", euwest1);
}
}
Loading

0 comments on commit 9b3df32

Please sign in to comment.