This is an automated email from the ASF dual-hosted git repository.

tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new f7b26846a0a Add Metric Prometheus Reporter IT (#11443)
f7b26846a0a is described below

commit f7b26846a0ac6102fe3f8d914415f9326f1d601d
Author: ZhangHongYin <[email protected]>
AuthorDate: Tue Nov 7 18:22:26 2023 +0800

    Add Metric Prometheus Reporter IT (#11443)
---
 .../org/apache/iotdb/it/env/cluster/EnvUtils.java  |  5 +-
 .../it/env/cluster/config/MppConfigNodeConfig.java |  7 +++
 .../it/env/cluster/config/MppDataNodeConfig.java   |  7 +++
 .../iotdb/it/env/cluster/env/AbstractEnv.java      | 53 ++++++++++-------
 .../it/env/cluster/node/AbstractNodeWrapper.java   |  7 +++
 .../it/env/cluster/node/ConfigNodeWrapper.java     |  7 +--
 .../iotdb/it/env/cluster/node/DataNodeWrapper.java |  5 +-
 .../env/remote/config/RemoteConfigNodeConfig.java  |  9 ++-
 .../it/env/remote/config/RemoteDataNodeConfig.java |  9 ++-
 .../iotdb/it/env/remote/env/RemoteServerEnv.java   | 17 ++++++
 .../java/org/apache/iotdb/itbase/env/BaseEnv.java  | 32 ++++++++++
 .../apache/iotdb/itbase/env/BaseNodeWrapper.java   |  2 +
 .../apache/iotdb/itbase/env/ConfigNodeConfig.java  |  6 +-
 .../apache/iotdb/itbase/env/DataNodeConfig.java    |  6 +-
 .../apache/iotdb/db/it/metric/IoTDBMetricIT.java   | 68 ++++++++++++++++++++++
 .../main/java/org/apache/iotdb/jdbc/Config.java    |  2 +
 .../apache/iotdb/commons/conf/IoTDBConstant.java   |  5 ++
 17 files changed, 212 insertions(+), 35 deletions(-)

diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java
index 8036b0faa4a..d23a0917844 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/EnvUtils.java
@@ -60,9 +60,10 @@ import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.USER_DIR;
 public class EnvUtils {
 
   public static int[] searchAvailablePorts() {
+    int length = 10;
     while (true) {
       int randomPortStart = 1000 + (int) (Math.random() * (1999 - 1000));
-      randomPortStart = randomPortStart * 10 + 1;
+      randomPortStart = randomPortStart * (length + 1) + 1;
       String lockFilePath = getLockFilePath(randomPortStart);
       File lockFile = new File(lockFilePath);
       try {
@@ -72,7 +73,7 @@ public class EnvUtils {
           continue;
         }
         List<Integer> requiredPorts =
-            IntStream.rangeClosed(randomPortStart, randomPortStart + 9)
+            IntStream.rangeClosed(randomPortStart, randomPortStart + length)
                 .boxed()
                 .collect(Collectors.toList());
         if (checkPortsAvailable(requiredPorts)) {
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppConfigNodeConfig.java
 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppConfigNodeConfig.java
index e8ee382a799..62ccbb0aa4f 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppConfigNodeConfig.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppConfigNodeConfig.java
@@ -22,6 +22,7 @@ package org.apache.iotdb.it.env.cluster.config;
 import org.apache.iotdb.itbase.env.ConfigNodeConfig;
 
 import java.io.IOException;
+import java.util.List;
 
 public class MppConfigNodeConfig extends MppBaseConfig implements 
ConfigNodeConfig {
 
@@ -48,4 +49,10 @@ public class MppConfigNodeConfig extends MppBaseConfig 
implements ConfigNodeConf
               + persistentConfig.getClass().getCanonicalName());
     }
   }
+
+  @Override
+  public ConfigNodeConfig setMetricReporterType(List<String> 
metricReporterTypes) {
+    properties.setProperty("cn_metric_reporter_list", String.join(",", 
metricReporterTypes));
+    return this;
+  }
 }
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppDataNodeConfig.java
 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppDataNodeConfig.java
index ea65fa2b9cd..75f1821a93c 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppDataNodeConfig.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppDataNodeConfig.java
@@ -22,6 +22,7 @@ package org.apache.iotdb.it.env.cluster.config;
 import org.apache.iotdb.itbase.env.DataNodeConfig;
 
 import java.io.IOException;
+import java.util.List;
 
 public class MppDataNodeConfig extends MppBaseConfig implements DataNodeConfig 
{
 
@@ -48,4 +49,10 @@ public class MppDataNodeConfig extends MppBaseConfig 
implements DataNodeConfig {
               + persistentConfig.getClass().getCanonicalName());
     }
   }
+
+  @Override
+  public DataNodeConfig setMetricReporterType(List<String> 
metricReporterTypes) {
+    properties.setProperty("dn_metric_reporter_list", String.join(",", 
metricReporterTypes));
+    return this;
+  }
 }
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java
 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java
index 88a99162281..b96c8f4d4f9 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java
@@ -34,11 +34,7 @@ import org.apache.iotdb.isession.SessionConfig;
 import org.apache.iotdb.isession.pool.ISessionPool;
 import org.apache.iotdb.it.env.EnvFactory;
 import org.apache.iotdb.it.env.cluster.EnvUtils;
-import org.apache.iotdb.it.env.cluster.config.MppClusterConfig;
-import org.apache.iotdb.it.env.cluster.config.MppCommonConfig;
-import org.apache.iotdb.it.env.cluster.config.MppConfigNodeConfig;
-import org.apache.iotdb.it.env.cluster.config.MppDataNodeConfig;
-import org.apache.iotdb.it.env.cluster.config.MppJVMConfig;
+import org.apache.iotdb.it.env.cluster.config.*;
 import org.apache.iotdb.it.env.cluster.node.AbstractNodeWrapper;
 import org.apache.iotdb.it.env.cluster.node.ConfigNodeWrapper;
 import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
@@ -46,11 +42,7 @@ import org.apache.iotdb.it.framework.IoTDBTestLogger;
 import org.apache.iotdb.itbase.env.BaseEnv;
 import org.apache.iotdb.itbase.env.BaseNodeWrapper;
 import org.apache.iotdb.itbase.env.ClusterConfig;
-import org.apache.iotdb.itbase.runtime.ClusterTestConnection;
-import org.apache.iotdb.itbase.runtime.NodeConnection;
-import org.apache.iotdb.itbase.runtime.ParallelRequestDelegate;
-import org.apache.iotdb.itbase.runtime.RequestDelegate;
-import org.apache.iotdb.itbase.runtime.SerialRequestDelegate;
+import org.apache.iotdb.itbase.runtime.*;
 import org.apache.iotdb.jdbc.Config;
 import org.apache.iotdb.jdbc.Constant;
 import org.apache.iotdb.jdbc.IoTDBConnection;
@@ -67,22 +59,13 @@ import java.io.IOException;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
-import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.NODE_NETWORK_TIMEOUT_MS;
-import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.NODE_START_TIMEOUT;
-import static org.apache.iotdb.it.env.cluster.ClusterConstant.PROBE_TIMEOUT_MS;
-import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.TEMPLATE_NODE_LIB_PATH;
-import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.TEMPLATE_NODE_PATH;
+import static org.apache.iotdb.it.env.cluster.ClusterConstant.*;
 import static org.apache.iotdb.jdbc.Config.VERSION;
 
 public abstract class AbstractEnv implements BaseEnv {
@@ -121,6 +104,34 @@ public abstract class AbstractEnv implements BaseEnv {
     return clusterConfig;
   }
 
+  @Override
+  public List<String> getMetricPrometheusReporterContents() {
+    List<String> result = new ArrayList<>();
+    // get all report content of confignodes
+    for (ConfigNodeWrapper configNode : this.configNodeWrapperList) {
+      String configNodeMetricContent =
+          getUrlContent(
+              Config.IOTDB_HTTP_URL_PREFIX
+                  + configNode.getIp()
+                  + ":"
+                  + configNode.getMetricPort()
+                  + "/metrics");
+      result.add(configNodeMetricContent);
+    }
+    // get all report content of datanodes
+    for (DataNodeWrapper dataNode : this.dataNodeWrapperList) {
+      String dataNodeMetricContent =
+          getUrlContent(
+              Config.IOTDB_HTTP_URL_PREFIX
+                  + dataNode.getIp()
+                  + ":"
+                  + dataNode.getMetricPort()
+                  + "/metrics");
+      result.add(dataNodeMetricContent);
+    }
+    return result;
+  }
+
   protected void initEnvironment(int configNodesNum, int dataNodesNum) {
     initEnvironment(configNodesNum, dataNodesNum, 30);
   }
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/AbstractNodeWrapper.java
 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/AbstractNodeWrapper.java
index 187a819f332..433a180fa4f 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/AbstractNodeWrapper.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/AbstractNodeWrapper.java
@@ -123,6 +123,7 @@ public abstract class AbstractNodeWrapper implements 
BaseNodeWrapper {
   private Process instance;
   private final String nodeAddress;
   private int nodePort;
+  private int metricPort;
   private long startTime;
 
   /**
@@ -161,6 +162,7 @@ public abstract class AbstractNodeWrapper implements 
BaseNodeWrapper {
     this.portList = portList;
     this.nodeAddress = "127.0.0.1";
     this.nodePort = portList[0];
+    this.metricPort = portList[portList.length - 2];
     jmxPort = this.portList[portList.length - 1];
     // these properties can't be mutated.
     immutableCommonProperties.setProperty(UDF_LIB_DIR, 
MppBaseConfig.NULL_VALUE);
@@ -470,6 +472,11 @@ public abstract class AbstractNodeWrapper implements 
BaseNodeWrapper {
     return this.nodePort;
   }
 
+  @Override
+  public final int getMetricPort() {
+    return this.metricPort;
+  }
+
   public void setPort(int port) {
     this.nodePort = port;
   }
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/ConfigNodeWrapper.java
 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/ConfigNodeWrapper.java
index 8aec051dc9b..91a53b04e0e 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/ConfigNodeWrapper.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/ConfigNodeWrapper.java
@@ -32,8 +32,6 @@ import static 
org.apache.iotdb.consensus.ConsensusFactory.SIMPLE_CONSENSUS;
 import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.CN_CONNECTION_TIMEOUT_MS;
 import static org.apache.iotdb.it.env.cluster.ClusterConstant.CN_CONSENSUS_DIR;
 import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.CN_METRIC_IOTDB_REPORTER_HOST;
-import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.CN_METRIC_IOTDB_REPORTER_PORT;
-import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.CN_METRIC_PROMETHEUS_REPORTER_PORT;
 import static org.apache.iotdb.it.env.cluster.ClusterConstant.CN_SYSTEM_DIR;
 import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.COMMON_PROPERTIES_FILE;
 import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.CONFIG_NODE_CONSENSUS_PROTOCOL_CLASS;
@@ -88,10 +86,7 @@ public class ConfigNodeWrapper extends AbstractNodeWrapper {
     immutableNodeProperties.setProperty(IoTDBConstant.CN_SEED_CONFIG_NODE, 
seedConfigNodes);
     immutableNodeProperties.setProperty(CN_SYSTEM_DIR, 
MppBaseConfig.NULL_VALUE);
     immutableNodeProperties.setProperty(CN_CONSENSUS_DIR, 
MppBaseConfig.NULL_VALUE);
-    immutableNodeProperties.setProperty(
-        CN_METRIC_PROMETHEUS_REPORTER_PORT, MppBaseConfig.NULL_VALUE);
     immutableNodeProperties.setProperty(CN_METRIC_IOTDB_REPORTER_HOST, 
MppBaseConfig.NULL_VALUE);
-    immutableNodeProperties.setProperty(CN_METRIC_IOTDB_REPORTER_PORT, 
MppBaseConfig.NULL_VALUE);
   }
 
   @Override
@@ -168,6 +163,8 @@ public class ConfigNodeWrapper extends AbstractNodeWrapper {
     mutableNodeProperties.setProperty(IoTDBConstant.CN_INTERNAL_PORT, 
String.valueOf(getPort()));
     mutableNodeProperties.setProperty(
         IoTDBConstant.CN_CONSENSUS_PORT, String.valueOf(this.consensusPort));
+    mutableNodeProperties.setProperty(
+        IoTDBConstant.CN_METRIC_PROMETHEUS_REPORTER_PORT, 
String.valueOf(super.getMetricPort()));
   }
 
   @Override
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/DataNodeWrapper.java
 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/DataNodeWrapper.java
index e7543813599..20f1cb2eb82 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/DataNodeWrapper.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/DataNodeWrapper.java
@@ -47,7 +47,6 @@ import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.DN_DATA_REGION_CON
 import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.DN_JOIN_CLUSTER_RETRY_INTERVAL_MS;
 import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.DN_METRIC_INTERNAL_REPORTER_TYPE;
 import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.DN_METRIC_IOTDB_REPORTER_HOST;
-import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.DN_METRIC_PROMETHEUS_REPORTER_PORT;
 import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.DN_MPP_DATA_EXCHANGE_PORT;
 import static 
org.apache.iotdb.it.env.cluster.ClusterConstant.DN_SCHEMA_REGION_CONSENSUS_PORT;
 import static org.apache.iotdb.it.env.cluster.ClusterConstant.DN_SYNC_DIR;
@@ -117,8 +116,6 @@ public class DataNodeWrapper extends AbstractNodeWrapper {
     immutableNodeProperties.setProperty(DN_TRACING_DIR, 
MppBaseConfig.NULL_VALUE);
     immutableNodeProperties.setProperty(DN_SYNC_DIR, MppBaseConfig.NULL_VALUE);
     immutableNodeProperties.setProperty(DN_METRIC_IOTDB_REPORTER_HOST, 
MppBaseConfig.NULL_VALUE);
-    immutableNodeProperties.setProperty(
-        DN_METRIC_PROMETHEUS_REPORTER_PORT, MppBaseConfig.NULL_VALUE);
   }
 
   @Override
@@ -195,6 +192,8 @@ public class DataNodeWrapper extends AbstractNodeWrapper {
     mutableNodeProperties.setProperty(IoTDBConstant.DN_RPC_ADDRESS, 
super.getIp());
     mutableNodeProperties.setProperty(IoTDBConstant.DN_RPC_PORT, 
String.valueOf(super.getPort()));
     mutableNodeProperties.setProperty(IoTDBConstant.DN_INTERNAL_ADDRESS, 
this.internalAddress);
+    mutableNodeProperties.setProperty(
+        IoTDBConstant.DN_METRIC_PROMETHEUS_REPORTER_PORT, 
String.valueOf(super.getMetricPort()));
     mutableNodeProperties.setProperty(
         IoTDBConstant.DN_INTERNAL_PORT, String.valueOf(this.internalPort));
     mutableNodeProperties.setProperty(
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/config/RemoteConfigNodeConfig.java
 
b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/config/RemoteConfigNodeConfig.java
index c10eaa9afb6..5c40fd6ef6b 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/config/RemoteConfigNodeConfig.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/config/RemoteConfigNodeConfig.java
@@ -20,4 +20,11 @@ package org.apache.iotdb.it.env.remote.config;
 
 import org.apache.iotdb.itbase.env.ConfigNodeConfig;
 
-public class RemoteConfigNodeConfig implements ConfigNodeConfig {}
+import java.util.List;
+
+public class RemoteConfigNodeConfig implements ConfigNodeConfig {
+  @Override
+  public ConfigNodeConfig setMetricReporterType(List<String> 
metricReporterTypes) {
+    return this;
+  }
+}
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/config/RemoteDataNodeConfig.java
 
b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/config/RemoteDataNodeConfig.java
index dbd640fdff4..6bb6cfbcef4 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/config/RemoteDataNodeConfig.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/config/RemoteDataNodeConfig.java
@@ -20,4 +20,11 @@ package org.apache.iotdb.it.env.remote.config;
 
 import org.apache.iotdb.itbase.env.DataNodeConfig;
 
-public class RemoteDataNodeConfig implements DataNodeConfig {}
+import java.util.List;
+
+public class RemoteDataNodeConfig implements DataNodeConfig {
+  @Override
+  public DataNodeConfig setMetricReporterType(List<String> 
metricReporterTypes) {
+    return this;
+  }
+}
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java
 
b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java
index da0a9e0dcef..15f07a14370 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java
@@ -46,6 +46,7 @@ import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -55,6 +56,10 @@ public class RemoteServerEnv implements BaseEnv {
 
   private final String ip_addr = System.getProperty("RemoteIp", "127.0.0.1");
   private final String port = System.getProperty("RemotePort", "6667");
+  private final String configNodeMetricPort =
+      System.getProperty("RemoteConfigNodeMetricPort", "9091");
+
+  private final String dataNodeMetricPort = 
System.getProperty("RemoteDataNodeMetricPort", "9093");
   private final String user = System.getProperty("RemoteUser", "root");
   private final String password = System.getProperty("RemotePassword", "root");
   private IClientManager<TEndPoint, SyncConfigNodeIServiceClient> 
clientManager;
@@ -97,6 +102,18 @@ public class RemoteServerEnv implements BaseEnv {
     return clusterConfig;
   }
 
+  @Override
+  public List<String> getMetricPrometheusReporterContents() {
+    List<String> result = new ArrayList<>();
+    result.add(
+        getUrlContent(
+            Config.IOTDB_HTTP_URL_PREFIX + ip_addr + ":" + 
configNodeMetricPort + "/metrics"));
+    result.add(
+        getUrlContent(
+            Config.IOTDB_HTTP_URL_PREFIX + ip_addr + ":" + dataNodeMetricPort 
+ "/metrics"));
+    return result;
+  }
+
   @Override
   public Connection getConnection(String username, String password) throws 
SQLException {
     Connection connection = null;
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java 
b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java
index 08a99c936b2..7e3d70e1328 100644
--- a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java
+++ b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java
@@ -29,7 +29,12 @@ import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
 import org.apache.iotdb.jdbc.Constant;
 import org.apache.iotdb.rpc.IoTDBConnectionException;
 
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.List;
@@ -66,6 +71,33 @@ public interface BaseEnv {
   /** Return the {@link ClusterConfig} for developers to set values before 
test. */
   ClusterConfig getConfig();
 
+  default String getUrlContent(String urlStr) {
+    StringBuilder sb = new StringBuilder();
+    try {
+      URL url = new URL(urlStr);
+      HttpURLConnection httpConnection = (HttpURLConnection) 
url.openConnection();
+      if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
+        InputStream in = httpConnection.getInputStream();
+        InputStreamReader isr = new InputStreamReader(in);
+        BufferedReader bufr = new BufferedReader(isr);
+        String str;
+        while ((str = bufr.readLine()) != null) {
+          sb.append(str);
+        }
+        bufr.close();
+      } else {
+        return null;
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      return null;
+    }
+    return sb.toString();
+  }
+
+  /** Return the content of prometheus */
+  List<String> getMetricPrometheusReporterContents();
+
   default Connection getConnection() throws SQLException {
     return getConnection("root", "root");
   }
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseNodeWrapper.java
 
b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseNodeWrapper.java
index 0f560af8e6f..165ed3fd62f 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseNodeWrapper.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseNodeWrapper.java
@@ -35,6 +35,8 @@ public interface BaseNodeWrapper {
 
   int getPort();
 
+  int getMetricPort();
+
   String getId();
 
   String getIpAndPortString();
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/itbase/env/ConfigNodeConfig.java
 
b/integration-test/src/main/java/org/apache/iotdb/itbase/env/ConfigNodeConfig.java
index 658c59bf62a..bf7179ef702 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/itbase/env/ConfigNodeConfig.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/itbase/env/ConfigNodeConfig.java
@@ -19,5 +19,9 @@
 
 package org.apache.iotdb.itbase.env;
 
+import java.util.List;
+
 /** This interface is used to handle properties in 
iotdb-confignode.properties. */
-public interface ConfigNodeConfig {}
+public interface ConfigNodeConfig {
+  ConfigNodeConfig setMetricReporterType(List<String> metricReporterTypes);
+}
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/itbase/env/DataNodeConfig.java
 
b/integration-test/src/main/java/org/apache/iotdb/itbase/env/DataNodeConfig.java
index 80bf0ae5aa3..2778160d4d9 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/itbase/env/DataNodeConfig.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/itbase/env/DataNodeConfig.java
@@ -19,5 +19,9 @@
 
 package org.apache.iotdb.itbase.env;
 
+import java.util.List;
+
 /** This interface is used to handle properties in iotdb-datanode.properties. 
*/
-public interface DataNodeConfig {}
+public interface DataNodeConfig {
+  DataNodeConfig setMetricReporterType(List<String> metricReporterTypes);
+}
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/metric/IoTDBMetricIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/metric/IoTDBMetricIT.java
new file mode 100644
index 00000000000..1f50344a593
--- /dev/null
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/metric/IoTDBMetricIT.java
@@ -0,0 +1,68 @@
+/*
+ * 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.iotdb.db.it.metric;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.util.Collections;
+import java.util.List;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBMetricIT {
+  @BeforeClass
+  public static void setUp() throws Exception {
+    // Start ConfigNode with Prometheus reporter up
+    EnvFactory.getEnv()
+        .getConfig()
+        .getConfigNodeConfig()
+        .setMetricReporterType(Collections.singletonList("PROMETHEUS"));
+    // Start DataNode with Prometheus reporter up
+    EnvFactory.getEnv()
+        .getConfig()
+        .getDataNodeConfig()
+        .setMetricReporterType(Collections.singletonList("PROMETHEUS"));
+    EnvFactory.getEnv().initClusterEnvironment();
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanClusterEnvironment();
+  }
+
+  @Test
+  public void testPrometheusReporter() {
+    List<String> metricContents = 
EnvFactory.getEnv().getMetricPrometheusReporterContents();
+    for (String metricContent : metricContents) {
+      Assert.assertNotNull(metricContent);
+      Assert.assertNotEquals(0, metricContent.length());
+    }
+  }
+}
diff --git a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Config.java 
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Config.java
index 1e98bc56f2e..adb0125dbc9 100644
--- a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Config.java
+++ b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/Config.java
@@ -30,6 +30,8 @@ public class Config {
   /** The required prefix for the connection URL. */
   public static final String IOTDB_URL_PREFIX = "jdbc:iotdb://";
 
+  public static final String IOTDB_HTTP_URL_PREFIX = "http://";;
+
   public static final String IOTDB_ERROR_PREFIX = "Error";
 
   static final String IOTDB_DEFAULT_HOST = "localhost";
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/IoTDBConstant.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/IoTDBConstant.java
index 8d7ea4e6ad0..5f8d0db3d36 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/IoTDBConstant.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/IoTDBConstant.java
@@ -62,6 +62,11 @@ public class IoTDBConstant {
   public static final String CN_INTERNAL_ADDRESS = "cn_internal_address";
   public static final String DN_INTERNAL_ADDRESS = "dn_internal_address";
 
+  public static final String CN_METRIC_PROMETHEUS_REPORTER_PORT =
+      "cn_metric_prometheus_reporter_port";
+  public static final String DN_METRIC_PROMETHEUS_REPORTER_PORT =
+      "dn_metric_prometheus_reporter_port";
+
   public static final String CN_INTERNAL_PORT = "cn_internal_port";
   public static final String DN_INTERNAL_PORT = "dn_internal_port";
   public static final String CN_CONSENSUS_PORT = "cn_consensus_port";

Reply via email to