suddendust commented on code in PR #14155:
URL: https://github.com/apache/pinot/pull/14155#discussion_r1804151319


##########
pinot-common/src/test/java/org/apache/pinot/common/metrics/PinotJMXToPromMetricsTest.java:
##########
@@ -0,0 +1,266 @@
+/**
+ * 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.pinot.common.metrics;
+
+import com.google.common.base.Objects;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.common.utils.SimpleHttpResponse;
+import org.apache.pinot.common.utils.http.HttpClient;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.utils.StringUtil;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.testng.Assert;
+
+
+public class PinotJMXToPromMetricsTest {
+
+  protected HttpClient _httpClient;
+
+  protected static final String LABEL_KEY_TABLE = "table";
+
+  protected static final List<String> METER_TYPES =
+      List.of("Count", "FiveMinuteRate", "MeanRate", "OneMinuteRate", 
"FifteenMinuteRate");
+
+  protected static final List<String> TIMER_TYPES =
+      List.of("Count", "FiveMinuteRate", "Max", "999thPercentile", 
"95thPercentile", "75thPercentile", "98thPercentile",
+          "OneMinuteRate", "50thPercentile", "99thPercentile", 
"FifteenMinuteRate", "Mean", "StdDev", "MeanRate",
+          "Min");
+
+  protected static final String RAW_TABLE_NAME = "myTable";
+  protected static final String TABLE_NAME_WITH_TYPE =
+      
TableNameBuilder.forType(TableType.REALTIME).tableNameWithType(RAW_TABLE_NAME);
+
+  protected static final String KAFKA_TOPIC = "myTopic";
+  protected static final String PARTITION_GROUP_ID = "partitionGroupId";
+  protected static final String CLIENT_ID =
+      String.format("%s-%s-%s", TABLE_NAME_WITH_TYPE, KAFKA_TOPIC, 
PARTITION_GROUP_ID);
+  protected static final String TABLE_STREAM_NAME = String.format("%s_%s", 
TABLE_NAME_WITH_TYPE, KAFKA_TOPIC);
+
+  protected static final List<String> 
EXPORTED_LABELS_FOR_TABLE_NAME_TABLE_TYPE =
+      List.of("table", "myTable", "tableType", "REALTIME");
+
+  protected static final List<String> EXPORTED_LABELS_FOR_RAW_TABLE_NAME = 
List.of("table", "myTable");
+
+  protected static final List<String> EXPORTED_LABELS_FOR_CLIENT_ID =
+      List.of("partition", PARTITION_GROUP_ID, "table", RAW_TABLE_NAME, 
"tableType", TableType.REALTIME.toString(),
+          "topic", KAFKA_TOPIC);
+
+  protected void assertGaugeExportedCorrectly(String exportedGaugePrefix, 
String exportedMetricPrefix)
+      throws IOException, URISyntaxException {
+    List<PromMetric> promMetrics = 
parseExportedPromMetrics(getExportedPromMetrics().getResponse());
+    Assert.assertTrue(
+        promMetrics.contains(PromMetric.withName(exportedMetricPrefix + 
exportedGaugePrefix + "_" + "Value")),
+        exportedGaugePrefix);
+  }
+
+  protected void assertGaugeExportedCorrectly(String exportedGaugePrefix, 
List<String> labels,
+      String exportedMetricPrefix)
+      throws IOException, URISyntaxException {
+    List<PromMetric> promMetrics =
+        parseExportedPromMetrics(getExportedPromMetrics().getResponse());
+    Assert.assertTrue(promMetrics.contains(PromMetric.withNameAndLabels(
+        exportedMetricPrefix + exportedGaugePrefix + "_" + "Value", labels)));
+  }
+
+  protected void assertTimerExportedCorrectly(String exportedTimerPrefix, 
String exportedMetricPrefix) {
+    List<PromMetric> promMetrics = null;
+    try {
+      promMetrics = 
parseExportedPromMetrics(getExportedPromMetrics().getResponse());
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    } catch (URISyntaxException e) {
+      throw new RuntimeException(e);
+    }
+    for (String meterType : TIMER_TYPES) {
+      Assert.assertTrue(promMetrics.contains(PromMetric.withName(
+          exportedMetricPrefix + exportedTimerPrefix + "_" + meterType)));
+    }
+  }
+
+  protected void assertTimerExportedCorrectly(String exportedTimerPrefix, 
List<String> labels,
+      String exportedMetricPrefix) {
+    List<PromMetric> promMetrics;
+    try {
+      promMetrics = 
parseExportedPromMetrics(getExportedPromMetrics().getResponse());
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    } catch (URISyntaxException e) {
+      throw new RuntimeException(e);
+    }
+    for (String meterType : METER_TYPES) {
+      Assert.assertTrue(promMetrics.contains(PromMetric.withNameAndLabels(
+          exportedMetricPrefix + exportedTimerPrefix + "_" + meterType, 
labels)));
+    }
+  }
+
+  protected void assertMeterExportedCorrectly(String exportedMeterPrefix, 
String exportedMetricPrefix) {
+    List<PromMetric> promMetrics = null;
+    try {
+      promMetrics = 
parseExportedPromMetrics(getExportedPromMetrics().getResponse());
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    } catch (URISyntaxException e) {
+      throw new RuntimeException(e);
+    }
+    for (String meterType : METER_TYPES) {
+      Assert.assertTrue(promMetrics.contains(
+              PromMetric.withName(exportedMetricPrefix + exportedMeterPrefix + 
"_" + meterType)),
+          exportedMeterPrefix);
+    }
+  }
+
+  protected void assertMeterExportedCorrectly(String exportedMeterPrefix, 
List<String> labels,
+      String exportedMetricPrefix) {
+    List<PromMetric> promMetrics = null;
+    try {
+      promMetrics = 
parseExportedPromMetrics(getExportedPromMetrics().getResponse());
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    } catch (URISyntaxException e) {
+      throw new RuntimeException(e);
+    }
+    for (String meterType : METER_TYPES) {
+      Assert.assertTrue(promMetrics.contains(PromMetric.withNameAndLabels(
+          exportedMetricPrefix + exportedMeterPrefix + "_" + meterType, 
labels)), exportedMeterPrefix);
+    }
+  }
+
+  protected List<PromMetric> parseExportedPromMetrics(String response)
+      throws IOException {
+
+    List<PromMetric> exportedPromMetrics = new ArrayList<>();
+
+    BufferedReader reader = new BufferedReader(new StringReader(response));

Review Comment:
   Done



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to