You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2021/03/10 10:06:48 UTC

[lucene] 01/17: SOLR-15019: Initial draft of the APIs.

This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch jira/solr-15019
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit 7562aa2904f7fecc93116b5168fc44405fc71ad7
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Wed Dec 9 16:14:30 2020 +0100

    SOLR-15019: Initial draft of the APIs.
---
 .../solr/cluster/placement/AttributeFetcher.java   | 15 +++++++++---
 .../solr/cluster/placement/AttributeValues.java    | 10 ++++++--
 .../solr/cluster/placement/CollectionMetrics.java  | 28 ++++++++++++++++++++++
 .../solr/cluster/placement/ReplicaMetrics.java     | 28 ++++++++++++++++++++++
 .../solr/cluster/placement/ShardMetrics.java       | 27 +++++++++++++++++++++
 .../placement/impl/AttributeFetcherImpl.java       | 15 ++++++++----
 .../placement/impl/AttributeValuesImpl.java        |  9 ++++++-
 .../cluster/placement/AttributeFetcherForTest.java | 10 ++++++--
 8 files changed, 130 insertions(+), 12 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java b/solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java
index 9578326..3f1f004 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java
@@ -18,6 +18,7 @@
 package org.apache.solr.cluster.placement;
 
 import org.apache.solr.cluster.Node;
+import org.apache.solr.cluster.SolrCollection;
 
 import java.util.Set;
 
@@ -70,6 +71,12 @@ public interface AttributeFetcher {
    */
   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<String> metricNames);
 
   /**
    * The set of nodes from which to fetch all node related attributes. Calling this method is mandatory if any of the {@code requestNode*}
@@ -78,13 +85,15 @@ public interface AttributeFetcher {
   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);
 
   /**
    * 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(String)}.
    *
    * @return An instance allowing retrieval of all attributed that could be fetched.
    */
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java b/solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java
index 24fcb6f..f2854a0 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java
@@ -18,6 +18,7 @@
 package org.apache.solr.cluster.placement;
 
 import org.apache.solr.cluster.Node;
+import org.apache.solr.cluster.SolrCollection;
 
 import java.util.Optional;
 
@@ -69,7 +70,12 @@ public interface AttributeValues {
 
 
   /**
-   * 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);
 }
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/CollectionMetrics.java b/solr/core/src/java/org/apache/solr/cluster/placement/CollectionMetrics.java
new file mode 100644
index 0000000..8336881
--- /dev/null
+++ b/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 {
+
+  Optional<ShardMetrics> getShardMetrics(String shardName);
+}
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetrics.java b/solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetrics.java
new file mode 100644
index 0000000..5c08760
--- /dev/null
+++ b/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;
+
+/**
+ *
+ */
+public interface ReplicaMetrics {
+  int getReplicaSizeGB();
+  Optional<Object> getReplicaMetric(String metricName);
+}
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/ShardMetrics.java b/solr/core/src/java/org/apache/solr/cluster/placement/ShardMetrics.java
new file mode 100644
index 0000000..3f63316
--- /dev/null
+++ b/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);
+}
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java b/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java
index 3c3bf49..6a09836 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java
@@ -20,6 +20,7 @@ package org.apache.solr.cluster.placement.impl;
 import com.google.common.collect.Maps;
 import org.apache.solr.client.solrj.cloud.SolrCloudManager;
 import org.apache.solr.client.solrj.impl.SolrClientNodeStateProvider;
+import org.apache.solr.cluster.SolrCollection;
 import org.apache.solr.cluster.placement.AttributeFetcher;
 import org.apache.solr.cluster.placement.AttributeValues;
 import org.apache.solr.cluster.Node;
@@ -108,14 +109,20 @@ public class AttributeFetcherImpl implements AttributeFetcher {
   }
 
   @Override
-  public AttributeFetcher fetchFrom(Set<Node> nodes) {
-    this.nodes = nodes;
+  public AttributeFetcher requestNodeMetric(String metricKey) {
+    requestedNodeMetricSnitchTags.add(SolrClientNodeStateProvider.METRICS_PREFIX + metricKey);
     return this;
   }
 
   @Override
-  public AttributeFetcher requestMetric(String scope, String metricName) {
-    throw new UnsupportedOperationException("Not yet implemented...");
+  public AttributeFetcher requestCollectionMetrics(SolrCollection solrCollection, Set<String> metricNames) {
+    return null;
+  }
+
+  @Override
+  public AttributeFetcher fetchFrom(Set<Node> nodes) {
+    this.nodes = nodes;
+    return this;
   }
 
   @Override
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeValuesImpl.java b/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeValuesImpl.java
index ce68094..4f8b694 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeValuesImpl.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeValuesImpl.java
@@ -20,6 +20,7 @@ package org.apache.solr.cluster.placement.impl;
 import org.apache.solr.cluster.placement.AttributeFetcher;
 import org.apache.solr.cluster.placement.AttributeValues;
 import org.apache.solr.cluster.Node;
+import org.apache.solr.cluster.placement.CollectionMetrics;
 
 import java.util.Map;
 import java.util.Optional;
@@ -107,7 +108,13 @@ public class AttributeValuesImpl implements AttributeValues {
   }
 
   @Override
-  public Optional<Double> getMetric(String scope, String metricName) {
+  public Optional<Object> getNodeMetric(Node node, String metricKey) {
+    // TODO implement
+    return Optional.empty();
+  }
+
+  @Override
+  public Optional<CollectionMetrics> getCollectionMetrics(String collectionName) {
     // TODO implement
     return Optional.empty();
   }
diff --git a/solr/core/src/test/org/apache/solr/cluster/placement/AttributeFetcherForTest.java b/solr/core/src/test/org/apache/solr/cluster/placement/AttributeFetcherForTest.java
index b1cc2a0..bb59317 100644
--- a/solr/core/src/test/org/apache/solr/cluster/placement/AttributeFetcherForTest.java
+++ b/solr/core/src/test/org/apache/solr/cluster/placement/AttributeFetcherForTest.java
@@ -18,6 +18,7 @@
 package org.apache.solr.cluster.placement;
 
 import org.apache.solr.cluster.Node;
+import org.apache.solr.cluster.SolrCollection;
 import org.apache.solr.cluster.placement.AttributeFetcher;
 import org.apache.solr.cluster.placement.AttributeValues;
 
@@ -73,7 +74,12 @@ public class AttributeFetcherForTest implements AttributeFetcher {
 
   @Override
   public AttributeFetcher requestNodeMetric(String metricName, NodeMetricRegistry registry) {
-    return this;
+    throw new UnsupportedOperationException("Not yet implemented...");
+  }
+
+  @Override
+  public AttributeFetcher requestCollectionMetrics(SolrCollection solrCollection, Set<String> metricNames) {
+    throw new UnsupportedOperationException("Not yet implemented...");
   }
 
   @Override
@@ -82,7 +88,7 @@ public class AttributeFetcherForTest implements AttributeFetcher {
   }
 
   @Override
-  public AttributeFetcher requestMetric(String scope, String metricName) {
+  public AttributeFetcher requestNodeMetric(String metricKey) {
     throw new UnsupportedOperationException("Not yet implemented...");
   }