murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547936763



##########
File path: 
solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java
##########
@@ -113,72 +90,46 @@ public AttributeFetcher fetchFrom(Set<Node> nodes) {
     return this;
   }
 
-  @Override
-  public AttributeFetcher requestMetric(String scope, String metricName) {
-    throw new UnsupportedOperationException("Not yet implemented...");
-  }
+  private static final double GB = 1024 * 1024 * 1024;
 
   @Override
   public AttributeValues fetchAttributes() {
     // TODO Code here only supports node related attributes for now
 
     // Maps in which attribute values will be added
-    Map<Node, Integer> nodeToCoreCount = Maps.newHashMap();
-    Map<Node, DiskHardwareType> nodeToDiskType = Maps.newHashMap();
-    Map<Node, Long> nodeToFreeDisk = Maps.newHashMap();
-    Map<Node, Long> nodeToTotalDisk = Maps.newHashMap();
-    Map<Node, Double> nodeToHeapUsage = Maps.newHashMap();
-    Map<Node, Double> nodeToSystemLoadAverage = Maps.newHashMap();
-    Map<String, Map<Node, String>> syspropSnitchToNodeToValue = 
Maps.newHashMap();
-    Map<String, Map<Node, Double>> metricSnitchToNodeToValue = 
Maps.newHashMap();
+    Map<String, Map<Node, String>> systemSnitchToNodeToValue = new HashMap<>();
+    Map<NodeMetric<?>, Map<Node, Object>> metricSnitchToNodeToValue = new 
HashMap<>();
+    Map<String, CollectionMetricsBuilder> collectionMetricsBuilders = new 
HashMap<>();
+    Map<Node, Set<String>> nodeToReplicaInternalTags = new HashMap<>();
+    Map<String, Set<ReplicaMetric<?>>> requestedCollectionNamesMetrics = 
requestedCollectionMetrics.entrySet().stream()
+        .collect(Collectors.toMap(e -> e.getKey().getName(), e -> 
e.getValue()));
 
     // In order to match the returned values for the various snitches, we need 
to keep track of where each
     // received value goes. Given the target maps are of different types (the 
maps from Node to whatever defined
     // above) we instead pass a function taking two arguments, the node and 
the (non null) returned value,
     // that will cast the value into the appropriate type for the snitch tag 
and insert it into the appropriate map
     // with the node as the key.
-    Map<String, BiConsumer<Node, Object>> allSnitchTagsToInsertion = 
Maps.newHashMap();
-    if (requestedNodeCoreCount) {
-      allSnitchTagsToInsertion.put(ImplicitSnitch.CORES, (node, value) -> 
nodeToCoreCount.put(node, ((Number) value).intValue()));
-    }
-    if (requestedNodeDiskType) {
-      allSnitchTagsToInsertion.put(ImplicitSnitch.DISKTYPE, (node, value) -> {
-        if ("rotational".equals(value)) {
-          nodeToDiskType.put(node, DiskHardwareType.ROTATIONAL);
-        } else if ("ssd".equals(value)) {
-          nodeToDiskType.put(node, DiskHardwareType.SSD);
-        }
-        // unknown disk type: insert no value, returned optional will be empty
-      });
-    }
-    if (requestedNodeFreeDisk) {
-      
allSnitchTagsToInsertion.put(SolrClientNodeStateProvider.Variable.FREEDISK.tagName,
-          // Convert from bytes to GB
-          (node, value) -> nodeToFreeDisk.put(node, ((Number) 
value).longValue() / 1024 / 1024 / 1024));
-    }
-    if (requestedNodeTotalDisk) {
-      
allSnitchTagsToInsertion.put(SolrClientNodeStateProvider.Variable.TOTALDISK.tagName,
-          // Convert from bytes to GB
-          (node, value) -> nodeToTotalDisk.put(node, ((Number) 
value).longValue() / 1024 / 1024 / 1024));
-    }
-    if (requestedNodeHeapUsage) {
-      allSnitchTagsToInsertion.put(ImplicitSnitch.HEAPUSAGE,
-          (node, value) -> nodeToHeapUsage.put(node, ((Number) 
value).doubleValue()));
-    }
-    if (requestedNodeSystemLoadAverage) {
-      allSnitchTagsToInsertion.put(ImplicitSnitch.SYSLOADAVG,
-          (node, value) -> nodeToSystemLoadAverage.put(node, ((Number) 
value).doubleValue()));
-    }
-    for (String sysPropSnitch : requestedNodeSystemPropertiesSnitchTags) {
-      final Map<Node, String> sysPropMap = Maps.newHashMap();
-      syspropSnitchToNodeToValue.put(sysPropSnitch, sysPropMap);
+    Map<String, BiConsumer<Node, Object>> allSnitchTagsToInsertion = new 
HashMap<>();
+    for (String sysPropSnitch : requestedNodeSystemSnitchTags) {
+      final Map<Node, String> sysPropMap = new HashMap<>();
+      systemSnitchToNodeToValue.put(sysPropSnitch, sysPropMap);
       allSnitchTagsToInsertion.put(sysPropSnitch, (node, value) -> 
sysPropMap.put(node, (String) value));
     }
-    for (String metricSnitch : requestedNodeMetricSnitchTags) {
-      final Map<Node, Double> metricMap = Maps.newHashMap();
-      metricSnitchToNodeToValue.put(metricSnitch, metricMap);
-      allSnitchTagsToInsertion.put(metricSnitch, (node, value) -> 
metricMap.put(node, (Double) value));
+    for (NodeMetric<?> metric : requestedNodeMetricSnitchTags) {
+      final Map<Node, Object> metricMap = new HashMap<>();
+      metricSnitchToNodeToValue.put(metric, metricMap);
+      String metricSnitch = getMetricSnitchTag(metric);
+      allSnitchTagsToInsertion.put(metricSnitch, (node, value) -> 
metricMap.put(node, metric.convert(value)));
     }
+    requestedCollectionMetrics.forEach((collection, tags) -> {
+      Set<String> collectionTags = tags.stream().map(tag -> 
tag.getInternalName()).collect(Collectors.toSet());
+      collection.shards().forEach(shard ->
+          shard.replicas().forEach(replica -> {
+            Set<String> perNodeInternalTags = nodeToReplicaInternalTags
+                .computeIfAbsent(replica.getNode(), n -> new HashSet<>());
+            perNodeInternalTags.addAll(collectionTags);
+          }));
+    });
 
     // Now that we know everything we need to fetch (and where to put it), 
just do it.
     for (Node node : nodes) {

Review comment:
       Maybe add a comment here saying fetching could be made concurrent from 
all nodes at once for perf improvement?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to