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


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/SCMPipelineMetrics.java:
##########
@@ -106,6 +127,62 @@ public void getMetrics(MetricsCollector collector, boolean 
all) {
     pipelineCreationLatencyNs.snapshot(recordBuilder, true);
     numBlocksAllocated
         .forEach((pid, metric) -> metric.snapshot(recordBuilder, true));
+    tierPlacementFailures.forEach((tier, counters) -> 
counters.forEach((reason, counter) ->
+        collector.addRecord(SOURCE_NAME)
+            .tag(REQUESTED_TIER, tier)
+            .tag(REASON, reason.label)
+            .addCounter(TIER_PLACEMENT_FAILURES, counter.value())));
+  }
+
+  private void addTierPlacementCounters(String tier) {
+    Map<PlacementFailureReason, MutableCounterLong> counters = new 
EnumMap<>(PlacementFailureReason.class);
+    for (PlacementFailureReason reason : PlacementFailureReason.values()) {
+      counters.put(reason, new MutableCounterLong(TIER_PLACEMENT_FAILURES, 0));
+    }
+    tierPlacementFailures.put(tier, counters);
+  }
+
+  /**
+   * Counts one unsuccessful RATIS/standalone tier allocation after all 
provider retries. A later allocation on a
+   * fallback tier may still succeed. This does not count background pipeline 
creation or change aggregate counters.
+   * Missing/empty tiers are UNKNOWN. Reasons use SCM result codes, never 
exception messages; no_space includes
+   * insufficient eligible storage of the requested type, not just full 
volumes; no_suitable_node includes pipeline
+   * limits. Unclassified failures are other.
+   *
+   * @param tier tier of this allocation attempt, including a fallback tier 
when it is attempted
+   * @param failure last unsuccessful creation/wait operation, or null when no 
structured failure is available
+   */
+  void incTierPlacementFailure(StorageTier tier, IOException failure) {
+    String requestedTier = tier == null || tier == StorageTier.EMPTY ? 
UNKNOWN_TIER : tier.name();
+    
tierPlacementFailures.get(requestedTier).get(PlacementFailureReason.fromException(failure)).incr();
+  }
+
+  private enum PlacementFailureReason {
+    NO_SPACE("no_space"),
+    NO_SUITABLE_NODE("no_suitable_node"),
+    OTHER("other");
+
+    private final String label;
+
+    PlacementFailureReason(String label) {
+      this.label = label;
+    }
+
+    private static PlacementFailureReason fromException(IOException failure) {
+      if (failure instanceof SCMException) {
+        SCMException.ResultCodes code = ((SCMException) failure).getResult();
+        if (code == SCMException.ResultCodes.FAILED_TO_FIND_NODES_WITH_SPACE
+            || code == 
SCMException.ResultCodes.FAILED_TO_FIND_CONTAINER_WITH_SPACE) {
+          return NO_SPACE;
+        }
+        if (code == SCMException.ResultCodes.FAILED_TO_FIND_HEALTHY_NODES
+            || code == SCMException.ResultCodes.FAILED_TO_FIND_SUITABLE_NODE
+            || code == SCMException.ResultCodes.FAILED_TO_FIND_NODE_IN_POOL) {

Review Comment:
   Added. Note that today this code is only thrown in the block-protocol 
translator, after allocation succeeded, so it does not reach this metric yet. 
The mapping is there so it is classified correctly if it ever does.



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