You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/08/16 13:57:00 UTC

[GitHub] [ozone] Galsza commented on a diff in pull request #3682: HDDS-7120. Fix Prometheus reporting only 1 VolumeIOStat

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


##########
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:
   There is a bug with @Metric annotations for fields, which works properly for methods. Turns out that @Metric on fields ignores type. This needs to be fixed on hadoop-common side and we either use all annotations on methods or this hybrid way stays.
   
   Fixed the missing empty line and removed the unnecessary description.



##########
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:
   Thanks, fixed it



-- 
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-unsubscribe@ozone.apache.org

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


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