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


##########
solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginTest.java:
##########
@@ -212,6 +212,8 @@ public void initFromSecurityJSONUrlJwk() throws Exception {
 
     JWTAuthPlugin.JWTAuthenticationResponse resp = 
plugin.authenticate(testHeader);
     assertEquals(JWT_VALIDATION_EXCEPTION, resp.getAuthCode());
+    System.out.println(

Review Comment:
   You can delete this.



##########
solr/core/src/java/org/apache/solr/handler/admin/api/GetMetrics.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.admin.api;
+
+import io.prometheus.metrics.model.snapshots.MetricSnapshot;
+import io.prometheus.metrics.model.snapshots.MetricSnapshots;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.WebApplicationException;
+import jakarta.ws.rs.core.StreamingOutput;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import org.apache.solr.client.api.endpoint.MetricsApi;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.handler.admin.AdminHandlersProxy;
+import org.apache.solr.jersey.PermissionName;
+import org.apache.solr.metrics.SolrMetricManager;
+import org.apache.solr.metrics.otel.FilterablePrometheusMetricReader;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.PrometheusResponseWriter;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.security.PermissionNameProvider;
+import org.apache.solr.util.stats.MetricUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * V2 API implementation to fetch metrics gathered by Solr.
+ *
+ * <p>This API is analogous to the v1 /admin/metrics endpoint.
+ */
+public class GetMetrics extends AdminAPIBase implements MetricsApi {
+
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  private final SolrMetricManager metricManager;
+  private final boolean enabled;
+
+  @Inject
+  public GetMetrics(
+      CoreContainer coreContainer,
+      SolrQueryRequest solrQueryRequest,
+      SolrQueryResponse solrQueryResponse) {
+    super(coreContainer, solrQueryRequest, solrQueryResponse);
+    this.metricManager = coreContainer.getMetricManager();
+    this.enabled = coreContainer.getConfig().getMetricsConfig().isEnabled();
+  }
+
+  @Override
+  @PermissionName(PermissionNameProvider.Name.METRICS_READ_PERM)
+  public StreamingOutput getMetrics(
+      String acceptHeader,
+      String node,
+      String name,
+      String category,
+      String core,
+      String collection,
+      String shard,
+      String replicaType) {
+
+    // Convert request params into SolrParams, to reuse existing code.
+    ModifiableSolrParams params =
+        new ModifiableSolrParams(
+            Map.of(
+                MetricUtils.NODE_PARAM, new String[] {node},
+                MetricUtils.METRIC_NAME_PARAM, new String[] {name},
+                MetricUtils.CATEGORY_PARAM, new String[] {category},
+                MetricUtils.CORE_PARAM, new String[] {core},
+                MetricUtils.COLLECTION_PARAM, new String[] {collection},
+                MetricUtils.SHARD_PARAM, new String[] {shard},
+                MetricUtils.REPLICA_TYPE_PARAM, new String[] {replicaType}));
+
+    solrQueryRequest.setParams(params);
+
+    validateRequest(acceptHeader);
+
+    // TODO: fix AdminHandlersProxy to support V2
+    if (proxyToNodes()) {
+      return null;
+    }
+
+    // Using the same logic, same methods, as in MetricsHandler.handleRequest
+    Set<String> metricNames = MetricUtils.readParamsAsSet(params, 
MetricUtils.METRIC_NAME_PARAM);
+    SortedMap<String, Set<String>> labelFilters = 
MetricUtils.labelFilters(params);
+
+    return doGetMetrics(metricNames, labelFilters);
+  }
+
+  private void validateRequest(String acceptHeader) {
+    if (!enabled) {
+      log.info("Metrics not enabled");

Review Comment:
   These should be log errors/warns. But shouldn't need to log since throwing 
is going to log anyways. Just drop these if you're throwing



-- 
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