devmadhuu commented on code in PR #12079:
URL: https://github.com/apache/ozone/pull/12079#discussion_r4708918361


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/SCMPipelineMetrics.java:
##########
@@ -44,6 +50,12 @@ public final class SCMPipelineMetrics implements 
MetricsSource {
 
   private static final String SOURCE_NAME =
       SCMPipelineMetrics.class.getSimpleName();
+  private static final String UNKNOWN_TIER = "UNKNOWN";
+  private static final MetricsInfo REQUESTED_TIER = 
Interns.info("RequestedTier", "Requested allocation tier");
+  private static final MetricsInfo REASON = Interns.info("Reason", "Tier 
allocation failure category");
+  private static final MetricsInfo TIER_PLACEMENT_FAILURES = 
Interns.info("TierPlacementFailures",
+      "Failed RATIS/standalone tier allocations after retries; no_space 
includes storage-type eligibility failures; "

Review Comment:
   Changed to 'storage-type capacity shortages' in the metric help text and the 
javadoc.



##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestSCMTierPlacementMetrics.java:
##########
@@ -0,0 +1,212 @@
+/*
+ * 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.hdds.scm.pipeline;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+import org.apache.hadoop.hdds.client.StorageTier;
+import org.apache.hadoop.hdds.scm.exceptions.SCMException;
+import org.apache.hadoop.hdds.scm.exceptions.SCMException.ResultCodes;
+import org.apache.hadoop.hdds.server.http.PrometheusMetricsSink;
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricType;
+import org.apache.hadoop.metrics2.impl.MetricsCollectorImpl;
+import org.apache.hadoop.metrics2.impl.MetricsRecordImpl;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Verifies the published tier-allocation counters alongside existing pipeline 
metrics.
+ */
+class TestSCMTierPlacementMetrics {
+  private SCMPipelineMetrics metrics;
+
+  @BeforeEach
+  void setUp() {
+    SCMPipelineMetrics.unRegister();
+    metrics = SCMPipelineMetrics.create();
+  }
+
+  @AfterEach
+  void tearDown() {
+    SCMPipelineMetrics.unRegister();
+  }
+
+  @ParameterizedTest
+  @MethodSource("failureReasons")
+  void classifiesResultCodesWithoutParsingMessages(IOException failure, String 
reason) throws Exception {
+    metrics.incTierPlacementFailure(StorageTier.SSD, failure);
+    String output = prometheusOutput();
+    assertThat(output).contains(series("SSD", reason, 1));
+    assertEquals(1, totalFailures());
+  }
+
+  static Stream<Arguments> failureReasons() {
+    return Stream.of(
+        Arguments.of(new 
SCMException(ResultCodes.FAILED_TO_FIND_NODES_WITH_SPACE), "no_space"),
+        Arguments.of(new 
SCMException(ResultCodes.FAILED_TO_FIND_CONTAINER_WITH_SPACE), "no_space"),

Review Comment:
   Done. The enum is now package-private and the test uses its labels. I kept 
one test that pins the three label strings, since they are the published 
Prometheus values.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to