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



##########
File path: 
solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java
##########
@@ -197,32 +148,78 @@ public AttributeValues fetchAttributes() {
       }
     }
 
-    return new AttributeValuesImpl(nodeToCoreCount,
-        nodeToDiskType,
-        nodeToFreeDisk,
-        nodeToTotalDisk,
-        nodeToHeapUsage,
-        nodeToSystemLoadAverage,
-        syspropSnitchToNodeToValue,
-        metricSnitchToNodeToValue);
+    for (Node node : nodeToReplicaInternalTags.keySet()) {
+      Set<String> tags = nodeToReplicaInternalTags.get(node);
+      Map<String, Map<String, List<Replica>>> infos = 
cloudManager.getNodeStateProvider().getReplicaInfo(node.getName(), tags);
+      infos.entrySet().stream()
+          .filter(entry -> 
requestedCollectionNamesMetrics.containsKey(entry.getKey()))
+          .forEach(entry -> {
+            CollectionMetricsBuilder collectionMetricsBuilder = 
collectionMetricsBuilders
+                .computeIfAbsent(entry.getKey(), c -> new 
CollectionMetricsBuilder());
+            entry.getValue().forEach((shardName, replicas) -> {
+              CollectionMetricsBuilder.ShardMetricsBuilder shardMetricsBuilder 
=
+                  collectionMetricsBuilder.getShardMetricsBuilders()
+                  .computeIfAbsent(shardName, s -> new 
CollectionMetricsBuilder.ShardMetricsBuilder());
+              replicas.forEach(replica -> {
+                CollectionMetricsBuilder.ReplicaMetricsBuilder 
replicaMetricsBuilder =
+                    shardMetricsBuilder.getReplicaMetricsBuilders()
+                    .computeIfAbsent(replica.getName(), n -> new 
CollectionMetricsBuilder.ReplicaMetricsBuilder());
+                replicaMetricsBuilder.setLeader(replica.isLeader());
+                if (replica.isLeader()) {
+                  shardMetricsBuilder.setLeaderMetrics(replicaMetricsBuilder);
+                }
+                Set<ReplicaMetric<?>> requestedMetrics = 
requestedCollectionNamesMetrics.get(replica.getCollection());
+                if (requestedMetrics == null) {
+                  throw new RuntimeException("impossible error");
+                }
+                requestedMetrics.forEach(metric -> {
+                  replicaMetricsBuilder.addMetric(metric, 
replica.get(metric.getInternalName()));
+                });
+              });
+            });
+          });
+    }
+
+
+    Map<String, CollectionMetrics> collectionMetrics = new HashMap<>();
+    collectionMetricsBuilders.forEach((name, builder) -> 
collectionMetrics.put(name, builder.build()));
+
+    return new AttributeValuesImpl(systemSnitchToNodeToValue,
+        metricSnitchToNodeToValue, collectionMetrics);
   }
 
-  private static SolrInfoBean.Group 
getGroupFromMetricRegistry(NodeMetricRegistry registry) {
+  private static SolrInfoBean.Group 
getGroupFromMetricRegistry(NodeMetric.Registry registry) {
     switch (registry) {
       case SOLR_JVM:
         return SolrInfoBean.Group.jvm;
       case SOLR_NODE:
         return SolrInfoBean.Group.node;
+      case SOLR_JETTY:
+        return SolrInfoBean.Group.jetty;
       default:
         throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, 
"Unsupported registry value " + registry);
     }
   }
 
-  public static String getMetricSnitchTag(String metricName, 
NodeMetricRegistry registry) {
-    return SolrClientNodeStateProvider.METRICS_PREFIX + 
SolrMetricManager.getRegistryName(getGroupFromMetricRegistry(registry), 
metricName);
+  public static String getMetricSnitchTag(NodeMetric<?> metric) {
+    if (metric.getRegistry() != null) {
+      // regular registry + metricName
+      return SolrClientNodeStateProvider.METRICS_PREFIX +
+          
SolrMetricManager.getRegistryName(getGroupFromMetricRegistry(metric.getRegistry()))
 + ":" + metric.getInternalName();
+    } else if (ImplicitSnitch.tags.contains(metric.getInternalName())) {

Review comment:
       Well-known tags are simple String-s so they are indistinguishable from 
metric keys (such as `solr.jvm:system.properties:user.name`). We could perhaps 
move this check to `NodeMetricImpl` and add a pseudo-registry of 
`WELL_KNOWN_TAG` ... although this sounds maybe too complicated just to 
prettify these couple lines of code?




----------------------------------------------------------------
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