You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/06/16 02:13:50 UTC

[GitHub] [iotdb] CRZbulabula commented on a diff in pull request #6291: [IOTDB-3433] add metric for cluster.

CRZbulabula commented on code in PR #6291:
URL: https://github.com/apache/iotdb/pull/6291#discussion_r898626874


##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java:
##########
@@ -98,6 +105,42 @@ public PartitionInfo() {
     this.deletedRegionSet = Collections.synchronizedSet(new HashSet<>());
   }
 
+  public void addMetrics() {
+    if (MetricConfigDescriptor.getInstance().getMetricConfig().getEnableMetric()) {
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.PARTITION_TABLE.toString(),

Review Comment:
   Metric.STORAGEGROUP?



##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java:
##########
@@ -98,6 +105,42 @@ public PartitionInfo() {
     this.deletedRegionSet = Collections.synchronizedSet(new HashSet<>());
   }
 
+  public void addMetrics() {
+    if (MetricConfigDescriptor.getInstance().getMetricConfig().getEnableMetric()) {
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.PARTITION_TABLE.toString(),
+              MetricLevel.CORE,
+              storageGroupPartitionTables,
+              Map::size,
+              Tag.NAME.toString(),
+              "number");
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.REGION.toString(),
+              MetricLevel.IMPORTANT,
+              this,
+              o -> o.getTotalRegionCountAndUpdateMetric(TConsensusGroupType.SchemaRegion),
+              Tag.NAME.toString(),
+              "total",
+              Tag.TYPE.toString(),
+              TConsensusGroupType.SchemaRegion.toString());
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.REGION.toString(),

Review Comment:
   Metric.DATAREGION?



##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java:
##########
@@ -484,6 +529,54 @@ public List<Pair<Long, TConsensusGroupId>> getSortedRegionSlotsCounter(
     return storageGroupPartitionTables.get(storageGroup).getSortedRegionSlotsCounter(type);
   }
 
+  /**
+   * Get total region number and update metric
+   *
+   * @param type SchemaRegion or DataRegion
+   * @return the number of SchemaRegion or DataRegion
+   */
+  private int getTotalRegionCountAndUpdateMetric(TConsensusGroupType type) {

Review Comment:
   Split this interface into getTotalRegionCount and UpdateMetric might better, I wanna use getTotalRegionCount later~



##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/StorageGroupPartitionTable.java:
##########
@@ -70,6 +81,57 @@ public StorageGroupPartitionTable() {
 
     this.schemaPartitionTable = new SchemaPartitionTable();
     this.dataPartitionTable = new DataPartitionTable();
+
+    addMetrics();
+  }
+
+  private void addMetrics() {
+    if (MetricConfigDescriptor.getInstance().getMetricConfig().getEnableMetric()) {
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.REGION.toString(),
+              MetricLevel.NORMAL,
+              this,
+              o -> o.getRegionCount(TConsensusGroupType.SchemaRegion),
+              Tag.NAME.toString(),
+              storageGroupName,
+              Tag.TYPE.toString(),
+              TConsensusGroupType.SchemaRegion.toString());
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.REGION.toString(),

Review Comment:
   Metric.DATAREGION?



##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/StorageGroupPartitionTable.java:
##########
@@ -70,6 +81,57 @@ public StorageGroupPartitionTable() {
 
     this.schemaPartitionTable = new SchemaPartitionTable();
     this.dataPartitionTable = new DataPartitionTable();
+
+    addMetrics();
+  }
+
+  private void addMetrics() {
+    if (MetricConfigDescriptor.getInstance().getMetricConfig().getEnableMetric()) {
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.REGION.toString(),
+              MetricLevel.NORMAL,
+              this,
+              o -> o.getRegionCount(TConsensusGroupType.SchemaRegion),
+              Tag.NAME.toString(),
+              storageGroupName,
+              Tag.TYPE.toString(),
+              TConsensusGroupType.SchemaRegion.toString());
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.REGION.toString(),
+              MetricLevel.NORMAL,
+              this,
+              o -> o.getRegionCount(TConsensusGroupType.DataRegion),
+              Tag.NAME.toString(),
+              storageGroupName,
+              Tag.TYPE.toString(),
+              TConsensusGroupType.DataRegion.toString());
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.SLOT.toString(),
+              MetricLevel.NORMAL,
+              schemaPartitionTable,
+              o -> o.getSchemaPartitionMap().size(),
+              Tag.NAME.toString(),
+              storageGroupName,
+              Tag.TYPE.toString(),
+              "schemaSlotNumber");
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.SLOT.toString(),
+              MetricLevel.NORMAL,
+              dataPartitionTable,
+              o -> o.getDataPartitionMap().size(),
+              Tag.NAME.toString(),
+              storageGroupName,
+              Tag.TYPE.toString(),
+              "dataSlotNumber");
+    }

Review Comment:
   The name "SLOT" will be update later, please add a "TODO"



##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java:
##########
@@ -98,6 +105,42 @@ public PartitionInfo() {
     this.deletedRegionSet = Collections.synchronizedSet(new HashSet<>());
   }
 
+  public void addMetrics() {
+    if (MetricConfigDescriptor.getInstance().getMetricConfig().getEnableMetric()) {
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.PARTITION_TABLE.toString(),
+              MetricLevel.CORE,
+              storageGroupPartitionTables,
+              Map::size,
+              Tag.NAME.toString(),
+              "number");
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.REGION.toString(),

Review Comment:
   Metric.SCHEMAREGION?



##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java:
##########
@@ -484,6 +529,54 @@ public List<Pair<Long, TConsensusGroupId>> getSortedRegionSlotsCounter(
     return storageGroupPartitionTables.get(storageGroup).getSortedRegionSlotsCounter(type);
   }
 
+  /**
+   * Get total region number and update metric
+   *
+   * @param type SchemaRegion or DataRegion
+   * @return the number of SchemaRegion or DataRegion
+   */
+  private int getTotalRegionCountAndUpdateMetric(TConsensusGroupType type) {
+    Set<RegionGroup> regionGroups = new HashSet<>();
+    for (Map.Entry<String, StorageGroupPartitionTable> entry :
+        storageGroupPartitionTables.entrySet()) {
+      regionGroups.addAll(entry.getValue().getRegion(type));
+    }
+    int result = regionGroups.size();
+    // statistic
+    Map<TDataNodeLocation, Integer> dataNodeLocationIntegerMap = new HashMap<>();

Review Comment:
   Add java doc to display what this Map stands for



##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/PartitionInfo.java:
##########
@@ -484,6 +529,54 @@ public List<Pair<Long, TConsensusGroupId>> getSortedRegionSlotsCounter(
     return storageGroupPartitionTables.get(storageGroup).getSortedRegionSlotsCounter(type);
   }
 
+  /**
+   * Get total region number and update metric
+   *
+   * @param type SchemaRegion or DataRegion
+   * @return the number of SchemaRegion or DataRegion
+   */
+  private int getTotalRegionCountAndUpdateMetric(TConsensusGroupType type) {
+    Set<RegionGroup> regionGroups = new HashSet<>();
+    for (Map.Entry<String, StorageGroupPartitionTable> entry :
+        storageGroupPartitionTables.entrySet()) {
+      regionGroups.addAll(entry.getValue().getRegion(type));
+    }
+    int result = regionGroups.size();
+    // statistic
+    Map<TDataNodeLocation, Integer> dataNodeLocationIntegerMap = new HashMap<>();
+    for (RegionGroup regionGroup : regionGroups) {
+      TRegionReplicaSet regionReplicaSet = regionGroup.getReplicaSet();
+      List<TDataNodeLocation> dataNodeLocations = regionReplicaSet.getDataNodeLocations();
+      for (TDataNodeLocation dataNodeLocation : dataNodeLocations) {
+        if (!dataNodeLocationIntegerMap.containsKey(dataNodeLocation)) {
+          dataNodeLocationIntegerMap.put(dataNodeLocation, 0);
+        }
+        dataNodeLocationIntegerMap.put(
+            dataNodeLocation, dataNodeLocationIntegerMap.get(dataNodeLocation) + 1);
+      }
+    }
+    for (Map.Entry<TDataNodeLocation, Integer> entry : dataNodeLocationIntegerMap.entrySet()) {
+      TDataNodeLocation dataNodeLocation = entry.getKey();
+      String name =
+          "EndPoint("
+              + dataNodeLocation.getExternalEndPoint().ip
+              + ":"
+              + dataNodeLocation.getExternalEndPoint().port
+              + ")";
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateGauge(
+              Metric.REGION.toString(),
+              MetricLevel.IMPORTANT,
+              Tag.NAME.toString(),
+              name,
+              Tag.TYPE.toString(),
+              type.toString())
+          .set(dataNodeLocationIntegerMap.get(dataNodeLocation));

Review Comment:
   Comments may require another screenshot to show this monitoring indicators



##########
confignode/src/main/java/org/apache/iotdb/confignode/persistence/partition/StorageGroupPartitionTable.java:
##########
@@ -70,6 +81,57 @@ public StorageGroupPartitionTable() {
 
     this.schemaPartitionTable = new SchemaPartitionTable();
     this.dataPartitionTable = new DataPartitionTable();
+
+    addMetrics();
+  }
+
+  private void addMetrics() {
+    if (MetricConfigDescriptor.getInstance().getMetricConfig().getEnableMetric()) {
+      MetricsService.getInstance()
+          .getMetricManager()
+          .getOrCreateAutoGauge(
+              Metric.REGION.toString(),

Review Comment:
   Metric.SCHEMAREGION?



-- 
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: reviews-unsubscribe@iotdb.apache.org

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