mlbiscoc commented on code in PR #3499:
URL: https://github.com/apache/solr/pull/3499#discussion_r2301680182


##########
solr/core/src/test/org/apache/solr/handler/admin/MetricsHandlerTest.java:
##########
@@ -17,724 +17,242 @@
 
 package org.apache.solr.handler.admin;
 
-import com.codahale.metrics.Counter;
 import io.opentelemetry.api.common.Attributes;
-import io.prometheus.metrics.model.snapshots.CounterSnapshot;
-import io.prometheus.metrics.model.snapshots.GaugeSnapshot;
-import io.prometheus.metrics.model.snapshots.Labels;
-import io.prometheus.metrics.model.snapshots.MetricSnapshot;
 import io.prometheus.metrics.model.snapshots.MetricSnapshots;
-import java.util.Arrays;
-import java.util.HashMap;
 import java.util.Map;
 import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.common.MapWriter;
 import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.SimpleOrderedMap;
-import org.apache.solr.core.PluginBag;
-import org.apache.solr.core.PluginInfo;
 import org.apache.solr.handler.RequestHandlerBase;
 import org.apache.solr.metrics.MetricsMap;
 import org.apache.solr.metrics.SolrMetricsContext;
 import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrRequestHandler;
 import org.apache.solr.response.SolrQueryResponse;
 import org.apache.solr.security.AuthorizationContext;
-import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 /** Test for {@link MetricsHandler} */
 public class MetricsHandlerTest extends SolrTestCaseJ4 {
   @BeforeClass
   public static void beforeClass() throws Exception {
-
     initCore("solrconfig-minimal.xml", "schema.xml");
     h.getCoreContainer().waitForLoadingCoresToFinish(30000);
-
-    // manually register & seed some metrics in solr.jvm and solr.jetty for 
testing via handler
-    // (use "solrtest_" prefix just in case the jvm or jetty adds a "foo" 
metric at some point)
-    Counter c = h.getCoreContainer().getMetricManager().counter(null, 
"solr.jvm", "solrtest_foo");
-    c.inc();
-    c = h.getCoreContainer().getMetricManager().counter(null, "solr.jetty", 
"solrtest_foo");
-    c.inc(2);
-    // test escapes
-    c = h.getCoreContainer().getMetricManager().counter(null, "solr.jetty", 
"solrtest_foo:bar");
-    c.inc(3);
-
-    h.getCoreContainer()
-        .getMetricManager()
-        .meter(null, "solr.jetty", 
"org.eclipse.jetty.server.handler.DefaultHandler.2xx-responses");
-    h.getCoreContainer()
-        .getMetricManager()
-        .counter(
-            null, "solr.jetty", 
"org.eclipse.jetty.server.handler.DefaultHandler.active-requests");
-    h.getCoreContainer()
-        .getMetricManager()
-        .timer(null, "solr.jetty", 
"org.eclipse.jetty.server.handler.DefaultHandler.dispatches");
-  }
-
-  @AfterClass
-  public static void cleanupMetrics() {
-    if (null != h) {
-      
h.getCoreContainer().getMetricManager().registry("solr.jvm").remove("solrtest_foo");
-      
h.getCoreContainer().getMetricManager().registry("solr.jetty").remove("solrtest_foo");
-      
h.getCoreContainer().getMetricManager().registry("solr.jetty").remove("solrtest_foo:bar");
-    }
   }
 
-  // NOCOMMIT: This test does a bunch of /admin/metrics calls with various 
params, with various
-  // filters and parameters. We have not migrated all the metrics to otel yet 
or even created any
-  // filters. Once that is done, we should revisit this test and assert the 
prometheus response.
   @Test
-  @BadApple(bugUrl = "https://issues.apache.org/jira/browse/SOLR-17458";)
-  public void test() throws Exception {

Review Comment:
   Many of these tests that I removed tested all kind of different metrics and 
their values as well as filtering. I felt it was too much. We already test many 
of these metrics in other tests specific to their classes and 
`TestPrometheusResponseWriter` does a kind of higher level testing. So I 
dropped these and just did filter tests.



##########
solr/core/src/java/org/apache/solr/handler/admin/MetricsHandler.java:
##########
@@ -499,9 +584,87 @@ private List<MetricType> parseMetricTypes(SolrParams 
params) {
     return metricTypes;
   }
 
-  private String getCoreNameFromRegistry(String registryName) {
-    String coreName = registryName.substring(registryName.indexOf('.') + 1);
-    return coreName.replace(".", "_");
+  /**
+   * Merge a collection of individual {@link MetricSnapshot} instances into 
one {@link
+   * MetricSnapshots}. This is necessary because we create a {@link
+   * io.opentelemetry.sdk.metrics.SdkMeterProvider} per Solr core resulting in 
duplicate metric
+   * names across cores which is an illegal format if not under the same 
prometheus grouping.
+   */
+  private MetricSnapshots mergeSnapshots(List<MetricSnapshot> snapshots) {

Review Comment:
   Yeah I wrote this a while back. This was originally in 
`PrometheusResponseWriter` and I just moved it into `MetricHandler` which I 
think is a better place for 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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to