dsmiley commented on code in PR #3713:
URL: https://github.com/apache/solr/pull/3713#discussion_r2399857070
##########
solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/NodeValueFetcher.java:
##########
@@ -65,7 +65,13 @@ public Object extractResult(NamedList<Object> root) {
try (InputStream in = (InputStream) metrics) {
return prometheusMetricStream(in)
- .filter(line -> line.startsWith(metricName))
+ .filter(line ->
extractMetricNameFromLine(line).equals(metricName))
+ .filter(
+ line -> {
+ return line.contains("type=\"permanent\"")
+ || line.contains("type=\"transient\"")
+ || line.contains("type=\"unloaded\"");
+ })
Review Comment:
Oh I'm sorry; I now see the context of this better. It's expressly for
solr_cores_loaded. We don't care what the type is; the filter on the type
should be removed.
##########
solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java:
##########
@@ -173,35 +173,34 @@ public Map<String, Map<String, List<Replica>>>
getReplicaInfo(
}
RemoteCallCtx ctx = new RemoteCallCtx(node, solrClient);
- try (java.util.stream.Stream<String> metrics =
- fetchMetricStream(node, ctx, requestedMetricNames)) {
- metrics.forEach(
- line -> {
- String prometheusMetricName =
NodeValueFetcher.extractMetricNameFromLine(line);
-
- // Extract core name from prometheus line and the core label
- String coreParam =
NodeValueFetcher.extractLabelValueFromLine(line, "core");
- if (coreParam == null) return;
-
- // Find the matching core and set the metric value to its
corresponding replica
- // properties
- List<Pair<Replica, String>> replicaProps =
coreToReplicaProps.get(coreParam);
- if (replicaProps != null) {
- Double value =
NodeValueFetcher.Metrics.extractPrometheusValue(line);
- replicaProps.stream()
- .filter(pair -> pair.second().equals(prometheusMetricName))
- .forEach(pair ->
pair.first().getProperties().put(pair.second(), value));
- }
- });
- }
-
+ processMetricStream(
+ node,
+ ctx,
+ requestedMetricNames,
+ (line) -> {
+ String prometheusMetricName =
NodeValueFetcher.extractMetricNameFromLine(line);
+
+ // Extract core name from prometheus line and the core label
+ String coreParam = NodeValueFetcher.extractLabelValueFromLine(line,
"core");
+ if (coreParam == null) return;
+
+ // Find the matching core and set the metric value to its
corresponding replica
+ // properties
+ List<Pair<Replica, String>> replicaProps =
coreToReplicaProps.get(coreParam);
+ if (replicaProps != null) {
+ Double value =
NodeValueFetcher.Metrics.extractPrometheusValue(line);
+ replicaProps.stream()
+ .filter(pair -> pair.second().equals(prometheusMetricName))
+ .forEach(pair ->
pair.first().getProperties().put(pair.second(), value));
+ }
+ });
return result;
}
- /** Returns a stream of prometheus metrics lines for processing. */
- static java.util.stream.Stream<String> fetchMetricStream(
- String solrNode, RemoteCallCtx ctx, Set<String> metricNames) {
- if (!ctx.isNodeAlive(solrNode)) return java.util.stream.Stream.empty();
+ /** Process a stream of prometheus metrics lines */
+ static void processMetricStream(
+ String solrNode, RemoteCallCtx ctx, Set<String> metricNames,
Consumer<String> processor) {
Review Comment:
a little ambiguous, but if you rename processor to lineProcessor, we know
the processor processes a line
##########
solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/NodeValueFetcher.java:
##########
@@ -98,7 +104,8 @@ public Object extractResult(NamedList<Object> root) {
/**
* Extract metric value from Prometheus response, optionally filtering by
label. This
- * consolidated method handles both labeled and unlabeled metrics.
+ * consolidated method handles both labeled and unlabeled metrics. This
method assumes 1 metirc,
Review Comment:
```suggestion
* consolidated method handles both labeled and unlabeled metrics. This
method assumes 1 metric,
```
--
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]