mlbiscoc commented on code in PR #3444: URL: https://github.com/apache/solr/pull/3444#discussion_r2240827728
########## solr/solrj/src/test/org/apache/solr/client/solrj/SolrJMetricTestUtils.java: ########## @@ -0,0 +1,128 @@ +/* + * 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.client.solrj; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.Http2SolrClient; +import org.apache.solr.client.solrj.impl.InputStreamResponseParser; +import org.apache.solr.client.solrj.request.GenericSolrRequest; +import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.common.util.NamedList; + +public final class SolrJMetricTestUtils { + + public static double getPrometheusMetricValue(CloudSolrClient solrClient, String metricName) + throws SolrServerException, IOException { + var req = + new GenericSolrRequest( + SolrRequest.METHOD.GET, + "/admin/metrics", + SolrRequest.SolrRequestType.ADMIN, + new ModifiableSolrParams().set("wt", "prometheus")); + req.setResponseParser(new InputStreamResponseParser("prometheus")); + + NamedList<Object> resp = solrClient.request(req); + try (InputStream in = (InputStream) resp.get("stream")) { + String output = new String(in.readAllBytes(), StandardCharsets.UTF_8); + var line = + output + .lines() + .filter(l -> l.startsWith(metricName)) + .findFirst() + .orElseThrow(() -> new AssertionError("Metric not found: " + metricName)); + + return Double.parseDouble(line.substring(line.lastIndexOf(" ") + 1).trim()); + } + } + + public static Double getNumCoreRequests( Review Comment: According to Prometheus data model, the format value is always `float64` so parsed it as `double`. Under the hood though for OTEL though they are `LongCounters`. I can change it to `long` but was following the data model since we are parsing the `/admin/metrics` endpoint. -- 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-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org