murblanc commented on a change in pull request #2133: URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547943012
########## 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: Can we have the metric instance itself know if it's based on a well known snitch name or a metrics: name? That would made the condition tests here clearer. Given different constructors are used, that's easy to track. ---------------------------------------------------------------- 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