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


##########
pinot-common/src/test/java/org/apache/pinot/common/metrics/PinotPrometheusMetricsTest.java:
##########
@@ -0,0 +1,493 @@
+/**
+ * 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.fasterxml.jackson.databind.JsonNode;
+import com.google.common.base.Objects;
+import com.google.common.io.Resources;
+import io.prometheus.jmx.JmxCollector;
+import io.prometheus.jmx.common.http.HTTPServerFactory;
+import io.prometheus.jmx.shaded.io.prometheus.client.CollectorRegistry;
+import io.prometheus.jmx.shaded.io.prometheus.client.exporter.HTTPServer;
+import io.prometheus.jmx.shaded.io.prometheus.client.hotspot.DefaultExports;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.InetSocketAddress;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+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.plugin.metrics.dropwizard.DropwizardMetricsFactory;
+import org.apache.pinot.plugin.metrics.yammer.YammerMetricsFactory;
+import org.apache.pinot.spi.annotations.metrics.PinotMetricsFactory;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.metrics.PinotMetricUtils;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+
+import static 
org.apache.pinot.common.metrics.PinotPrometheusMetricsTest.ExportedLabelKeys.*;
+import static 
org.apache.pinot.common.metrics.PinotPrometheusMetricsTest.ExportedLabelValues.*;
+import static 
org.apache.pinot.spi.utils.CommonConstants.CONFIG_OF_METRICS_FACTORY_CLASS_NAME;
+
+
+public abstract class PinotPrometheusMetricsTest {
+
+  protected static final String TABLE_NAME_WITH_TYPE =
+      
TableNameBuilder.forType(TableType.REALTIME).tableNameWithType(ExportedLabelValues.TABLENAME);
+  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 PinotMetricsFactory _pinotMetricsFactory;
+
+  protected HttpClient _httpClient;
+
+  //config keys
+  private static final String CONFIG_KEY_JMX_EXPORTER_PARENT_DIR = 
"jmxExporterConfigsParentDir";
+  private static final String CONFIG_KEY_PINOT_METRICS_FACTORY = 
"pinotMetricsFactory";
+  private static final String CONFIG_KEY_CONTROLLER_CONFIG_FILE_NAME = 
"controllerConfigFileName";
+  private static final String CONFIG_KEY_SERVER_CONFIG_FILE_NAME = 
"serverConfigFileName";
+  private static final String CONFIG_KEY_BROKER_CONFIG_FILE_NAME = 
"brokerConfigFileName";
+  private static final String CONFIG_KEY_MINION_CONFIG_FILE_NAME = 
"minionConfigFileName";
+
+  //each meter defined in code is exported with these measurements
+  private static final List<String> METER_TYPES =
+      List.of("Count", "FiveMinuteRate", "MeanRate", "OneMinuteRate", 
"FifteenMinuteRate");
+
+  //each timer defined in code is exported with these measurements
+  private static final List<String> TIMER_TYPES =
+      List.of("Count", "FiveMinuteRate", "Max", "999thPercentile", 
"95thPercentile", "75thPercentile", "98thPercentile",
+          "OneMinuteRate", "50thPercentile", "99thPercentile", 
"FifteenMinuteRate", "Mean", "StdDev", "MeanRate",
+          "Min");
+
+  //each gauge defined in code is exported with these measurements
+  private static final List<String> GAUGE_TYPES = List.of("Value");
+
+  private String _exporterConfigsParentDir;
+
+  private final Map<PinotComponent, String> _pinotComponentToConfigFileMap = 
new HashMap<>();
+
+  @BeforeClass
+  public void setupTest()
+      throws Exception {
+    //read test configuration
+    JsonNode jsonNode = 
JsonUtils.DEFAULT_READER.readTree(loadResourceAsString("metrics/testConfig.json"));
+    _exporterConfigsParentDir = 
jsonNode.get(CONFIG_KEY_JMX_EXPORTER_PARENT_DIR).textValue();
+    _pinotComponentToConfigFileMap.put(PinotComponent.CONTROLLER,
+        jsonNode.get(CONFIG_KEY_CONTROLLER_CONFIG_FILE_NAME).textValue());
+    _pinotComponentToConfigFileMap.put(PinotComponent.SERVER,
+        jsonNode.get(CONFIG_KEY_SERVER_CONFIG_FILE_NAME).textValue());
+    _pinotComponentToConfigFileMap.put(PinotComponent.BROKER,
+        jsonNode.get(CONFIG_KEY_BROKER_CONFIG_FILE_NAME).textValue());
+    _pinotComponentToConfigFileMap.put(PinotComponent.MINION,
+        jsonNode.get(CONFIG_KEY_MINION_CONFIG_FILE_NAME).textValue());
+
+    String pinotMetricsFactory = 
jsonNode.get(CONFIG_KEY_PINOT_METRICS_FACTORY).textValue();
+    switch (pinotMetricsFactory) {
+      case "YammerMetricsFactory":
+        _pinotMetricsFactory = new YammerMetricsFactory();
+        break;
+      case "DropwizardMetricsFactory":
+        _pinotMetricsFactory = new DropwizardMetricsFactory();
+        break;
+      default:
+        throw new IllegalArgumentException("Unknow metrics factory specified 
in test config: " + pinotMetricsFactory
+            + ", supported ones are: YammerMetricsFactory and 
DropwizardMetricsFactory");
+    }

Review Comment:
   Thanks for the detailed comment, have restructured the code as discussed.



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