janhoy commented on code in PR #3908:
URL: https://github.com/apache/solr/pull/3908#discussion_r2580269555
##########
solr/core/src/java/org/apache/solr/handler/admin/AdminHandlersProxy.java:
##########
@@ -129,9 +134,169 @@ public static CompletableFuture<NamedList<Object>>
callRemoteNode(
URI baseUri =
URI.create(zkController.zkStateReader.getBaseUrlForNodeName(nodeName));
SolrRequest<?> proxyReq = new GenericSolrRequest(SolrRequest.METHOD.GET,
uriPath, params);
+ // Set response parser based on wt parameter to ensure correct format is
used
+ String wt = params.get("wt");
+ if ("prometheus".equals(wt) || "openmetrics".equals(wt)) {
+ proxyReq.setResponseParser(new InputStreamResponseParser(wt));
+ }
+
return zkController
.getCoreContainer()
.getDefaultHttpSolrClient()
.requestWithBaseUrl(baseUri.toString(), c -> c.requestAsync(proxyReq));
}
+
+ /**
+ * Resolve node names from the "nodes" parameter into a set of live node
names.
+ *
+ * @param nodeNames the value of the "nodes" parameter ("all" or
comma-separated node names)
+ * @param container the CoreContainer
+ * @return set of resolved node names
+ * @throws SolrException if node format is invalid or node is not in cluster
+ */
+ private static Set<String> resolveNodes(String nodeNames, CoreContainer
container) {
+ Set<String> liveNodes =
+
container.getZkController().zkStateReader.getClusterState().getLiveNodes();
+
+ if (nodeNames.equals("all")) {
+ log.debug("All live nodes requested");
+ return liveNodes;
+ }
+
+ Set<String> nodes = new HashSet<>(Arrays.asList(nodeNames.split(",")));
+ for (String nodeName : nodes) {
+ if (!nodeName.matches("^[^/:]+:\\d+_[\\w/]+$")) {
+ throw new SolrException(
+ SolrException.ErrorCode.BAD_REQUEST, "Parameter " + PARAM_NODES +
" has wrong format");
+ }
+ if (!liveNodes.contains(nodeName)) {
+ throw new SolrException(
+ SolrException.ErrorCode.BAD_REQUEST,
+ "Requested node " + nodeName + " is not part of cluster");
+ }
+ }
+ log.debug("Nodes requested: {}", nodes);
+ return nodes;
+ }
+
+ /** Handle Prometheus format by fetching from nodes and merging text
responses. */
+ private static void handlePrometheusFormat(
+ Set<String> nodes,
+ String pathStr,
+ SolrParams params,
+ CoreContainer container,
+ SolrQueryResponse rsp)
+ throws IOException, SolrServerException, InterruptedException {
+
+ ZkController zkController = container.getZkController();
+ Map<String, Future<NamedList<Object>>> responses = new LinkedHashMap<>();
+
+ // Ensure wt=prometheus for all requests
+ ModifiableSolrParams prometheusParams = new ModifiableSolrParams(params);
+ if (!prometheusParams.get("wt", "").equals("prometheus")) {
+ prometheusParams.set("wt", "prometheus");
+ }
+
+ // Submit all requests
+ for (String node : nodes) {
+ responses.put(node, callRemoteNode(node, pathStr, prometheusParams,
zkController));
+ }
+
+ // Collect all Prometheus text responses
+ StringBuilder mergedText = new StringBuilder();
+ for (Map.Entry<String, Future<NamedList<Object>>> entry :
responses.entrySet()) {
+ try {
+ NamedList<Object> resp =
+ entry.getValue().get(PROMETHEUS_FETCH_TIMEOUT_SECONDS,
TimeUnit.SECONDS);
+
+ // Extract text from InputStream response
+ Object streamObj = resp.get("stream");
+ if (streamObj instanceof InputStream) {
+ try (InputStream stream = (InputStream) streamObj) {
+ String prometheusText = new String(stream.readAllBytes(),
StandardCharsets.UTF_8);
+ if (!prometheusText.isEmpty()) {
+ // Inject node label into each metric line
+ String labeledText = injectNodeLabelIntoText(prometheusText,
entry.getKey());
+ mergedText.append(labeledText);
Review Comment:
Added a comment line on top of response clarifying it is ONLY for UI
--
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]