fapifta commented on code in PR #3682:
URL: https://github.com/apache/ozone/pull/3682#discussion_r946193284


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/VolumeIOStats.java:
##########
@@ -156,6 +157,8 @@ public long getReadTime() {
   public long getWriteTime() {
     return writeTime.value();
   }
-
-
+  @Metric(value = "Returns the storage directory name for the volume")

Review Comment:
   I think we should conform with the current style of annotation usage, and 
annotate the `private String storageDirectory` field instead of the method 
here, with that I would like to ask you to consider either to skip the 
description, or add a description to other fields as well, would these 
descriptions tell more about the metric that the name does not tell, or does it 
help understand the metrics on the UI? If yes, then let's add description, if 
not, let's skip I think.
   
   Also a small thing, but we should keep the convention of leaving an empty 
line before a new method declaration.



##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestVolumeIOStatsWithPrometheusSink.java:
##########
@@ -0,0 +1,91 @@
+/**
+ * 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.hadoop.ozone.container.common.volume;
+
+import org.apache.hadoop.hdds.server.http.PrometheusMetricsSink;
+import org.apache.hadoop.metrics2.MetricsSystem;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+/**
+ * Test PrometheusMetricSink regarding VolumeIOStats.
+ */
+public class TestVolumeIOStatsWithPrometheusSink {
+  private MetricsSystem metrics;
+  private PrometheusMetricsSink sink;
+
+  @BeforeEach
+  public void init() {
+    metrics = DefaultMetricsSystem.instance();
+    metrics.init("test");
+    sink = new PrometheusMetricsSink();
+    metrics.register("Prometheus", "Prometheus", sink);
+  }
+
+  @AfterEach
+  public void tearDown() {
+    metrics.stop();
+    metrics.shutdown();
+  }
+
+  @Test
+  public void testMultipleVolumeIOMetricsExist() throws IOException {
+    //GIVEN
+    VolumeIOStats volumeIOStats1 = new VolumeIOStats("VolumeIOStat1",
+        "vol1/dir");
+    VolumeIOStats volumeIOStat2 = new VolumeIOStats("VolumeIOStat2",
+        "vol2/dir");
+
+    //WHEN
+    String writtenMetrics = publishMetricsAndGetOutput();
+
+    //THEN
+    Assertions.assertTrue(
+        writtenMetrics.contains("storagedirectory=\"" +
+            volumeIOStats1.getStorageDirectory() + "\""),
+        "The expected metric line is missing from prometheus" +
+            " metrics output"
+    );
+    Assertions.assertTrue(
+        writtenMetrics.contains("storagedirectory=\"" +
+            volumeIOStat2.getStorageDirectory() + "\""),
+        "The expected metric line is missing from prometheus" +
+            " metrics output"
+    );
+  }
+  private String publishMetricsAndGetOutput() throws IOException {

Review Comment:
   nit: missing empty line before method declaration.



-- 
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: issues-unsubscr...@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org
For additional commands, e-mail: issues-h...@ozone.apache.org

Reply via email to