Pengzna commented on code in PR #12723:
URL: https://github.com/apache/iotdb/pull/12723#discussion_r1637599335


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/consensus/PipeConsensusReceiverMetric.java:
##########
@@ -0,0 +1,384 @@
+/*
+ * 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.pipe.consensus;
+
+import org.apache.iotdb.commons.service.metric.enums.Metric;
+import org.apache.iotdb.commons.service.metric.enums.Tag;
+import 
org.apache.iotdb.db.pipe.receiver.protocol.pipeconsensus.PipeConsensusReceiver;
+import org.apache.iotdb.metrics.AbstractMetricService;
+import org.apache.iotdb.metrics.impl.DoNothingMetricManager;
+import org.apache.iotdb.metrics.metricsets.IMetricSet;
+import org.apache.iotdb.metrics.type.Timer;
+import org.apache.iotdb.metrics.utils.MetricLevel;
+import org.apache.iotdb.metrics.utils.MetricType;
+
+public class PipeConsensusReceiverMetric implements IMetricSet {
+  private final PipeConsensusReceiver pipeConsensusReceiver;
+
+  private Timer tsFilePieceWriteTimer = 
DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer tsFilePiecePreCheckTimer = 
DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer tsFileSealLoadTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer tsFileSealPreCheckTimer = 
DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer borrowTsFileWriterTimer = 
DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer acquireExecutorLockTimer = 
DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer dispatchWaitingTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer receiveWALTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer receiveTsFileTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer receiveEventTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
+
+  private static final String RECEIVER = "pipeConsensusReceiver";
+
+  public PipeConsensusReceiverMetric(PipeConsensusReceiver 
pipeConsensusReceiver) {
+    this.pipeConsensusReceiver = pipeConsensusReceiver;
+  }
+
+  public void recordTsFilePieceWriteTime(long costTimeInNanos) {
+    tsFilePieceWriteTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordTsFilePiecePreCheckTime(long costTimeInNanos) {
+    tsFilePiecePreCheckTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordTsFileSealLoadTimer(long costTimeInNanos) {
+    tsFileSealLoadTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordTsFileSealPreCheckTimer(long costTimeInNanos) {
+    tsFileSealPreCheckTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordBorrowTsFileWriterTimer(long costTimeInNanos) {
+    borrowTsFileWriterTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordAcquireExecutorLockTimer(long costTimeInNanos) {
+    acquireExecutorLockTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordDispatchWaitingTimer(long costTimeInNanos) {
+    dispatchWaitingTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordReceiveWALTimer(long costTimeInNanos) {
+    receiveWALTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordReceiveTsFileTimer(long costTimeInNanos) {
+    receiveTsFileTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordReceiveEventTimer(long costTimeInNanos) {
+    receiveEventTimer.updateNanos(costTimeInNanos);
+  }
+
+  @Override
+  public void bindTo(AbstractMetricService metricService) {
+    bindAutoGauge(metricService);
+    bindStageTimer(metricService);
+    bindReceiveTimer(metricService);
+  }
+
+  @Override
+  public void unbindFrom(AbstractMetricService metricService) {
+    unbindAutoGauge(metricService);
+    unbindStageTimer(metricService);
+    unbindReceiveTimer(metricService);
+  }
+
+  public void bindAutoGauge(AbstractMetricService metricService) {
+    metricService.createAutoGauge(
+        Metric.PIPE_RECEIVE_EVENT.toString(),
+        MetricLevel.IMPORTANT,
+        pipeConsensusReceiver,
+        PipeConsensusReceiver::getReceiveBufferSize,
+        Tag.NAME.toString(),
+        RECEIVER,
+        Tag.REGION.toString(),
+        pipeConsensusReceiver.getConsensusGroupIdStr(),
+        Tag.TYPE.toString(),
+        "receiveBufferSize");
+    metricService.createAutoGauge(
+        Metric.PIPE_RECEIVE_EVENT.toString(),
+        MetricLevel.IMPORTANT,
+        pipeConsensusReceiver,
+        PipeConsensusReceiver::getWALEventCount,
+        Tag.NAME.toString(),
+        RECEIVER,
+        Tag.REGION.toString(),
+        pipeConsensusReceiver.getConsensusGroupIdStr(),
+        Tag.TYPE.toString(),
+        "walEventCount");
+    metricService.createAutoGauge(
+        Metric.PIPE_RECEIVE_EVENT.toString(),
+        MetricLevel.IMPORTANT,
+        pipeConsensusReceiver,
+        PipeConsensusReceiver::getTsFileEventCount,
+        Tag.NAME.toString(),
+        RECEIVER,
+        Tag.REGION.toString(),
+        pipeConsensusReceiver.getConsensusGroupIdStr(),
+        Tag.TYPE.toString(),
+        "tsFileEventCount");
+  }
+
+  public void bindStageTimer(AbstractMetricService metricService) {
+    tsFilePieceWriteTimer =
+        metricService.getOrCreateTimer(
+            Metric.STAGE.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            RECEIVER,
+            Tag.REGION.toString(),
+            pipeConsensusReceiver.getConsensusGroupIdStr(),
+            Tag.TYPE.toString(),
+            "tsPieceWrite");
+    tsFilePiecePreCheckTimer =
+        metricService.getOrCreateTimer(
+            Metric.STAGE.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            RECEIVER,
+            Tag.REGION.toString(),
+            pipeConsensusReceiver.getConsensusGroupIdStr(),
+            Tag.TYPE.toString(),
+            "tsFilePiecePreCheck");
+    tsFileSealLoadTimer =
+        metricService.getOrCreateTimer(
+            Metric.STAGE.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            RECEIVER,
+            Tag.REGION.toString(),
+            pipeConsensusReceiver.getConsensusGroupIdStr(),
+            Tag.TYPE.toString(),
+            "tsFileSealLoad");
+    tsFileSealPreCheckTimer =
+        metricService.getOrCreateTimer(
+            Metric.STAGE.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            RECEIVER,
+            Tag.REGION.toString(),
+            pipeConsensusReceiver.getConsensusGroupIdStr(),
+            Tag.TYPE.toString(),
+            "tsFileSealPreCheck");
+    borrowTsFileWriterTimer =
+        metricService.getOrCreateTimer(
+            Metric.STAGE.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            RECEIVER,
+            Tag.REGION.toString(),
+            pipeConsensusReceiver.getConsensusGroupIdStr(),
+            Tag.TYPE.toString(),
+            "borrowTsFileWriter");
+    acquireExecutorLockTimer =
+        metricService.getOrCreateTimer(
+            Metric.STAGE.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            RECEIVER,
+            Tag.REGION.toString(),
+            pipeConsensusReceiver.getConsensusGroupIdStr(),
+            Tag.TYPE.toString(),
+            "acquireExecutorLock");
+    dispatchWaitingTimer =
+        metricService.getOrCreateTimer(
+            Metric.STAGE.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            RECEIVER,
+            Tag.REGION.toString(),
+            pipeConsensusReceiver.getConsensusGroupIdStr(),
+            Tag.TYPE.toString(),
+            "dispatchWaiting");
+  }
+
+  public void bindReceiveTimer(AbstractMetricService metricService) {
+    receiveEventTimer =
+        metricService.getOrCreateTimer(
+            Metric.PIPE_RECEIVE_EVENT.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            RECEIVER,
+            Tag.REGION.toString(),
+            pipeConsensusReceiver.getConsensusGroupIdStr(),
+            Tag.TYPE.toString(),
+            "receiveEvent");
+    receiveWALTimer =
+        metricService.getOrCreateTimer(
+            Metric.PIPE_RECEIVE_EVENT.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            RECEIVER,
+            Tag.REGION.toString(),
+            pipeConsensusReceiver.getConsensusGroupIdStr(),
+            Tag.STAGE.toString(),
+            "receiveWALEvent");

Review Comment:
   fixed



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to