Copilot commented on code in PR #3576:
URL: https://github.com/apache/solr/pull/3576#discussion_r3853005870


##########
solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrScraper.java:
##########
@@ -156,61 +162,64 @@ protected MetricSamples request(SolrClient client, 
MetricsQuery query) throws IO
 
     for (JsonQuery jsonQuery : query.getJsonQueries()) {
       try {
-        List<JsonNode> results = jsonQuery.apply(jsonNode);
-        for (JsonNode result : results) {
-          String type = result.get("type").textValue();
-          String name = result.get("name").textValue();
-          String help = result.get("help").textValue();
-          double value = result.get("value").doubleValue();
-
-          List<String> labelNames = new ArrayList<>();
-          List<String> labelValues = new ArrayList<>();
-
-          /* Labels in response */
-          for (JsonNode item : result.get("label_names")) {
-            labelNames.add(item.textValue());
-          }
-
-          for (JsonNode item : result.get("label_values")) {
-            labelValues.add(item.textValue());
-          }
-
-          /* Labels due to client */
-          if (!baseUrlLabelValue.isEmpty()) {
-            labelNames.add(BASE_URL_LABEL);
-            labelValues.add(baseUrlLabelValue);
-          } else if (!zkHostLabelValue.isEmpty()) {
-            labelNames.add(ZK_HOST_LABEL);
-            labelValues.add(zkHostLabelValue);
-          }
-
-          // Add the unique cluster ID, either as specified on cmdline 
--cluster-id or
-          // baseUrl/zkHost
-          labelNames.add(CLUSTER_ID_LABEL);
-          labelValues.add(clusterId);
-
-          // Deduce core if not there
-          if (labelNames.indexOf("core") < 0
-              && labelNames.indexOf("collection") >= 0
-              && labelNames.indexOf("shard") >= 0
-              && labelNames.indexOf("replica") >= 0) {
-            labelNames.add("core");
-
-            String collection = 
labelValues.get(labelNames.indexOf("collection"));
-            String shard = labelValues.get(labelNames.indexOf("shard"));
-            String replica = labelValues.get(labelNames.indexOf("replica"));
-
-            labelValues.add(collection + "_" + shard + "_" + replica);
-          }
-
-          samples.addSamplesIfNotPresent(
-              name,
-              new Collector.MetricFamilySamples(
-                  name, Collector.Type.valueOf(type), help, new 
ArrayList<>()));
-
-          samples.addSampleIfMetricExists(
-              name, new Collector.MetricFamilySamples.Sample(name, labelNames, 
labelValues, value));
-        }
+        jsonQuery.apply(
+            JqSupport.ROOT_SCOPE,
+            jsonNode,
+            result -> {

Review Comment:
   This streams each jq result directly into `samples`, so a query that emits 
one or more results and then throws `JsonQueryException` now leaves those 
partial metrics in the returned scrape. The previous list-returning API only 
processed results after evaluation completed successfully. Please first collect 
the callback outputs into a temporary list, then add them to `samples` after 
`apply` returns, preserving the prior all-or-nothing behavior for each query.



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