You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2020/12/09 15:17:23 UTC
[GitHub] [lucene-solr] sigram opened a new pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
sigram opened a new pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133
See JIRA for details.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547935638
##########
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
Review comment:
remove comment
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r546738344
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java
##########
@@ -65,11 +65,16 @@
/**
* For the given node: metric of specific name and registry
*/
- Optional<Double> getMetric(Node node, String metricName, AttributeFetcher.NodeMetricRegistry registry);
+ Optional<Object> getMetric(Node node, String metricName, AttributeFetcher.NodeMetricRegistry registry);
Review comment:
Also, method likely needs to have `Node` in the name given it's a node metric (like method below).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r543196623
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/CollectionMetricsBuilder.java
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement.impl;
+
+import org.apache.solr.cluster.placement.CollectionMetrics;
+import org.apache.solr.cluster.placement.ReplicaMetrics;
+import org.apache.solr.cluster.placement.ShardMetrics;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ *
+ */
+public class CollectionMetricsBuilder {
+
+ final Map<String, ShardMetricsBuilder> shardMetricsBuilders = new HashMap<>();
+
+
+ public void addShardMetrics(String shardName, ShardMetricsBuilder shardMetricsBuilder) {
+ shardMetricsBuilders.put(shardName, shardMetricsBuilder);
+ }
+
+ public CollectionMetrics build() {
+ final Map<String, ShardMetrics> metricsMap = new HashMap<>();
+ shardMetricsBuilders.forEach((shard, builder) -> metricsMap.put(shard, builder.build()));
+ return shardName -> Optional.ofNullable(metricsMap.get(shardName));
+ }
+
+ public static class ShardMetricsBuilder {
+ final Map<String, ReplicaMetricsBuilder> replicaMetricsBuilders = new HashMap<>();
+
+ public ShardMetricsBuilder addReplicaMetrics(String replicaName, ReplicaMetricsBuilder replicaMetricsBuilder) {
+ replicaMetricsBuilders.put(replicaName, replicaMetricsBuilder);
+ return this;
+ }
+
+ public ShardMetricsBuilder setLeaderMetrics(ReplicaMetricsBuilder replicaMetricsBuilder) {
+ replicaMetricsBuilders.put(LEADER, replicaMetricsBuilder);
+ return this;
+ }
+
+ public static final String LEADER = "__leader__";
+
+ public ShardMetrics build() {
+ final Map<String, ReplicaMetrics> metricsMap = new HashMap<>();
+ replicaMetricsBuilders.forEach((name, replicaBuilder) -> {
+ ReplicaMetrics metrics = replicaBuilder.build();
+ metricsMap.put(name, metrics);
+ if (replicaBuilder.leader) {
+ metricsMap.put(LEADER, metrics);
+ }
+ });
+ return new ShardMetrics() {
+ @Override
+ public Optional<ReplicaMetrics> getLeaderMetrics() {
+ return Optional.ofNullable(metricsMap.get(LEADER));
+ }
+
+ @Override
+ public Optional<ReplicaMetrics> getReplicaMetrics(String replicaName) {
+ return Optional.ofNullable(metricsMap.get(replicaName));
+ }
+ };
+ }
+ }
+
+ public static class ReplicaMetricsBuilder {
+ final Map<String, Object> metrics = new HashMap<>();
+ int sizeGB = 0;
Review comment:
Maybe use `Integer` here? Replicas always have size, even new ones, but if we can return null then we can signal that the size is unknown (eg. couldn't be retrieved from the node).
Also, should we use Integer or Long? The unit is GB, I don't think we need Long here (and in other places that deal with disk size).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r546779168
##########
File path: solr/core/src/test/org/apache/solr/cluster/placement/impl/PlacementPluginIntegrationTest.java
##########
@@ -220,6 +231,66 @@ public void testDynamicReconfiguration() throws Exception {
assertNull("no factory should be present", factory);
}
+ @Test
+ public void testAttributeFetcherImpl() throws Exception {
+ CollectionAdminResponse rsp = CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 2)
+ .process(cluster.getSolrClient());
+ assertTrue(rsp.isSuccess());
+ cluster.waitForActiveCollection(COLLECTION, 2, 4);
+ Cluster cluster = new SimpleClusterAbstractionsImpl.ClusterImpl(cloudManager);
+ SolrCollection collection = cluster.getCollection(COLLECTION);
+ AttributeFetcher attributeFetcher = new AttributeFetcherImpl(cloudManager);
+ String someMetricName = "solr.jvm:system.properties:user.name";
+ String sysprop = "user.name";
+ String sysenv = "PWD";
+ attributeFetcher
+ .fetchFrom(cluster.getLiveNodes())
+ .requestNodeHeapUsage()
+ .requestNodeMetric(someMetricName)
+ .requestNodeSystemProperty(sysprop)
+ .requestNodeEnvironmentVariable(sysenv)
+ .requestNodeTotalDisk()
+ .requestNodeFreeDisk()
+ .requestNodeCoresCount()
+ .requestCollectionMetrics(collection, Set.of(ReplicaMetric.QUERY_RATE_1MIN, ReplicaMetric.UPDATE_RATE_1MIN));
+ AttributeValues attributeValues = attributeFetcher.fetchAttributes();
+ String userName = System.getProperty("user.name");
+ String pwd = System.getenv("PWD");
+ // node metrics
+ for (Node node : cluster.getLiveNodes()) {
+ assertTrue("heap usage", attributeValues.getHeapUsage(node).isPresent());
+ assertTrue("total disk", attributeValues.getTotalDisk(node).isPresent());
+ assertTrue("free disk", attributeValues.getFreeDisk(node).isPresent());
+ assertTrue("cores count", attributeValues.getCoresCount(node).isPresent());
+ Optional<Object> userNameOpt = attributeValues.getNodeMetric(node, someMetricName);
+ assertTrue("user.name", userNameOpt.isPresent());
+ assertEquals("userName", userName, userNameOpt.get());
+ Optional<String> syspropOpt = attributeValues.getSystemProperty(node, sysprop);
+ assertTrue("sysprop", syspropOpt.isPresent());
+ assertEquals("user.name sysprop", userName, syspropOpt.get());
+ Optional<String> sysenvOpt = attributeValues.getEnvironmentVariable(node, sysenv);
+ assertTrue("sysenv", sysenvOpt.isPresent());
+ assertEquals("PWD sysenv", pwd, sysenvOpt.get());
+ }
+ assertTrue(attributeValues.getCollectionMetrics(COLLECTION).isPresent());
+ CollectionMetrics collectionMetrics = attributeValues.getCollectionMetrics(COLLECTION).get();
+ collection.shards().forEach(shard -> {
+ Optional<ShardMetrics> shardMetricsOpt = collectionMetrics.getShardMetrics(shard.getShardName());
+ assertTrue("shard metrics", shardMetricsOpt.isPresent());
+ shard.replicas().forEach(replica -> {
+ Optional<ReplicaMetrics> replicaMetricsOpt = shardMetricsOpt.get().getReplicaMetrics(replica.getReplicaName());
+ assertTrue("replica metrics", replicaMetricsOpt.isPresent());
+ ReplicaMetrics replicaMetrics = replicaMetricsOpt.get();
+ // this should always be present
+ assertNotNull("size", replicaMetrics.getReplicaSizeGB());
+ assertTrue("should be greater than 0 but was " + replicaMetrics.getReplicaSizeGB(),
+ replicaMetrics.getReplicaSizeGB() > 0);
+ assertNotNull("queryRate", replicaMetrics.getReplicaMetric(ReplicaMetric.QUERY_RATE_1MIN.getName()));
Review comment:
This will possibly happen earlier in the test code if index size is converted into a normal metric though.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] HoustonPutman commented on pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
HoustonPutman commented on pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#issuecomment-781548967
@sigram is there need to keep this branch around?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547948300
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/MetricAttributeImpl.java
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement.impl;
+
+import org.apache.solr.cluster.placement.MetricAttribute;
+
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Base class for {@link MetricAttribute} implementations.
+ */
+public class MetricAttributeImpl<T> implements MetricAttribute<T> {
+
+ public static final double GB = 1024 * 1024 * 1024;
+
+ /**
+ * Identity converter. It returns the raw value unchanged IFF
+ * the value's type can be cast to the generic type of this attribute,
+ * otherwise it returns null.
+ */
+ @SuppressWarnings("unchecked")
+ public final Function<Object, T> IDENTITY_CONVERTER = v -> {
+ try {
+ return (T) v;
+ } catch (ClassCastException cce) {
+ return null;
+ }
+ };
+
+ /**
+ * Bytes to gigabytes converter. Supports converting number or string
+ * representations of raw values expressed in bytes.
+ */
+ @SuppressWarnings("unchecked")
+ public static final Function<Object, Double> BYTES_TO_GB_CONVERTER = v -> {
+ double sizeInBytes;
+ if (!(v instanceof Number)) {
+ if (v == null) {
+ return null;
+ }
+ try {
+ sizeInBytes = Double.valueOf(String.valueOf(v)).doubleValue();
Review comment:
`Double.parseDouble(String.valueOf(v))` does the job.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547915021
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java
##########
@@ -18,93 +18,53 @@
package org.apache.solr.cluster.placement;
import org.apache.solr.cluster.Node;
+import org.apache.solr.cluster.SolrCollection;
import java.util.Set;
/**
* <p>Instances of this interface are used to fetch various attributes from nodes (and other sources) in the cluster.</p>
*/
public interface AttributeFetcher {
- /**
- * Request the number of cores on each node. To get the value use {@link AttributeValues#getCoresCount(Node)}
- */
- AttributeFetcher requestNodeCoreCount();
-
- /**
- * Request the disk hardware type on each node. To get the value use {@link AttributeValues#getDiskType(Node)}
- */
- AttributeFetcher requestNodeDiskType();
-
- /**
- * Request the free disk size on each node. To get the value use {@link AttributeValues#getFreeDisk(Node)}
- */
- AttributeFetcher requestNodeFreeDisk();
-
- /**
- * Request the total disk size on each node. To get the value use {@link AttributeValues#getTotalDisk(Node)}
- */
- AttributeFetcher requestNodeTotalDisk();
-
- /**
- * Request the heap usage on each node. To get the value use {@link AttributeValues#getHeapUsage(Node)}
- */
- AttributeFetcher requestNodeHeapUsage();
-
- /**
- * Request the system load average on each node. To get the value use {@link AttributeValues#getSystemLoadAverage(Node)}
- */
- AttributeFetcher requestNodeSystemLoadAverage();
-
/**
* Request a given system property on each node. To get the value use {@link AttributeValues#getSystemProperty(Node, String)}
+ * @param name system property name
*/
AttributeFetcher requestNodeSystemProperty(String name);
/**
* Request an environment variable on each node. To get the value use {@link AttributeValues#getEnvironmentVariable(Node, String)}
+ * @param name environment property name
*/
AttributeFetcher requestNodeEnvironmentVariable(String name);
/**
- * Request a node metric from each node. To get the value use {@link AttributeValues#getMetric(Node, String, NodeMetricRegistry)}
+ * Request a node metric from each node. To get the value use {@link AttributeValues#getNodeMetric(Node, NodeMetric)}
+ * @param metric metric to retrieve (see {@link NodeMetric})
*/
- AttributeFetcher requestNodeMetric(String metricName, NodeMetricRegistry registry);
+ AttributeFetcher requestNodeMetric(NodeMetric<?> metric);
+ /**
+ * Request collection-level metrics. To get the values use {@link AttributeValues#getCollectionMetrics(String)}.
+ * Note that this request will fetch information from nodes relevant to the collection
+ * replicas and not the ones specified in {@link #fetchFrom(Set)} (though they may overlap).
+ * @param solrCollection request metrics for this collection
+ * @param metrics metrics to retrieve (see {@link ReplicaMetric})
+ */
+ AttributeFetcher requestCollectionMetrics(SolrCollection solrCollection, Set<ReplicaMetric<?>> metrics);
/**
* The set of nodes from which to fetch all node related attributes. Calling this method is mandatory if any of the {@code requestNode*}
* methods got called.
+ * @param nodes nodes to fetch from
*/
AttributeFetcher fetchFrom(Set<Node> nodes);
- /**
- * Requests a (non node) metric of a given scope and name. To get the value use {@link AttributeValues#getMetric(String, String)}
- */
- AttributeFetcher requestMetric(String scope, String metricName);
-
/**
* Fetches all requested node attributes from all nodes passed to {@link #fetchFrom(Set)} as well as non node attributes
- * (those requested for example using {@link #requestMetric(String, String)}.
+ * (those requested for example using {@link #requestNodeMetric(NodeMetric)}.
Review comment:
Didn't you mean to reference `requestCollectionMetrics` here?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547938685
##########
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()) {
Review comment:
I understand here we might be contacting nodes again to fetch replica metrics. I think this is ok but maybe add a comment that there can be an optimization where node metrics and replica metrics are fetched with a single call to each node?
Here we might even contact each node multiple times I believe depending on the collections we need info about and how their replicas are distributed?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r545160385
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java
##########
@@ -70,6 +71,12 @@
*/
AttributeFetcher requestNodeMetric(String metricName, NodeMetricRegistry registry);
+ /**
+ * Request collection-level metrics. To get the values use {@link AttributeValues#getCollectionMetrics(String)}.
+ * Note that this request will fetch information from nodes relevant to the collection
+ * replicas and not the ones specified in {@link #fetchFrom(Set)} (though they may overlap).
+ */
+ AttributeFetcher requestCollectionMetrics(SolrCollection solrCollection, Set<ReplicaMetric<?>> metricNames);
Review comment:
`metricNames` is not a good name, there are not just names.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r548000385
##########
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()) {
Review comment:
Yes, we make two calls per node - one is `getNodeValues` and the other is `getReplicaInfos`.
The number of calls doesn't depend on the number of collections - we already use a set of nodes that covers all replicas for all interesting collections and we only call `getReplicaInfo` once per node (and it returns all replica infos, regardless of collection).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547921749
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/MetricAttributeImpl.java
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement.impl;
+
+import org.apache.solr.cluster.placement.MetricAttribute;
+
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Base class for {@link MetricAttribute} implementations.
+ */
+public class MetricAttributeImpl<T> implements MetricAttribute<T> {
Review comment:
Make class `abstract`.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r545162052
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetric.java
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement;
+
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Replica metric wrapper that defines a short symbolic name of the metric, the corresponding
+ * internal metric name (as reported in <code>solr.core.[collection].[replica]</code> registry)
+ * and the desired format/unit conversion.
+ */
+public class ReplicaMetric<T> {
+
+ private static final double GB = 1024 * 1024 * 1024;
+ @SuppressWarnings("unchecked")
+ private final Function<Object, T> NO_CONVERTER = v -> {
Review comment:
I'd rather have this named `IDENTITY_CONVERTER`
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r546651221
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetric.java
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement;
+
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Replica metric wrapper that defines a short symbolic name of the metric, the corresponding
+ * internal metric name (as reported in <code>solr.core.[collection].[replica]</code> registry)
+ * and the desired format/unit conversion.
+ */
+public class ReplicaMetric<T> {
Review comment:
`ReplicaMetric` (singular) is a pseudo-enum that encapsulates both the metric name that we want to use (usually something simple), the internal Solr metrics name (which is usually longer and more complicated) and the optional unit/type conversion for the value retrieved from the metrics API.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r546752593
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetrics.java
##########
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.cluster.placement;
+
+import java.util.Optional;
+
+/**
+ *
+ */
+public interface ReplicaMetrics {
+
+ Double getReplicaSizeGB();
+ Optional<Object> getReplicaMetric(String metricName);
Review comment:
This will require casts in implementations anyway, but I agree the external API is cleaner this way.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r546778721
##########
File path: solr/core/src/test/org/apache/solr/cluster/placement/impl/PlacementPluginIntegrationTest.java
##########
@@ -220,6 +231,66 @@ public void testDynamicReconfiguration() throws Exception {
assertNull("no factory should be present", factory);
}
+ @Test
+ public void testAttributeFetcherImpl() throws Exception {
+ CollectionAdminResponse rsp = CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 2)
+ .process(cluster.getSolrClient());
+ assertTrue(rsp.isSuccess());
+ cluster.waitForActiveCollection(COLLECTION, 2, 4);
+ Cluster cluster = new SimpleClusterAbstractionsImpl.ClusterImpl(cloudManager);
+ SolrCollection collection = cluster.getCollection(COLLECTION);
+ AttributeFetcher attributeFetcher = new AttributeFetcherImpl(cloudManager);
+ String someMetricName = "solr.jvm:system.properties:user.name";
+ String sysprop = "user.name";
+ String sysenv = "PWD";
+ attributeFetcher
+ .fetchFrom(cluster.getLiveNodes())
+ .requestNodeHeapUsage()
+ .requestNodeMetric(someMetricName)
+ .requestNodeSystemProperty(sysprop)
+ .requestNodeEnvironmentVariable(sysenv)
+ .requestNodeTotalDisk()
+ .requestNodeFreeDisk()
+ .requestNodeCoresCount()
+ .requestCollectionMetrics(collection, Set.of(ReplicaMetric.QUERY_RATE_1MIN, ReplicaMetric.UPDATE_RATE_1MIN));
+ AttributeValues attributeValues = attributeFetcher.fetchAttributes();
+ String userName = System.getProperty("user.name");
+ String pwd = System.getenv("PWD");
+ // node metrics
+ for (Node node : cluster.getLiveNodes()) {
+ assertTrue("heap usage", attributeValues.getHeapUsage(node).isPresent());
+ assertTrue("total disk", attributeValues.getTotalDisk(node).isPresent());
+ assertTrue("free disk", attributeValues.getFreeDisk(node).isPresent());
+ assertTrue("cores count", attributeValues.getCoresCount(node).isPresent());
+ Optional<Object> userNameOpt = attributeValues.getNodeMetric(node, someMetricName);
+ assertTrue("user.name", userNameOpt.isPresent());
+ assertEquals("userName", userName, userNameOpt.get());
+ Optional<String> syspropOpt = attributeValues.getSystemProperty(node, sysprop);
+ assertTrue("sysprop", syspropOpt.isPresent());
+ assertEquals("user.name sysprop", userName, syspropOpt.get());
+ Optional<String> sysenvOpt = attributeValues.getEnvironmentVariable(node, sysenv);
+ assertTrue("sysenv", sysenvOpt.isPresent());
+ assertEquals("PWD sysenv", pwd, sysenvOpt.get());
+ }
+ assertTrue(attributeValues.getCollectionMetrics(COLLECTION).isPresent());
+ CollectionMetrics collectionMetrics = attributeValues.getCollectionMetrics(COLLECTION).get();
+ collection.shards().forEach(shard -> {
+ Optional<ShardMetrics> shardMetricsOpt = collectionMetrics.getShardMetrics(shard.getShardName());
+ assertTrue("shard metrics", shardMetricsOpt.isPresent());
+ shard.replicas().forEach(replica -> {
+ Optional<ReplicaMetrics> replicaMetricsOpt = shardMetricsOpt.get().getReplicaMetrics(replica.getReplicaName());
+ assertTrue("replica metrics", replicaMetricsOpt.isPresent());
+ ReplicaMetrics replicaMetrics = replicaMetricsOpt.get();
+ // this should always be present
+ assertNotNull("size", replicaMetrics.getReplicaSizeGB());
+ assertTrue("should be greater than 0 but was " + replicaMetrics.getReplicaSizeGB(),
+ replicaMetrics.getReplicaSizeGB() > 0);
+ assertNotNull("queryRate", replicaMetrics.getReplicaMetric(ReplicaMetric.QUERY_RATE_1MIN.getName()));
Review comment:
We need to retrieve the value of a replica metric and verify it (previously it would have been making sure it is cast to the appropriate type, but with the ongoing changes, show how these values are read and make sure things actually works).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r546685808
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/CollectionMetrics.java
##########
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.cluster.placement;
+
+import java.util.Optional;
+
+/**
+ *
+ */
+public interface CollectionMetrics {
Review comment:
Ok for not renaming, but maybe say something in the Javadoc about this? Are there collection level metrics that are not shard metrics?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r543193912
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/ShardMetrics.java
##########
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement;
+
+import java.util.Optional;
+
+/**
+ *
+ */
+public interface ShardMetrics {
+ Optional<ReplicaMetrics> getLeaderMetrics();
+ Optional<ReplicaMetrics> getReplicaMetrics(String replicaName);
Review comment:
Perhaps we should add `iterator()` here too, so that the consumers are not required to know the replica name in advance.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r543195639
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/CollectionMetricsBuilder.java
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement.impl;
+
+import org.apache.solr.cluster.placement.CollectionMetrics;
+import org.apache.solr.cluster.placement.ReplicaMetrics;
+import org.apache.solr.cluster.placement.ShardMetrics;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ *
+ */
+public class CollectionMetricsBuilder {
+
+ final Map<String, ShardMetricsBuilder> shardMetricsBuilders = new HashMap<>();
+
+
+ public void addShardMetrics(String shardName, ShardMetricsBuilder shardMetricsBuilder) {
+ shardMetricsBuilders.put(shardName, shardMetricsBuilder);
+ }
+
+ public CollectionMetrics build() {
+ final Map<String, ShardMetrics> metricsMap = new HashMap<>();
+ shardMetricsBuilders.forEach((shard, builder) -> metricsMap.put(shard, builder.build()));
+ return shardName -> Optional.ofNullable(metricsMap.get(shardName));
+ }
+
+ public static class ShardMetricsBuilder {
+ final Map<String, ReplicaMetricsBuilder> replicaMetricsBuilders = new HashMap<>();
+
+ public ShardMetricsBuilder addReplicaMetrics(String replicaName, ReplicaMetricsBuilder replicaMetricsBuilder) {
+ replicaMetricsBuilders.put(replicaName, replicaMetricsBuilder);
+ return this;
+ }
+
+ public ShardMetricsBuilder setLeaderMetrics(ReplicaMetricsBuilder replicaMetricsBuilder) {
+ replicaMetricsBuilders.put(LEADER, replicaMetricsBuilder);
+ return this;
+ }
+
+ public static final String LEADER = "__leader__";
Review comment:
Make this `@VisibleForTesting` or package-private.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r546733523
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetrics.java
##########
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.cluster.placement;
+
+import java.util.Optional;
+
+/**
+ *
+ */
+public interface ReplicaMetrics {
+
+ Double getReplicaSizeGB();
+ Optional<Object> getReplicaMetric(String metricName);
Review comment:
Can we change this signature into:
`<T> Optional<T> getReplicaMetric(ReplicaMetric<T> replicaMetric);`
to get rid of the type check and casts of the returned value and the `getName()` on the `ReplicaMetric` parameter?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547954091
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactory.java
##########
@@ -194,7 +195,9 @@ public PlacementPlan computePlacement(Cluster cluster, PlacementRequest request,
// Request all needed attributes
attributeFetcher.requestNodeSystemProperty(AVAILABILITY_ZONE_SYSPROP).requestNodeSystemProperty(REPLICA_TYPE_SYSPROP);
- attributeFetcher.requestNodeCoreCount().requestNodeFreeDisk();
+ attributeFetcher
+ .requestNodeMetric(NodeMetricImpl.NUM_CORES)
Review comment:
One option (simpler than a factory and less verbose) is to define an enum with metrics in interface `NodeMetric` and have the implementation convert these to the actual instances (in some `if... else` succession ugliness, like was done for example for the `Registry` enum to not leak the actual registry values).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547932957
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetrics.java
##########
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.cluster.placement;
+
+import java.util.Optional;
+
+/**
+ * Strongly-typed replica-level metrics.
+ */
+public interface ReplicaMetrics {
+
+ <T> Optional<T> getReplicaMetric(ReplicaMetric<T> metric);
Review comment:
Shouldn't this method be called `getReplicaMetricValue`?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r548004312
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/MetricAttributeImpl.java
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement.impl;
+
+import org.apache.solr.cluster.placement.MetricAttribute;
+
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Base class for {@link MetricAttribute} implementations.
+ */
+public class MetricAttributeImpl<T> implements MetricAttribute<T> {
+
+ public static final double GB = 1024 * 1024 * 1024;
+
+ /**
+ * Identity converter. It returns the raw value unchanged IFF
+ * the value's type can be cast to the generic type of this attribute,
+ * otherwise it returns null.
+ */
+ @SuppressWarnings("unchecked")
+ public final Function<Object, T> IDENTITY_CONVERTER = v -> {
+ try {
+ return (T) v;
+ } catch (ClassCastException cce) {
+ return null;
+ }
+ };
+
+ /**
+ * Bytes to gigabytes converter. Supports converting number or string
+ * representations of raw values expressed in bytes.
+ */
+ @SuppressWarnings("unchecked")
+ public static final Function<Object, Double> BYTES_TO_GB_CONVERTER = v -> {
+ double sizeInBytes;
+ if (!(v instanceof Number)) {
+ if (v == null) {
+ return null;
+ }
+ try {
+ sizeInBytes = Double.valueOf(String.valueOf(v)).doubleValue();
+ } catch (Exception nfe) {
+ return null;
+ }
+ } else {
+ sizeInBytes = ((Number) v).doubleValue();
+ }
+ return sizeInBytes / GB;
+ };
+
+ protected final String name;
+ protected final String internalName;
+ protected final Function<Object, T> converter;
+
+ /**
+ * Create a metric attribute.
+ * @param name short-hand name that identifies this attribute.
+ * @param internalName internal name of a Solr metric.
+ */
+ public MetricAttributeImpl(String name, String internalName) {
+ this(name, internalName, null);
+ }
+
+ /**
+ * Create a metric attribute.
+ * @param name short-hand name that identifies this attribute.
+ * @param internalName internal name of a Solr metric.
+ * @param converter optional raw value converter. If null then
+ * {@link #IDENTITY_CONVERTER} will be used.
+ */
+ public MetricAttributeImpl(String name, String internalName, Function<Object, T> converter) {
+ Objects.requireNonNull(name);
+ Objects.requireNonNull(internalName);
+ this.name = name;
+ this.internalName = internalName;
+ if (converter == null) {
+ this.converter = IDENTITY_CONVERTER;
+ } else {
+ this.converter = converter;
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getInternalName() {
+ return internalName;
+ }
+
+ @Override
+ public Function<Object, T> getConverter() {
+ return converter;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ MetricAttribute<?> that = (MetricAttribute<?>) o;
+ return name.equals(that.getName()) && internalName.equals(that.getInternalName()) && converter.equals(that.getConverter());
Review comment:
Ah, this was a problem with class hierarchy - it should cast to `MetricAttributeImpl`, I'll fix this.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547935041
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java
##########
@@ -33,18 +37,18 @@
import java.lang.invoke.MethodHandles;
import java.util.*;
import java.util.function.BiConsumer;
+import java.util.stream.Collectors;
+/**
+ * Implementation of {@link AttributeFetcher} that uses {@link SolrCloudManager}
+ * to access Solr cluster details.
+ */
public class AttributeFetcherImpl implements AttributeFetcher {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- boolean requestedNodeCoreCount;
- boolean requestedNodeDiskType;
- boolean requestedNodeFreeDisk;
- boolean requestedNodeTotalDisk;
- boolean requestedNodeHeapUsage;
- boolean requestedNodeSystemLoadAverage;
- Set<String> requestedNodeSystemPropertiesSnitchTags = new HashSet<>();
- Set<String> requestedNodeMetricSnitchTags = new HashSet<>();
+ Set<String> requestedNodeSystemSnitchTags = new HashSet<>();
Review comment:
Oh I see it's used for both system properties and environment variables... In which case I'd drop system in the name.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547952921
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactory.java
##########
@@ -194,7 +195,9 @@ public PlacementPlan computePlacement(Cluster cluster, PlacementRequest request,
// Request all needed attributes
attributeFetcher.requestNodeSystemProperty(AVAILABILITY_ZONE_SYSPROP).requestNodeSystemProperty(REPLICA_TYPE_SYSPROP);
- attributeFetcher.requestNodeCoreCount().requestNodeFreeDisk();
+ attributeFetcher
+ .requestNodeMetric(NodeMetricImpl.NUM_CORES)
Review comment:
Leaking implementation to the plugin code here.
Something that I think we managed to avoid until now. Shall we continue to try? And expose these metric instances through a factory that will have an interface visible to the client? Or consider it's not worth the trouble?
From `NodeMetricImpl` dependencies go to `ImplicitSnitch` to `ZkStateReader` and to basically the whole codebase.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547920372
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/MetricAttribute.java
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement;
+
+import java.util.function.Function;
+
+/**
+ * Metric-related attribute of a node or replica. It defines a short symbolic name of the metric, the corresponding
+ * internal metric name and the desired format/unit conversion. Generic type
+ * defines the type of converted values of this attribute.
+ */
+public interface MetricAttribute<T> {
Review comment:
I find it a bit weird (naming wise) that interface `MetricAttribute` has subinterfaces `NodeMetric` and `ReplicaMetric`.
Ideally I'd drop the `Attribute` part of the interface name here (and in `MetricAttributeImpl`).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r546766696
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/ShardMetrics.java
##########
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement;
+
+import java.util.Optional;
+
+/**
+ *
+ */
+public interface ShardMetrics {
+ Optional<ReplicaMetrics> getLeaderMetrics();
+ Optional<ReplicaMetrics> getReplicaMetrics(String replicaName);
Review comment:
Yes. As well as `ShardMetrics` iterator in `CollectionMetrics`.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547949666
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/MetricAttributeImpl.java
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement.impl;
+
+import org.apache.solr.cluster.placement.MetricAttribute;
+
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Base class for {@link MetricAttribute} implementations.
+ */
+public class MetricAttributeImpl<T> implements MetricAttribute<T> {
+
+ public static final double GB = 1024 * 1024 * 1024;
+
+ /**
+ * Identity converter. It returns the raw value unchanged IFF
+ * the value's type can be cast to the generic type of this attribute,
+ * otherwise it returns null.
+ */
+ @SuppressWarnings("unchecked")
+ public final Function<Object, T> IDENTITY_CONVERTER = v -> {
+ try {
+ return (T) v;
+ } catch (ClassCastException cce) {
+ return null;
+ }
+ };
+
+ /**
+ * Bytes to gigabytes converter. Supports converting number or string
+ * representations of raw values expressed in bytes.
+ */
+ @SuppressWarnings("unchecked")
+ public static final Function<Object, Double> BYTES_TO_GB_CONVERTER = v -> {
+ double sizeInBytes;
+ if (!(v instanceof Number)) {
+ if (v == null) {
+ return null;
+ }
+ try {
+ sizeInBytes = Double.valueOf(String.valueOf(v)).doubleValue();
+ } catch (Exception nfe) {
+ return null;
+ }
+ } else {
+ sizeInBytes = ((Number) v).doubleValue();
+ }
+ return sizeInBytes / GB;
+ };
+
+ protected final String name;
+ protected final String internalName;
+ protected final Function<Object, T> converter;
+
+ /**
+ * Create a metric attribute.
+ * @param name short-hand name that identifies this attribute.
+ * @param internalName internal name of a Solr metric.
+ */
+ public MetricAttributeImpl(String name, String internalName) {
+ this(name, internalName, null);
+ }
+
+ /**
+ * Create a metric attribute.
+ * @param name short-hand name that identifies this attribute.
+ * @param internalName internal name of a Solr metric.
+ * @param converter optional raw value converter. If null then
+ * {@link #IDENTITY_CONVERTER} will be used.
+ */
+ public MetricAttributeImpl(String name, String internalName, Function<Object, T> converter) {
+ Objects.requireNonNull(name);
+ Objects.requireNonNull(internalName);
+ this.name = name;
+ this.internalName = internalName;
+ if (converter == null) {
+ this.converter = IDENTITY_CONVERTER;
+ } else {
+ this.converter = converter;
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getInternalName() {
+ return internalName;
+ }
+
+ @Override
+ public Function<Object, T> getConverter() {
+ return converter;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ MetricAttribute<?> that = (MetricAttribute<?>) o;
+ return name.equals(that.getName()) && internalName.equals(that.getInternalName()) && converter.equals(that.getConverter());
Review comment:
Why the inconsistency between direct field access for `this` instance and getter for `that`?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547976517
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetrics.java
##########
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.cluster.placement;
+
+import java.util.Optional;
+
+/**
+ * Strongly-typed replica-level metrics.
+ */
+public interface ReplicaMetrics {
+
+ <T> Optional<T> getReplicaMetric(ReplicaMetric<T> metric);
Review comment:
`AttributeValues.getNodeMetric` follows the same pattern .. maybe both are wrong (or right?).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram closed pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram closed pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547957901
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java
##########
@@ -18,93 +18,53 @@
package org.apache.solr.cluster.placement;
import org.apache.solr.cluster.Node;
+import org.apache.solr.cluster.SolrCollection;
import java.util.Set;
/**
* <p>Instances of this interface are used to fetch various attributes from nodes (and other sources) in the cluster.</p>
*/
public interface AttributeFetcher {
- /**
- * Request the number of cores on each node. To get the value use {@link AttributeValues#getCoresCount(Node)}
- */
- AttributeFetcher requestNodeCoreCount();
-
- /**
- * Request the disk hardware type on each node. To get the value use {@link AttributeValues#getDiskType(Node)}
- */
- AttributeFetcher requestNodeDiskType();
-
- /**
- * Request the free disk size on each node. To get the value use {@link AttributeValues#getFreeDisk(Node)}
- */
- AttributeFetcher requestNodeFreeDisk();
-
- /**
- * Request the total disk size on each node. To get the value use {@link AttributeValues#getTotalDisk(Node)}
- */
- AttributeFetcher requestNodeTotalDisk();
-
- /**
- * Request the heap usage on each node. To get the value use {@link AttributeValues#getHeapUsage(Node)}
- */
- AttributeFetcher requestNodeHeapUsage();
-
- /**
- * Request the system load average on each node. To get the value use {@link AttributeValues#getSystemLoadAverage(Node)}
- */
- AttributeFetcher requestNodeSystemLoadAverage();
-
/**
* Request a given system property on each node. To get the value use {@link AttributeValues#getSystemProperty(Node, String)}
+ * @param name system property name
*/
AttributeFetcher requestNodeSystemProperty(String name);
/**
* Request an environment variable on each node. To get the value use {@link AttributeValues#getEnvironmentVariable(Node, String)}
+ * @param name environment property name
*/
AttributeFetcher requestNodeEnvironmentVariable(String name);
/**
- * Request a node metric from each node. To get the value use {@link AttributeValues#getMetric(Node, String, NodeMetricRegistry)}
+ * Request a node metric from each node. To get the value use {@link AttributeValues#getNodeMetric(Node, NodeMetric)}
+ * @param metric metric to retrieve (see {@link NodeMetric})
*/
- AttributeFetcher requestNodeMetric(String metricName, NodeMetricRegistry registry);
+ AttributeFetcher requestNodeMetric(NodeMetric<?> metric);
+ /**
+ * Request collection-level metrics. To get the values use {@link AttributeValues#getCollectionMetrics(String)}.
+ * Note that this request will fetch information from nodes relevant to the collection
+ * replicas and not the ones specified in {@link #fetchFrom(Set)} (though they may overlap).
+ * @param solrCollection request metrics for this collection
+ * @param metrics metrics to retrieve (see {@link ReplicaMetric})
+ */
+ AttributeFetcher requestCollectionMetrics(SolrCollection solrCollection, Set<ReplicaMetric<?>> metrics);
/**
* The set of nodes from which to fetch all node related attributes. Calling this method is mandatory if any of the {@code requestNode*}
* methods got called.
+ * @param nodes nodes to fetch from
*/
AttributeFetcher fetchFrom(Set<Node> nodes);
- /**
- * Requests a (non node) metric of a given scope and name. To get the value use {@link AttributeValues#getMetric(String, String)}
- */
- AttributeFetcher requestMetric(String scope, String metricName);
-
/**
* Fetches all requested node attributes from all nodes passed to {@link #fetchFrom(Set)} as well as non node attributes
- * (those requested for example using {@link #requestMetric(String, String)}.
+ * (those requested for example using {@link #requestNodeMetric(NodeMetric)}.
Review comment:
Ah, this is more complicated and it needs to be documented properly - there's a note in `requestCollectionMetrics` about this but I can add it here, too. Collection metrics are fetched from whatever nodes host the replicas, and `fetchFrom` doesn't affect this.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r546775011
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/CollectionMetricsBuilder.java
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement.impl;
+
+import org.apache.solr.cluster.placement.CollectionMetrics;
+import org.apache.solr.cluster.placement.ReplicaMetrics;
+import org.apache.solr.cluster.placement.ShardMetrics;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ *
+ */
+public class CollectionMetricsBuilder {
+
+ final Map<String, ShardMetricsBuilder> shardMetricsBuilders = new HashMap<>();
+
+
+ public Map<String, ShardMetricsBuilder> getShardMetricsBuilders() {
+ return shardMetricsBuilders;
+ }
+
+ public CollectionMetrics build() {
+ final Map<String, ShardMetrics> metricsMap = new HashMap<>();
+ shardMetricsBuilders.forEach((shard, builder) -> metricsMap.put(shard, builder.build()));
+ return shardName -> Optional.ofNullable(metricsMap.get(shardName));
+ }
+
+ public static class ShardMetricsBuilder {
+ final Map<String, ReplicaMetricsBuilder> replicaMetricsBuilders = new HashMap<>();
+
+ public Map<String, ReplicaMetricsBuilder> getReplicaMetricsBuilders() {
+ return replicaMetricsBuilders;
+ }
+
+ public ShardMetricsBuilder setLeaderMetrics(ReplicaMetricsBuilder replicaMetricsBuilder) {
+ replicaMetricsBuilders.put(LEADER, replicaMetricsBuilder);
+ return this;
+ }
+
+ static final String LEADER = "__leader__";
Review comment:
I'd rather have a dedicated variable in the `ShardMetricsBuilder` referencing the leader's `ReplicaMetricsBuilder` instance and a dedicated variable in the anonymous subclass of `ShardMetrics` doing the same.
Will be cleaner to read and not less efficient.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547934318
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java
##########
@@ -33,18 +37,18 @@
import java.lang.invoke.MethodHandles;
import java.util.*;
import java.util.function.BiConsumer;
+import java.util.stream.Collectors;
+/**
+ * Implementation of {@link AttributeFetcher} that uses {@link SolrCloudManager}
+ * to access Solr cluster details.
+ */
public class AttributeFetcherImpl implements AttributeFetcher {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- boolean requestedNodeCoreCount;
- boolean requestedNodeDiskType;
- boolean requestedNodeFreeDisk;
- boolean requestedNodeTotalDisk;
- boolean requestedNodeHeapUsage;
- boolean requestedNodeSystemLoadAverage;
- Set<String> requestedNodeSystemPropertiesSnitchTags = new HashSet<>();
- Set<String> requestedNodeMetricSnitchTags = new HashSet<>();
+ Set<String> requestedNodeSystemSnitchTags = new HashSet<>();
Review comment:
I preferred the previous name `requestedNodeSystemPropertiesSnitchTags` ("system" by itself is too vague).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r548489854
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/NodeMetricImpl.java
##########
@@ -67,7 +67,7 @@ public NodeMetricImpl(String key) {
public NodeMetricImpl(String key, Function<Object, T> converter) {
super(key, key, converter);
Review comment:
Maybe replace implementation by `this(key, Registry.UNSPECIFIED, key, converter);` ?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r546776315
##########
File path: solr/core/src/test/org/apache/solr/cluster/placement/Builders.java
##########
@@ -48,7 +49,11 @@ public static CollectionBuilder newCollectionBuilder(String collectionName) {
public ClusterBuilder initializeLiveNodes(int countNodes) {
nodeBuilders = new LinkedList<>();
for (int n = 0; n < countNodes; n++) {
- nodeBuilders.add(new NodeBuilder().setNodeName("node_" + n)); // Default name, can be changed
+ NodeBuilder nodeBuilder = new NodeBuilder().setNodeName("node_" + n); // Default name, can be changed
+ nodeBuilder.setTotalDiskGB(10000.0);
+ nodeBuilder.setFreeDiskGB(5000.0);
+ nodeBuilder.setDiskType(AttributeFetcher.DiskHardwareType.SSD);
Review comment:
I thought disk type was going away?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r548488944
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/CollectionMetricsBuilder.java
##########
@@ -61,18 +80,19 @@ public ShardMetrics build() {
replicaMetricsBuilders.forEach((name, replicaBuilder) -> {
ReplicaMetrics metrics = replicaBuilder.build();
metricsMap.put(name, metrics);
- // skip leader from map
if (replicaBuilder.leader) {
if (leaderMetricsBuilder == null) {
leaderMetricsBuilder = replicaBuilder;
}
- if (replicaBuilder != leaderMetricsBuilder) {
Review comment:
Why did you remove that check? It doesn't deserve a new if statement (just `else` to the `leaderMetricsBuilder == null` condition is equivalent) but it's interesting, it means two replicas pretend they are shard leader... Maybe error log?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547940278
##########
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);
Review comment:
If we do add a `NULL` or `UNDEFINED` `Registry` enum value, it's ok to handle it as `default` here and throw exception (although it getting all the way to here likely denotes a bug in our 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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r545151767
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java
##########
@@ -65,11 +65,16 @@
/**
* For the given node: metric of specific name and registry
*/
- Optional<Double> getMetric(Node node, String metricName, AttributeFetcher.NodeMetricRegistry registry);
+ Optional<Object> getMetric(Node node, String metricName, AttributeFetcher.NodeMetricRegistry registry);
/**
- * Get a non node related metric of specific scope and name
+ * Get any metric using a fully-qualified metric key.
*/
- Optional<Double> getMetric(String scope, String metricName);
+ Optional<Object> getNodeMetric(Node node, String metricKey);
+
+ /**
+ *
+ */
+ Optional<CollectionMetrics> getCollectionMetrics(String collectionName);
Review comment:
We have a lack of symmetry now between node metrics that return mere `Object`s and collection/shard/replica metrics that are defined types (eventually resolving to a `ReplicaMetrics` that can return an object or specific typed metrics - currently only replica size GB).
Maybe we should call something different the "typed" metric interfaces to distinguish between them and the object being eventually returned?
I suggest that rather than calling the interface `CollectionMetrics`, we call it `CollectionMetricContainer` (and similarly for Shard and Replica). That would help me.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r545154753
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetric.java
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement;
+
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Replica metric wrapper that defines a short symbolic name of the metric, the corresponding
+ * internal metric name (as reported in <code>solr.core.[collection].[replica]</code> registry)
+ * and the desired format/unit conversion.
+ */
+public class ReplicaMetric<T> {
Review comment:
Now I'm confused between `ReplicaMetric` and `ReplicaMetrics`.... So take previous comments with a grain of salt I might have gotten things wrong.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547915611
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java
##########
@@ -65,11 +35,10 @@
/**
* For the given node: metric of specific name and registry
Review comment:
Javadoc comment needs updating
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547930986
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/MetricAttribute.java
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement;
+
+import java.util.function.Function;
+
+/**
+ * Metric-related attribute of a node or replica. It defines a short symbolic name of the metric, the corresponding
+ * internal metric name and the desired format/unit conversion. Generic type
+ * defines the type of converted values of this attribute.
+ */
+public interface MetricAttribute<T> {
+
+ /**
+ * Return the short-hand name that identifies this attribute.
+ */
+ String getName();
+
+ /**
+ * Return the internal name of a Solr metric associated with this attribute.
+ */
+ String getInternalName();
+
+ /**
+ * Conversion function to convert formats/units of raw values.
+ */
+ Function<Object, T> getConverter();
Review comment:
I don't see the value in exposing the converter function in the interface. `convert` method below is sufficient (and its default implementation moved to the abstract implementation `MetricAttributeImpl` (or `MetricImpl` as I'd prefer it to be named)).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547969376
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/MetricAttribute.java
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement;
+
+import java.util.function.Function;
+
+/**
+ * Metric-related attribute of a node or replica. It defines a short symbolic name of the metric, the corresponding
+ * internal metric name and the desired format/unit conversion. Generic type
+ * defines the type of converted values of this attribute.
+ */
+public interface MetricAttribute<T> {
Review comment:
There's already a `Metric` class on the classpath, it comes from Dropwizard Metrics... I wanted to avoid the naming conflict. Let me think...
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547997354
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java
##########
@@ -33,18 +37,18 @@
import java.lang.invoke.MethodHandles;
import java.util.*;
import java.util.function.BiConsumer;
+import java.util.stream.Collectors;
+/**
+ * Implementation of {@link AttributeFetcher} that uses {@link SolrCloudManager}
+ * to access Solr cluster details.
+ */
public class AttributeFetcherImpl implements AttributeFetcher {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- boolean requestedNodeCoreCount;
- boolean requestedNodeDiskType;
- boolean requestedNodeFreeDisk;
- boolean requestedNodeTotalDisk;
- boolean requestedNodeHeapUsage;
- boolean requestedNodeSystemLoadAverage;
- Set<String> requestedNodeSystemPropertiesSnitchTags = new HashSet<>();
- Set<String> requestedNodeMetricSnitchTags = new HashSet<>();
+ Set<String> requestedNodeSystemSnitchTags = new HashSet<>();
Review comment:
I disagree, having "system" here makes it clearer what category of metrics we want to keep here. In any case, this is an internal variable name...
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r546737245
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java
##########
@@ -65,11 +65,16 @@
/**
* For the given node: metric of specific name and registry
*/
- Optional<Double> getMetric(Node node, String metricName, AttributeFetcher.NodeMetricRegistry registry);
+ Optional<Object> getMetric(Node node, String metricName, AttributeFetcher.NodeMetricRegistry registry);
Review comment:
If `ReplicaMetrics` can be improved as suggested by a [comment](https://github.com/apache/lucene-solr/pull/2133/files#r546733523) there to make better use of `ReplicaMetric<T>` instances and not use generic `Object` values, can we generalize the concept?
Either rename `ReplicaMetric` and have it define metrics for all types of cluster entities (i.e. including nodes) or introduce a similar `NodeMetric<T>` class that would be used here as well as in `AttributeFetcher`?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r546650524
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java
##########
@@ -65,11 +65,16 @@
/**
* For the given node: metric of specific name and registry
*/
- Optional<Double> getMetric(Node node, String metricName, AttributeFetcher.NodeMetricRegistry registry);
+ Optional<Object> getMetric(Node node, String metricName, AttributeFetcher.NodeMetricRegistry registry);
/**
- * Get a non node related metric of specific scope and name
+ * Get any metric using a fully-qualified metric key.
*/
- Optional<Double> getMetric(String scope, String metricName);
+ Optional<Object> getNodeMetric(Node node, String metricKey);
+
+ /**
+ *
+ */
+ Optional<CollectionMetrics> getCollectionMetrics(String collectionName);
Review comment:
Hmm... It's clear that this type is not a primitive. Similarly, we're not calling the container for attribute values an `AttributeValuesContainer`. I don't think this change here would actually help in understanding this relationship.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547918055
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/NodeMetric.java
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.cluster.placement;
+
+/**
+ * Node metric identifier, corresponding
+ * to a node-level metric registry and the internal metric name.
+ * Alternatively this identified may use a fully-qualified metric key,
Review comment:
typo: identified -> identifier
Also, the second part of the Javadoc comment seems more appropriate for the implementation rather than the interface.
Can we add to the `Registry` enum a `NULL` or `UNSPECIFIED` value so that the implementation registry is never `null`?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r545146525
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java
##########
@@ -65,11 +65,16 @@
/**
* For the given node: metric of specific name and registry
*/
- Optional<Double> getMetric(Node node, String metricName, AttributeFetcher.NodeMetricRegistry registry);
+ Optional<Object> getMetric(Node node, String metricName, AttributeFetcher.NodeMetricRegistry registry);
/**
- * Get a non node related metric of specific scope and name
+ * Get any metric using a fully-qualified metric key.
*/
- Optional<Double> getMetric(String scope, String metricName);
+ Optional<Object> getNodeMetric(Node node, String metricKey);
+
+ /**
+ *
Review comment:
Javadoc :-)
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r543196623
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/impl/CollectionMetricsBuilder.java
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cluster.placement.impl;
+
+import org.apache.solr.cluster.placement.CollectionMetrics;
+import org.apache.solr.cluster.placement.ReplicaMetrics;
+import org.apache.solr.cluster.placement.ShardMetrics;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ *
+ */
+public class CollectionMetricsBuilder {
+
+ final Map<String, ShardMetricsBuilder> shardMetricsBuilders = new HashMap<>();
+
+
+ public void addShardMetrics(String shardName, ShardMetricsBuilder shardMetricsBuilder) {
+ shardMetricsBuilders.put(shardName, shardMetricsBuilder);
+ }
+
+ public CollectionMetrics build() {
+ final Map<String, ShardMetrics> metricsMap = new HashMap<>();
+ shardMetricsBuilders.forEach((shard, builder) -> metricsMap.put(shard, builder.build()));
+ return shardName -> Optional.ofNullable(metricsMap.get(shardName));
+ }
+
+ public static class ShardMetricsBuilder {
+ final Map<String, ReplicaMetricsBuilder> replicaMetricsBuilders = new HashMap<>();
+
+ public ShardMetricsBuilder addReplicaMetrics(String replicaName, ReplicaMetricsBuilder replicaMetricsBuilder) {
+ replicaMetricsBuilders.put(replicaName, replicaMetricsBuilder);
+ return this;
+ }
+
+ public ShardMetricsBuilder setLeaderMetrics(ReplicaMetricsBuilder replicaMetricsBuilder) {
+ replicaMetricsBuilders.put(LEADER, replicaMetricsBuilder);
+ return this;
+ }
+
+ public static final String LEADER = "__leader__";
+
+ public ShardMetrics build() {
+ final Map<String, ReplicaMetrics> metricsMap = new HashMap<>();
+ replicaMetricsBuilders.forEach((name, replicaBuilder) -> {
+ ReplicaMetrics metrics = replicaBuilder.build();
+ metricsMap.put(name, metrics);
+ if (replicaBuilder.leader) {
+ metricsMap.put(LEADER, metrics);
+ }
+ });
+ return new ShardMetrics() {
+ @Override
+ public Optional<ReplicaMetrics> getLeaderMetrics() {
+ return Optional.ofNullable(metricsMap.get(LEADER));
+ }
+
+ @Override
+ public Optional<ReplicaMetrics> getReplicaMetrics(String replicaName) {
+ return Optional.ofNullable(metricsMap.get(replicaName));
+ }
+ };
+ }
+ }
+
+ public static class ReplicaMetricsBuilder {
+ final Map<String, Object> metrics = new HashMap<>();
+ int sizeGB = 0;
Review comment:
Maybe use `Integer` here? Replicas always have size, even new ones, but if we can return null then we can signal that the size is unknown (eg. couldn't be retrieved from the node).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r545153262
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/CollectionMetrics.java
##########
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.cluster.placement;
+
+import java.util.Optional;
+
+/**
+ *
+ */
+public interface CollectionMetrics {
Review comment:
As suggested elsewhere, I'd rather have this interface named `CollectionMetricsContainer`.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r545143577
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java
##########
@@ -78,13 +85,15 @@
AttributeFetcher fetchFrom(Set<Node> nodes);
/**
- * Requests a (non node) metric of a given scope and name. To get the value use {@link AttributeValues#getMetric(String, String)}
+ * Requests any metric from any metric registry on each node, using a fully-qualified metric key,
+ * for example <code>solr.jvm:system.properties:user.name</code>.
+ * To get the value use {@link AttributeValues#getNodeMetric(Node, String)}
*/
- AttributeFetcher requestMetric(String scope, String metricName);
+ AttributeFetcher requestNodeMetric(String metricKey);
Review comment:
Move this method closer to the other `requestNodeMetric` above.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r545897320
##########
File path: solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java
##########
@@ -70,6 +71,12 @@
*/
AttributeFetcher requestNodeMetric(String metricName, NodeMetricRegistry registry);
+ /**
+ * Request collection-level metrics. To get the values use {@link AttributeValues#getCollectionMetrics(String)}.
+ * Note that this request will fetch information from nodes relevant to the collection
+ * replicas and not the ones specified in {@link #fetchFrom(Set)} (though they may overlap).
+ */
+ AttributeFetcher requestCollectionMetrics(SolrCollection solrCollection, Set<ReplicaMetric<?>> metricNames);
Review comment:
Initially this was a String but then I realized we need more metadata, I'll fix it.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] sigram commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
sigram commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r548001677
##########
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");
Review comment:
I'll remove this check.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene-solr] murblanc commented on a change in pull request #2133: SOLR-15019: Replica placement API needs a way to fetch existing replica metrics
Posted by GitBox <gi...@apache.org>.
murblanc commented on a change in pull request #2133:
URL: https://github.com/apache/lucene-solr/pull/2133#discussion_r547939345
##########
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");
Review comment:
Likely an error log with the value of `replica.getCollection()` (or add the value to the exception text) could help understand how the impossible happens. Or just remove this check and let the NPE bubble up?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org