Skip to content

Commit

Permalink
replace servo with spectator
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Gordineer committed Jan 5, 2024
1 parent 0b32fa1 commit 229700e
Show file tree
Hide file tree
Showing 44 changed files with 466 additions and 670 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,10 @@

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

import com.netflix.discovery.util.ServoUtil;
import com.netflix.spectator.api.Counter;
import com.netflix.spectator.api.Spectator;
import com.netflix.spectator.api.Timer;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyStore;
Expand Down Expand Up @@ -36,12 +40,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 +322,19 @@ 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);
}
final com.netflix.spectator.api.Registry registry = Spectator.globalRegistry();
executionTimeStats = registry.timer("Eureka-Connection-Cleaner-Time");
cleanupFailed = registry.counter("Eureka-Connection-Cleaner-Failure");
}

@Override
public void run() {
Stopwatch start = executionTimeStats.start();
long monotonicTime = ServoUtil.time(executionTimeStats);
try {
HttpClientConnectionManager cm = (HttpClientConnectionManager) jerseyClient
.getConfiguration()
Expand All @@ -351,11 +344,8 @@ public void run() {
s_logger.error("Cannot clean connections", e);
cleanupFailed.increment();
} finally {
if (null != start) {
start.stop();
}
ServoUtil.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
5 changes: 4 additions & 1 deletion eureka-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ dependencies {
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 "com.netflix.netflix-commons:netflix-eventbus:0.3.0"
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 229700e

Please sign in to comment.