difin commented on code in PR #6507:
URL: https://github.com/apache/hive/pull/6507#discussion_r3430319832


##########
packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/autoscaling/PrometheusTextParser.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.hive.kubernetes.operator.autoscaling;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Parses Prometheus text exposition format (from JMX Exporter /metrics).
+ * Only extracts metric name → value pairs; labels are stripped.
+ * For metrics with labels, the full line (name + labels) is used as key.
+ */
+public final class PrometheusTextParser {
+
+  private PrometheusTextParser() {
+  }
+
+  /**
+   * Parse Prometheus text format into metric-name → value map.
+   * Labels are stripped from keys; duplicate metric names (from multiple
+   * label sets) are summed.
+   */
+  public static Map<String, Double> parse(String body) {
+    return doParse(body, false);
+  }
+
+  /**
+   * Parse and return per-label-set metrics (preserving labels in key).
+   * Key format: "metric_name{label=value,...}"
+   */
+  public static Map<String, Double> parseWithLabels(String body) {
+    return doParse(body, true);
+  }
+
+  private static Map<String, Double> doParse(String body, boolean keepLabels) {
+    Map<String, Double> result = new HashMap<>();
+    if (body == null || body.isEmpty()) {

Review Comment:
   `StringUtils.isEmpty(body)` would be a good fit here instead of `body == 
null || body.isEmpty()`



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