gortiz commented on code in PR #14155: URL: https://github.com/apache/pinot/pull/14155#discussion_r1808238160
########## 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: Just to be clear. Due to the limitations of TestNG, what I would expect is to have 1 test class per component (broker, controller, etc) and per metric registry (Yammer, Dropwizard, etc). In order to have so, I would expect PinotPrometheusMetricsTest to be abstract and have two abstract methods: 1. `PinotComponent getComponent()`, as explained in another comment. 2. `PinotMetricsFactory getPinotMetricsFactory()`, that returns the registry to be used. Then for each component we may have another abstract class (like `BrokerPrometheusMetricsTest`) that inherits `PinotPrometheusMetricsTest` and implements `getComponents` and includes all test methods and finally two not-abstract classes `YammerBrokerPrometheusMetricsTest` and `DropwizardBrokerPrometheusMetricsTest` which extends `BrokerPrometheusMetricsTest` and only implements `getPinotMetricsFactory()`. Something like: ```mermaid classDiagram class PinotPrometheusMetricsTest { } class BrokerPrometheusMetricsTest { getComponent } class DropwizardBrokerPrometheusMetricsTest { getPinotMetricsFactory } class YammerBrokerPrometheusMetricsTest { getPinotMetricsFactory } class ServerPrometheusMetricsTest { getComponent } class DropwizardServerPrometheusMetricsTest { getPinotMetricsFactory } class YammerServerPrometheusMetricsTest { getPinotMetricsFactory } PinotPrometheusMetricsTest <|-- BrokerPrometheusMetricsTest BrokerPrometheusMetricsTest <|-- DropwizardBrokerPrometheusMetricsTest BrokerPrometheusMetricsTest <|-- YammerBrokerPrometheusMetricsTest PinotPrometheusMetricsTest <|-- ServerPrometheusMetricsTest ServerPrometheusMetricsTest <|-- DropwizardServerPrometheusMetricsTest ServerPrometheusMetricsTest <|-- YammerServerPrometheusMetricsTest ``` -- 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