Skip to content

Commit

Permalink
fixed metrics to add ServerGroup whereever possible. Fixed hashing al…
Browse files Browse the repository at this point in the history
…gorithm when so that it works in test environment
  • Loading branch information
smadappa committed Aug 16, 2016
1 parent accff80 commit ae44156
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ final public class EVCacheImpl implements EVCache {

stats = EVCacheMetricsFactory.getStats(appName, cacheName);
_metricName = (_cacheName == null) ? _appName : _appName + "." + _cacheName;
_metricPrefix = ( (_cacheName == null) ? _appName : _appName + "-" + _cacheName ) + "-";
_metricPrefix = _appName + "-";
this._poolManager = poolManager;
this._pool = poolManager.getEVCacheClientPool(_appName);
final EVCacheConfig config = EVCacheConfig.getInstance();
Expand Down Expand Up @@ -198,7 +198,7 @@ private void increment(String metric) {
}

private void increment(String serverGroup, String metric) {
EVCacheMetricsFactory.increment(_appName, _cacheName, serverGroup, _metricPrefix + metric);
EVCacheMetricsFactory.increment(_appName, null, serverGroup, _metricPrefix + metric);
}

public <T> T get(String key, Transcoder<T> tc) throws EVCacheException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ public static Counter getCounter(String appName, String cacheName, String server
if(serverGroupName != null && serverGroupName.length() > 0) {
tags = BasicTagList.concat(tags, new BasicTag("ServerGroup", serverGroupName));
}
if(!tags.containsKey(DataSourceType.COUNTER.getKey())) {
tags = BasicTagList.concat(tags, DataSourceType.COUNTER);
}
writeLock.lock();
try {
if (monitorMap.containsKey(name)) {
Expand All @@ -207,7 +210,7 @@ public static Counter getCounter(String appName, String cacheName, String server
}

public static StepCounter getStepCounter(String appName, String cacheName, String metric) {
final String metricName = getMetricName(appName, cacheName, metric);
final String metricName = getMetricName(appName, null, metric);
final String name = metricName + "type=StepCounter";
final StepCounter counter = (StepCounter) monitorMap.get(name);
if (counter != null) return counter;
Expand All @@ -228,7 +231,7 @@ public static StepCounter getStepCounter(String appName, String cacheName, Strin
}

public static StatsTimer getStatsTimer(String appName, String cacheName, String metric) {
final String metricName = getMetricName(appName, cacheName, metric);
final String metricName = getMetricName(appName, null, metric);
final String name = metricName + "type=StatsTimer";
final StatsTimer duration = (StatsTimer) monitorMap.get(name);
if (duration != null) return duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public DiscoveryNodeListProvider(ApplicationInfoManager applicationInfoManager,
this._discoveryClient = discoveryClient;
this._appName = appName;
ignoreHosts = new DynamicStringSetProperty(appName + ".ignore.hosts", "");

}

/*
Expand Down Expand Up @@ -75,38 +75,38 @@ public Map<ServerGroup, EVCacheServerGroupConfig> discoverInstances() throws IOE
/* Only AWS instances are usable; bypass all others */
if (DataCenterInfo.Name.Amazon != dcInfo.getName() || !(dcInfo instanceof AmazonInfo)) {
log.error("This is not a AWSDataCenter. You will not be able to use Discovery Nodelist Provider. Cannot proceed. DataCenterInfo : "
+ dcInfo + "; appName - " + _appName + ". Please use SimpleNodeList provider and specify the server groups manually.");
+ dcInfo + "; appName - " + _appName + ". Please use SimpleNodeList provider and specify the server groups manually.");
continue;
}

final AmazonInfo amznInfo = (AmazonInfo) dcInfo;
// We checked above if this instance is Amazon so no need to do a instanceof check
final String zone = amznInfo.get(AmazonInfo.MetaDataKey.availabilityZone);
if(zone == null) {
EVCacheMetricsFactory.increment(_appName, null, "EVCacheClient-DiscoveryNodeListProvider-NULL_ZONE");
continue;
EVCacheMetricsFactory.increment(_appName, null, "EVCacheClient-DiscoveryNodeListProvider-NULL_ZONE");
continue;
}
final String rSetName = iInfo.getASGName();
if(rSetName == null) {
EVCacheMetricsFactory.increment(_appName, null, "EVCacheClient-DiscoveryNodeListProvider-NULL_SERVER_GROUP");
continue;
final String asgName = iInfo.getASGName();
if(asgName == null) {
EVCacheMetricsFactory.increment(_appName, null, "EVCacheClient-DiscoveryNodeListProvider-NULL_SERVER_GROUP");
continue;
}

final Map<String, String> metaInfo = iInfo.getMetadata();
final int evcachePort = Integer.parseInt((metaInfo != null && metaInfo.containsKey("evcache.port")) ? metaInfo.get("evcache.port") : DEFAULT_PORT);
final int rendPort = (metaInfo != null && metaInfo.containsKey("rend.port")) ? Integer.parseInt(metaInfo.get("rend.port")) : 0;
final int rendBatchPort = (metaInfo != null && metaInfo.containsKey("rend.batch.port")) ? Integer.parseInt(metaInfo.get("rend.batch.port")) : 0;
final int udsproxyMemcachedPort = (metaInfo != null && metaInfo.containsKey("udsproxy.memcached.port")) ? Integer.parseInt(metaInfo.get("udsproxy.memcached.port")) : 0;
final int udsproxyMementoPort = (metaInfo != null && metaInfo.containsKey("udsproxy.memento.port")) ? Integer.parseInt(metaInfo.get("udsproxy.memento.port")) : 0;

ChainedDynamicProperty.BooleanProperty useBatchPort = useRendBatchPortMap.get(rSetName);
ChainedDynamicProperty.BooleanProperty useBatchPort = useRendBatchPortMap.get(asgName);
if (useBatchPort == null) {
useBatchPort = EVCacheConfig.getInstance().getChainedBooleanProperty(_appName + "." + rSetName+ ".use.batch.port", _appName + ".use.batch.port", Boolean.FALSE);
useRendBatchPortMap.put(rSetName, useBatchPort);
useBatchPort = EVCacheConfig.getInstance().getChainedBooleanProperty(_appName + ".use.batch.port", "evcache.use.batch.port", Boolean.FALSE);
useRendBatchPortMap.put(asgName, useBatchPort);
}
final int port = rendPort == 0 ? evcachePort : ((useBatchPort.get().booleanValue()) ? rendBatchPort : rendPort);

final ServerGroup rSet = new ServerGroup(zone, rSetName);
final ServerGroup rSet = new ServerGroup(zone, asgName);
final Set<InetSocketAddress> instances;
final EVCacheServerGroupConfig config;
if (instancesSpecific.containsKey(rSet)) {
Expand All @@ -116,6 +116,7 @@ public Map<ServerGroup, EVCacheServerGroupConfig> discoverInstances() throws IOE
instances = new HashSet<InetSocketAddress>();
config = new EVCacheServerGroupConfig(rSet, instances, rendPort, udsproxyMemcachedPort, udsproxyMementoPort);
instancesSpecific.put(rSet, config);
EVCacheMetricsFactory.getLongGauge("EVCacheClient-"+_appName + "-" + asgName +"-port").set(Long.valueOf(port));
}

/* Don't try to use downed instances */
Expand Down Expand Up @@ -150,45 +151,34 @@ public Map<ServerGroup, EVCacheServerGroupConfig> discoverInstances() throws IOE
final String myRegion = (myZone != null) ? myZone.substring(0, myZone.length() - 1) : null;
final String region = (zone != null) ? zone.substring(0, zone.length() - 1) : null;
final String host = amznInfo.get(AmazonInfo.MetaDataKey.publicHostname);
if (log.isDebugEnabled()) log.debug("myZone - " + myZone + "; zone : " + zone + "; myRegion : " + myRegion + "; region : " + region + "; host : " + host);
InetSocketAddress address = null;
if(host != null) {
if (myRegion == null || region == null || !myRegion.equals(region)) {
// Hack so tests can work on desktop and in jenkins
final InetAddress inetAddress = InetAddress.getByName(host);
final String vpcId = amznInfo.get(AmazonInfo.MetaDataKey.vpcId);
final String localIp = amznInfo.get(AmazonInfo.MetaDataKey.localIpv4);
if (log.isDebugEnabled()) log.debug("myZone - " + myZone + "; zone : " + zone + "; myRegion : " + myRegion + "; region : " + region + "; host : " + host + "; vpcId : " + vpcId);
if(localIp != null && ignoreHosts.get().contains(localIp)) continue;
if(host != null && ignoreHosts.get().contains(host)) continue;

if (vpcId != null) {
final InetAddress add = InetAddresses.forString(localIp);
final InetAddress inetAddress = InetAddress.getByAddress(localIp, add.getAddress());
address = new InetSocketAddress(inetAddress, port);

if (log.isDebugEnabled()) log.debug("VPC : localIp - " + localIp + " ; add : " + add + "; inetAddress : " + inetAddress + "; address - " + address
+ "; App Name : " + _appName + "; Zone : " + zone + "; myZone - " + myZone + "; Host : " + iInfo.getHostName() + "; Instance Id - " + iInfo.getId());
} else {
if(host != null && host.startsWith("ec2")) {

final InetAddress inetAddress = (localIp != null) ? InetAddress.getByAddress(host, InetAddresses.forString(localIp).getAddress()) : InetAddress.getByName(host);
address = new InetSocketAddress(inetAddress, port);
if (log.isDebugEnabled()) log.debug("myZone - " + myZone + ". host : " + host
+ "; inetAddress : " + inetAddress + "; address - " + address + "; App Name : " + _appName
+ "; Zone : " + zone + "; Host : " + iInfo.getHostName() + "; Instance Id - " + iInfo.getId());
} else {
final String localIp = (isInCloud) ? amznInfo.get(AmazonInfo.MetaDataKey.localIpv4) : amznInfo.get(AmazonInfo.MetaDataKey.publicIpv4);
if(ignoreHosts.get().contains(localIp)) continue;
final InetAddress add = InetAddresses.forString(localIp);
final InetAddress inetAddress = InetAddress.getByAddress(host, add.getAddress());
address = new InetSocketAddress(inetAddress, port);
if (log.isDebugEnabled()) log.debug("CLASSIC : localIp - " + localIp + ". host : " + host + "; add : "
+ add + "; inetAddress : " + inetAddress + "; address - " + address + "; App Name : " + _appName
+ "; Zone : " + zone + "; myZone - " + myZone + "; Host : " + iInfo.getHostName() + "; Instance Id - " + iInfo.getId());
}
} else {
if (amznInfo.get(AmazonInfo.MetaDataKey.vpcId) != null) {
final String localIp = amznInfo.get(AmazonInfo.MetaDataKey.localIpv4);
if(ignoreHosts.get().contains(localIp)) continue;

final InetAddress add = InetAddresses.forString(localIp);
final InetAddress inetAddress = InetAddress.getByAddress(localIp, add.getAddress());
address = new InetSocketAddress(inetAddress, port);

if (log.isDebugEnabled()) log.debug("VPC : localIp - " + localIp + " ; add : " + add + "; inetAddress : " + inetAddress + "; address - " + address
+ "; App Name : " + _appName + "; Zone : " + zone + "; myZone - " + myZone + "; Host : " + iInfo.getHostName() + "; Instance Id - " + iInfo.getId());
} else {
final String localIp = (isInCloud) ? amznInfo.get(AmazonInfo.MetaDataKey.localIpv4)
: amznInfo.get(AmazonInfo.MetaDataKey.publicIpv4);
if(ignoreHosts.get().contains(localIp)) continue;
final InetAddress add = InetAddresses.forString(localIp);
final InetAddress inetAddress = InetAddress.getByAddress(localIp, add.getAddress());
final String ipToUse = (isInCloud) ? localIp : amznInfo.get(AmazonInfo.MetaDataKey.publicIpv4);
final InetAddress add = InetAddresses.forString(ipToUse);
final InetAddress inetAddress = InetAddress.getByAddress(ipToUse, add.getAddress());
address = new InetSocketAddress(inetAddress, port);
if (log.isDebugEnabled()) log.debug("CLASSIC : localIp - " + localIp + " ; add : " + add + "; inetAddress : " + inetAddress + "; address - " + address
if (log.isDebugEnabled()) log.debug("CLASSIC : IPToUse - " + ipToUse + " ; add : " + add + "; inetAddress : " + inetAddress + "; address - " + address
+ "; App Name : " + _appName + "; Zone : " + zone + "; myZone - " + myZone + "; Host : " + iInfo.getHostName() + "; Instance Id - " + iInfo.getId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private Collection<String> validateReadQueueSize(Collection<String> canonicalKey
// Size - " + size + " for app " + appName + " & zone " + zone +
// " ; node " + node);
if (!canAddToOpQueue) {
EVCacheMetricsFactory.getCounter("EVCacheClient-" + appName + "-READ_QUEUE_FULL", evcNode.getBaseTags()).increment();
EVCacheMetricsFactory.getCounter(appName + "-READ_QUEUE_FULL", evcNode.getBaseTags()).increment();
if (log.isDebugEnabled()) log.debug("Read Queue Full on Bulk Operation for app : " + appName
+ "; zone : " + zone + "; Current Size : " + size + "; Max Size : " + maxReadQueueSize.get() * 2);
} else {
Expand Down Expand Up @@ -192,7 +192,7 @@ private boolean validateNode(String key, boolean _throwException) throws EVCache
if (log.isDebugEnabled()) log.debug("Current Read Queue Size - " + size + " for app " + appName + " & zone "
+ zone);
if (!canAddToOpQueue) {
EVCacheMetricsFactory.getCounter("EVCacheClient-" + appName + "-" + zone + "-READ_QUEUE_FULL", evcNode.getBaseTags()).increment();
EVCacheMetricsFactory.getCounter(appName + "-READ_QUEUE_FULL", evcNode.getBaseTags()).increment();
if (log.isDebugEnabled()) log.debug("Read Queue Full for Node : " + node + "; app : " + appName
+ "; zone : " + zone + "; Current Size : " + size + "; Max Size : " + maxReadQueueSize.get());
if (_throwException) throw new EVCacheReadQueueException("Read Queue Full for Node : " + node + "; app : "
Expand Down
Loading

0 comments on commit ae44156

Please sign in to comment.