You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2022/07/25 22:59:33 UTC

[GitHub] [solr] madrob commented on a diff in pull request #948: SOLR-15007: Adding ability to provide aggregated node level metrics for request handlers

madrob commented on code in PR #948:
URL: https://github.com/apache/solr/pull/948#discussion_r929375135


##########
solr/core/src/test/org/apache/solr/metrics/DelegateRegistryTimerTest.java:
##########
@@ -0,0 +1,218 @@
+/*
+ * 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.metrics;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import com.codahale.metrics.Clock;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+import java.time.Duration;
+import java.util.concurrent.TimeUnit;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DelegateRegistryTimerTest {
+
+  MetricRegistry.MetricSupplier<Timer> timerSupplier =
+      new MetricSuppliers.DefaultTimerSupplier(null);
+
+  @Test
+  public void update() {
+    DelegateRegistryTimer delegateRegistryTimer =
+        new DelegateRegistryTimer(
+            Clock.defaultClock(), timerSupplier.newMetric(), timerSupplier.newMetric());
+    delegateRegistryTimer.update(Duration.ofSeconds(10));
+    assertEquals(1, delegateRegistryTimer.getPrimaryTimer().getCount());
+    assertEquals(
+        10000000000.0, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMean(), 0.0);
+    assertEquals(
+        10000000000.0, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMedian(), 0.0);
+    assertEquals(10000000000L, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMax());
+    assertEquals(10000000000.0, delegateRegistryTimer.getSnapshot().getMean(), 0.0);
+    assertEquals(10000000000.0, delegateRegistryTimer.getSnapshot().getMedian(), 0.0);
+    assertEquals(10000000000L, delegateRegistryTimer.getSnapshot().getMax());
+    assertEquals(1, delegateRegistryTimer.getDelegateTimer().getCount());
+    assertEquals(
+        10000000000.0, delegateRegistryTimer.getDelegateTimer().getSnapshot().getMean(), 0.0);
+    assertEquals(
+        10000000000.0, delegateRegistryTimer.getDelegateTimer().getSnapshot().getMedian(), 0.0);
+    assertEquals(10000000000L, delegateRegistryTimer.getDelegateTimer().getSnapshot().getMax());
+
+    delegateRegistryTimer.update(Duration.ofSeconds(20));
+    delegateRegistryTimer.update(Duration.ofSeconds(30));
+    assertEquals(3, delegateRegistryTimer.getPrimaryTimer().getCount());
+    assertEquals(
+        20000000000.0, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMean(), 0.0);
+    assertEquals(
+        20000000000.0, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMedian(), 0.0);
+    assertEquals(30000000000L, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMax());
+    assertEquals(20000000000.0, delegateRegistryTimer.getSnapshot().getMean(), 0.0);
+    assertEquals(20000000000.0, delegateRegistryTimer.getSnapshot().getMedian(), 0.0);
+    assertEquals(30000000000L, delegateRegistryTimer.getSnapshot().getMax());
+    assertEquals(3, delegateRegistryTimer.getDelegateTimer().getCount());
+    assertEquals(
+        20000000000.0, delegateRegistryTimer.getDelegateTimer().getSnapshot().getMean(), 0.0);
+    assertEquals(
+        20000000000.0, delegateRegistryTimer.getDelegateTimer().getSnapshot().getMedian(), 0.0);
+    assertEquals(30000000000L, delegateRegistryTimer.getDelegateTimer().getSnapshot().getMax());
+  }
+
+  @Test
+  public void testUpdate() {
+    DelegateRegistryTimer delegateRegistryTimer =
+        new DelegateRegistryTimer(
+            Clock.defaultClock(), timerSupplier.newMetric(), timerSupplier.newMetric());
+    delegateRegistryTimer.update(10, TimeUnit.SECONDS);
+    assertEquals(1, delegateRegistryTimer.getPrimaryTimer().getCount());
+    assertEquals(
+        10000000000.0, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMean(), 0.0);
+    assertEquals(
+        10000000000.0, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMedian(), 0.0);
+    assertEquals(10000000000L, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMax());
+    assertEquals(10000000000.0, delegateRegistryTimer.getSnapshot().getMean(), 0.0);
+    assertEquals(10000000000.0, delegateRegistryTimer.getSnapshot().getMedian(), 0.0);
+    assertEquals(10000000000L, delegateRegistryTimer.getSnapshot().getMax());
+    assertEquals(1, delegateRegistryTimer.getDelegateTimer().getCount());
+    assertEquals(
+        10000000000.0, delegateRegistryTimer.getDelegateTimer().getSnapshot().getMean(), 0.0);
+    assertEquals(
+        10000000000.0, delegateRegistryTimer.getDelegateTimer().getSnapshot().getMedian(), 0.0);
+    assertEquals(10000000000L, delegateRegistryTimer.getDelegateTimer().getSnapshot().getMax());
+
+    delegateRegistryTimer.update(20, TimeUnit.SECONDS);
+    delegateRegistryTimer.update(30, TimeUnit.SECONDS);
+    assertEquals(3, delegateRegistryTimer.getPrimaryTimer().getCount());
+    assertEquals(
+        20000000000.0, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMean(), 0.0);
+    assertEquals(
+        20000000000.0, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMedian(), 0.0);
+    assertEquals(30000000000L, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMax());
+    assertEquals(20000000000.0, delegateRegistryTimer.getSnapshot().getMean(), 0.0);
+    assertEquals(20000000000.0, delegateRegistryTimer.getSnapshot().getMedian(), 0.0);
+    assertEquals(30000000000L, delegateRegistryTimer.getSnapshot().getMax());
+    assertEquals(3, delegateRegistryTimer.getDelegateTimer().getCount());
+    assertEquals(
+        20000000000.0, delegateRegistryTimer.getDelegateTimer().getSnapshot().getMean(), 0.0);
+    assertEquals(
+        20000000000.0, delegateRegistryTimer.getDelegateTimer().getSnapshot().getMedian(), 0.0);
+    assertEquals(30000000000L, delegateRegistryTimer.getDelegateTimer().getSnapshot().getMax());
+  }
+
+  @Test
+  public void timeContext() throws InterruptedException {
+    DelegateRegistryTimer delegateRegistryTimer =
+        new DelegateRegistryTimer(
+            Clock.defaultClock(), timerSupplier.newMetric(), timerSupplier.newMetric());
+    Timer.Context time = delegateRegistryTimer.time();
+    Thread.sleep(100);
+    time.close();
+    assertTrue(delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMean() > 100000);
+    assertTrue(delegateRegistryTimer.getDelegateTimer().getSnapshot().getMean() > 100000);
+    assertEquals(
+        delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMean(),
+        delegateRegistryTimer.getDelegateTimer().getSnapshot().getMean(),
+        0.0);
+    assertEquals(
+        delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMean(),
+        delegateRegistryTimer.getSnapshot().getMean(),
+        0.0);
+  }
+
+  @Test
+  public void timeSupplier() {
+    DelegateRegistryTimer delegateRegistryTimer =
+        new DelegateRegistryTimer(
+            Clock.defaultClock(), timerSupplier.newMetric(), timerSupplier.newMetric());
+    Long supplierResult =
+        delegateRegistryTimer.timeSupplier(
+            () -> {
+              try {
+                Thread.sleep(100);
+              } catch (InterruptedException e) {
+                Assert.fail("Thread was interrupted while sleeping");

Review Comment:
   Would need to double check that this will actually fail the test instead of getting caught in some other exception handler if it goes to a different thread.



##########
solr/core/src/test/org/apache/solr/handler/RequestHandlerMetricsTest.java:
##########
@@ -0,0 +1,196 @@
+/*
+ * 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.handler;
+
+import org.apache.solr.client.solrj.*;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.response.SolrResponseBase;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class RequestHandlerMetricsTest extends SolrCloudTestCase {
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    System.setProperty("metricsEnabled", "true");
+    configureCluster(1)
+        .addConfig(
+            "conf1",
+            TEST_PATH()
+                .resolve("configsets")
+                .resolve("cloud-aggregate-node-metrics")
+                .resolve("conf"))

Review Comment:
   ```suggestion
               configset("cloud-aggregate-node-metrics")
   ```



##########
solr/core/src/java/org/apache/solr/metrics/DelegateRegistryCounter.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.metrics;
+
+import com.codahale.metrics.Counter;
+
+public class DelegateRegistryCounter extends Counter {
+
+  private final Counter primaryCounter;

Review Comment:
   I agree with @dsmiley - don't we have SolrDelegateRegistryMetricsContext for exactly the case of determining whether we need to create a regular Counter or a Delegating one?



##########
solr/core/src/test/org/apache/solr/metrics/DelegateRegistryTimerTest.java:
##########
@@ -0,0 +1,218 @@
+/*
+ * 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.metrics;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import com.codahale.metrics.Clock;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+import java.time.Duration;
+import java.util.concurrent.TimeUnit;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DelegateRegistryTimerTest {
+
+  MetricRegistry.MetricSupplier<Timer> timerSupplier =
+      new MetricSuppliers.DefaultTimerSupplier(null);
+
+  @Test
+  public void update() {
+    DelegateRegistryTimer delegateRegistryTimer =
+        new DelegateRegistryTimer(
+            Clock.defaultClock(), timerSupplier.newMetric(), timerSupplier.newMetric());
+    delegateRegistryTimer.update(Duration.ofSeconds(10));
+    assertEquals(1, delegateRegistryTimer.getPrimaryTimer().getCount());
+    assertEquals(
+        10000000000.0, delegateRegistryTimer.getPrimaryTimer().getSnapshot().getMean(), 0.0);

Review Comment:
   These are a bit hard to read, can we pull them into some constants?



##########
solr/core/src/test/org/apache/solr/handler/RequestHandlerMetricsTest.java:
##########
@@ -0,0 +1,196 @@
+/*
+ * 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.handler;
+
+import org.apache.solr.client.solrj.*;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.response.SolrResponseBase;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class RequestHandlerMetricsTest extends SolrCloudTestCase {
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    System.setProperty("metricsEnabled", "true");
+    configureCluster(1)
+        .addConfig(
+            "conf1",
+            TEST_PATH()
+                .resolve("configsets")
+                .resolve("cloud-aggregate-node-metrics")
+                .resolve("conf"))
+        .configure();
+  }
+
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+    cluster.deleteAllCollections();
+  }
+
+  @AfterClass
+  public static void afterClass() {
+    System.clearProperty("metricsEnabled");
+  }
+
+  @Test
+  @SuppressWarnings({"unchecked"})
+  public void testAggregateNodeLevelMetrics() throws SolrServerException, IOException {
+    String collection1 = "testRequestHandlerMetrics1";
+    String collection2 = "testRequestHandlerMetrics2";
+
+    CloudSolrClient cloudClient = cluster.getSolrClient();
+
+    CollectionAdminRequest.Create create =
+        CollectionAdminRequest.createCollection(collection1, "conf1", 1, 1);
+    cloudClient.request(create);
+    cluster.waitForActiveCollection(collection1, 1, 1);
+
+    create = CollectionAdminRequest.createCollection(collection2, "conf1", 1, 1);
+    cloudClient.request(create);
+    cluster.waitForActiveCollection(collection2, 1, 1);
+
+    SolrInputDocument solrInputDocument =
+        new SolrInputDocument("id", "10", "title", "test", "val_s1", "aaa");
+    cloudClient.add(collection1, solrInputDocument);
+    cloudClient.add(collection2, solrInputDocument);
+
+    SolrQuery solrQuery = new SolrQuery("*:*");
+    cloudClient.query(collection1, solrQuery);
+    cloudClient.query(collection2, solrQuery);
+
+    NamedList<Object> response =
+        cloudClient.request(
+            new SolrRequest<>(SolrRequest.METHOD.GET, "/admin/metrics") {
+              @Override
+              public String getRequestType() {
+                return "metricsRequest";
+              }
+
+              @Override
+              public SolrParams getParams() {
+                return null;
+              }
+
+              @Override
+              protected SolrResponse createResponse(SolrClient client) {
+                return new SolrResponseBase();
+              }
+            });
+
+    NamedList<Object> metrics = (NamedList<Object>) response.get("metrics");
+
+    final double[] minQueryTime = {Double.MAX_VALUE};
+    final double[] maxQueryTime = {-1.0};
+    final double[] minUpdateTime = {Double.MAX_VALUE};
+    final double[] maxUpdateTime = {-1.0};

Review Comment:
   Why are these arrays? I am probably missing something fairly straightforward 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.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org