Skip to content

Commit

Permalink
add metrics for symlink cluster count and total hosts count
Browse files Browse the repository at this point in the history
  • Loading branch information
bohhyang committed Dec 15, 2023
1 parent dac1bca commit 693eeac
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,11 @@ public int getTrackerClientCount(String clusterName)
return count;
}

public Set<String> getClusters()
{
return _uriProperties.keySet();
}

public Set<String> getServicesForCluster(String clusterName)
{
Set<String> services = _servicesPerCluster.get(clusterName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public int getFirstValidPartitionId()
return _stateUpdater.getFirstValidPartitionId();
}

public int getTotalHostsInAllPartitions()
{
return _stateUpdater.getTotalHostsInAllPartitions();
}

/**
* Exposed for testings
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ PartitionState getPartitionState(int partitionId)
return _partitionLoadBalancerStateMap.get(partitionId);
}

/**
* Return the total tracker clients in all partitions regardless of their statuses.
*/
int getTotalHostsInAllPartitions()
{
return _partitionLoadBalancerStateMap.values().stream()
.map(partitionState -> partitionState.getTrackerClients().size())
.mapToInt(Integer::intValue)
.sum();
}

/**
* Return the first valid partition id. This is mainly used for monitoring at least one valid partition.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ public static boolean containsSymlink(String path)
{
return (firstSymlinkIndex(path) < 0) ? false : true;
}

public static boolean isSymlinkNodeOrPath(String nodeNameOrPath)
{
return nodeNameOrPath != null && nodeNameOrPath.indexOf(SYMLINK_PREFIX) >= 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,28 @@ public double getNthPercentileLatencyRelativeFactor(double pct)
return avgLatency == 0 ? 0 : nthLatency / avgLatency;
}

@Override
public int getTotalHostsInAllPartitionsCount()
{
if (isPartitionDataUnavailable())
{
return DEFAULT_INT_METRICS;
}

return _strategy.getTotalHostsInAllPartitions();
}

@Override
public int getTotalHostsCount()
{
if (isPartitionDataUnavailable())
{
return DEFAULT_INT_METRICS;
}

return _strategy.getPartitionState(_strategy.getFirstValidPartitionId()).getTrackerClientStateMap().size();
}

@Override
public int getUnhealthyHostsCount()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ public interface RelativeLoadBalancerStrategyJmxMBean
*/
double getNthPercentileLatencyRelativeFactor(double pct);

/**
*
* @return the number of total hosts in all partitions regardless of their status
*/
int getTotalHostsInAllPartitionsCount();

/**
*
* @return the number of total hosts regardless of their status
*/
int getTotalHostsCount();

/**
*
* @return the number of unhealthy hosts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.linkedin.d2.jmx;

import com.linkedin.d2.balancer.clients.TrackerClient;
import com.linkedin.d2.discovery.stores.zk.SymlinkUtil;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
Expand All @@ -41,6 +42,12 @@ public int getClusterCount()
return _state.getClusterCount();
}

@Override
public long getSymlinkClusterCount()
{
return _state.getClusters().stream().filter(SymlinkUtil::isSymlinkNodeOrPath).count();
}

@Override
public int getClusterListenCount()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public interface SimpleLoadBalancerStateJmxMBean

int getClusterCount();

long getSymlinkClusterCount();

int getServiceCount();

long getVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.google.common.collect.HashBiMap;
import com.google.common.collect.MapDifference;
import com.google.common.collect.Maps;
import com.google.protobuf.InvalidProtocolBufferException;
import com.linkedin.d2.balancer.dualread.DualReadStateManager;
import com.linkedin.d2.balancer.properties.ClusterProperties;
import com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer;
Expand All @@ -31,6 +30,7 @@
import com.linkedin.d2.discovery.PropertySerializationException;
import com.linkedin.d2.discovery.event.PropertyEventBus;
import com.linkedin.d2.discovery.event.ServiceDiscoveryEventEmitter;
import com.linkedin.d2.discovery.stores.zk.SymlinkUtil;
import indis.XdsD2;
import io.grpc.Status;
import java.nio.charset.StandardCharsets;
Expand All @@ -54,7 +54,6 @@ public class XdsToD2PropertiesAdaptor
private static final String D2_CLUSTER_NODE_PREFIX = "/d2/clusters/";
private static final String D2_SERVICE_NODE_PREFIX = "/d2/services/";
private static final String D2_URI_NODE_PREFIX = "/d2/uris/";
private static final char SYMLINK_NODE_IDENTIFIER = '$';
private static final char PATH_SEPARATOR = '/';
private static final String NON_EXISTENT_CLUSTER = "NonExistentCluster";

Expand Down Expand Up @@ -144,7 +143,7 @@ public void listenToCluster(String clusterName)
{
// if cluster name is a symlink, watch for D2SymlinkNode instead
String resourceName = D2_CLUSTER_NODE_PREFIX + clusterName;
if (isSymlinkNode(clusterName))
if (SymlinkUtil.isSymlinkNodeOrPath(clusterName))
{
listenToSymlink(clusterName, resourceName);
}
Expand All @@ -163,7 +162,7 @@ public void listenToUris(String clusterName)
{
// if cluster name is a symlink, watch for D2SymlinkNode instead
String resourceName = D2_URI_NODE_PREFIX + clusterName;
if (isSymlinkNode(clusterName))
if (SymlinkUtil.isSymlinkNodeOrPath(clusterName))
{
listenToSymlink(clusterName, resourceName);
}
Expand All @@ -188,11 +187,6 @@ public void listenToService(String serviceName)
});
}

private static boolean isSymlinkNode(String nodeNameOrPath)
{
return nodeNameOrPath != null && nodeNameOrPath.indexOf(SYMLINK_NODE_IDENTIFIER) >= 0;
}

private void listenToSymlink(String name, String fullResourceName)
{
// use full resource name ("/d2/clusters/$FooClusterMater", "/d2/uris/$FooClusterMaster") as the key
Expand Down

0 comments on commit 693eeac

Please sign in to comment.