ArafatKhan2198 commented on code in PR #12145:
URL: https://github.com/apache/ozone/pull/12145#discussion_r4692046939


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java:
##########
@@ -214,6 +220,8 @@ public CompletableFuture<Message> applyTransaction(
         // Otherwise, it's considered as a logical rejection and is returned to
         // Ratis client, leaving SCM intact.
         applyTransactionFuture.completeExceptionally(ex);
+      } finally {
+        span.end();

Review Comment:
   Suppose SCM takes **3 ms** to process a transaction and then spends **200 
ms** flushing the changes to RocksDB. The new `applyTransaction` span ends 
before that flush, so Jaeger can show roughly 3 ms If the flush fails SCM can 
terminate after the span has already finished with no error recorded. An 
unexpected exception from `process()` can also escape the inner handler which 
only records `SCMException`
   
   Could the span cover the full apply operation and record the exception that 
caused it to fail? There’s already a test that deliberately fails the flush and 
verifies SCM terminates. Could that test also check what Jaeger would show? 
[Existing failure 
test](https://github.com/apache/ozone/blob/d4c1c10918e724cb95d359c99c265c47e1d008c6/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMStateMachine.java#L566)



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/protocol/ScmBlockLocationProtocolServerSideTranslatorPB.java:
##########
@@ -192,8 +194,10 @@ private SCMBlockLocationResponse processMessage(
     } catch (IOException e) {
       RatisUtil.checkRatisException(e, scm.getBlockProtocolRpcPort(),
           scm.getScmId(), scm.getHostname(), ROLE_TYPE);
+      TracingUtil.recordExceptionInCurrentSpan(e);

Review Comment:
   Suppose OM asks SCM to delete 100 blocks while SCM is in safe mode. 
`deleteKey`Blocks() can catch the exception and send a normal RPC response 
containing 100 individual safeMode failures. The new tracing code watches for 
an exception reaching the RPC handler. In this case, none reaches it. An 
operator looking at DeleteScmKeyBlocks could miss that zero blocks were deleted.
   
   Could the span show how many blocks failed and why, even when the failure is 
reported inside the response?



##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditMessage.java:
##########
@@ -121,6 +122,7 @@ public Builder setPerformance(PerformanceStringBuilder 
perf) {
     }
 
     public AuditMessage build() {
+      TracingUtil.addAttributesToCurrentSpan(params);

Review Comment:
   Can S3 credentials reach the trace collector? S3 Gateway puts every query 
parameter in the audit map, and this change copies that map into the span. 
Could we allowlist the fields we export and add a presigned-request test 
proving that X-Amz-Signature and X-Amz-Security-Token never reach the 
collector? 
   
   and add a test proving that the signature and session token never appear in 
a span?



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java:
##########
@@ -623,6 +627,13 @@ public static void addAttributesToCurrentSpan(String key, 
boolean value) {
     }
   }
 
+  public static void addAttributesToCurrentSpan(Map<String, String> 
attributes) {
+    if (attributes == null) {
+      return;
+    }
+    attributes.forEach(TracingUtil::addAttributesToCurrentSpan);

Review Comment:
   There are two separate costs - 
   
   **When tracing is off**, Ozone still goes through every field in the audit 
map to check whether it can add that field to a span. For example, if the map 
has 64 fields, it checks the current span 64 times. Checking once before the 
loop could avoid that work.
   
   **When tracing is on**, some fields can be very large. `KeyBlockToDelete` 
can contain a whole batch of blocks. Adding the full list to a span means 
Jaeger has more data to receive and store. A count and a few example block IDs 
might be enough to understand what happened.
   
   Could we check whether the span is recording before looping through the 
audit map? Have we measured the performance impact of adding these audit fields 
to spans?



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java:
##########
@@ -202,9 +205,12 @@ public CompletableFuture<Message> applyTransaction(
       if (LOG.isDebugEnabled()) {
         LOG.debug("{}: applyTransaction {}", getId(), 
TermIndex.valueOf(trx.getLogEntry()));
       }
-      try {
+      final Span span = request.getTraceID().isEmpty() ? Span.getInvalid()
+          : 
TracingUtil.importAndCreateSpan("SCMStateMachine.applyTransaction", 
request.getTraceID());

Review Comment:
   I had a query, do correct me if I am missing something.
   
   Ozone passes trace information from one SCM to another so Jaeger can connect 
their work. This information can also include extra details called tracestate.
   
   The current parser can lose those extra details The existing parser splits 
at every =, gets three pieces, and discards the field. The spans still appear 
connected in Jaeger because the parent ID survives, so a test that checks only 
the parent-child relationship passes.
   
   Could we also test that tracestate is preserved when the trace passes 
through Ratis? The spans may still appear connected even if those extra details 
are lost.



##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMRatisServerImpl.java:
##########
@@ -232,6 +243,82 @@ public void testGetRatisRolesKeepsHostname() throws 
Exception {
     }
   }
 
+  @Test
+  public void testSubmitRequestIsTracedUnderTheCurrentSpan() throws Exception {
+    ArgumentCaptor<RaftClientRequest> submitted = 
ArgumentCaptor.forClass(RaftClientRequest.class);
+    SCMRatisServerImpl scmRatisServer = newScmRatisServer(submitted, null);
+    SCMRatisRequest request = SCMRatisRequest.of(RequestType.PIPELINE, "op", 
new Class<?>[0]);
+
+    try (TestSpanCollector collector = TestSpanCollector.install("scm")) {
+      TracingUtil.executeInNewSpan("request", () -> 
scmRatisServer.submitRequest(request));
+
+      collector.assertParent("SCMRatisServerImpl.submit.op", "request");
+      // The request is encoded inside the span, so the apply span on each SCM 
continues from it.
+      String traceID = 
SCMRatisRequest.decode(submitted.getValue().getMessage()).getTraceID();
+      TracingUtil.executeAsChildSpan("apply", traceID, () -> { });
+      collector.assertParent("apply", "SCMRatisServerImpl.submit.op");
+    }
+  }
+

Review Comment:
   There are two pieces of information here. OpenTelemetry’s ERROR says the 
operation failed. Ozone’s ozone.status can say why, for example 
CONTAINER_NOT_FOUND. The pr desc explained that the dispatcher already records 
thrown exceptions. The remaining question is about searching. A span can show 
an exception and still be missing from a search for 
ozone.status=CONTAINER_NOT_FOUND.
   
   Do we expect operators to be able to search by Ozone error code across 
protocols, regardless of how the server reported the failure?



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineManagerImpl.java:
##########
@@ -221,9 +224,10 @@ public Pipeline createPipeline(ReplicationConfig 
replicationConfig,
       throws IOException {
     checkIfPipelineCreationIsAllowed(replicationConfig);
 
-    acquireWriteLock();
+    final Span span = 
TracingUtil.createInternalSpan("PipelineManagerImpl.createPipeline");
+    TracingUtil.executeInNewSpan("PipelineManagerImpl.acquireWriteLock", () -> 
acquireWriteLock());
     final Pipeline pipeline;
-    try {
+    try (Scope ignored = span.makeCurrent()) {

Review Comment:
   SCM takes a write lock while creating a pipeline one so it can safely update 
pipeline state. The new tracing code currently runs in this order.
   
   1. SCM checks whether pipeline creation is allowed. The check can reject 
creation when safe-mode prechecks have not passed.
   2. SCM creates a createPipeline span.
   3. It starts another span and waits for the write lock.
   4. Once it gets the lock, it makes createPipeline the active span and 
continues creating the pipeline.
   
   The ordering creates two gaps in Jaeger.
   - If the check in step 1 fails, there is no createPipeline span for that 
attempt.
   - The lock-wait span starts before createPipeline is active, so it can 
appear beside the creation span. Someone reading the trace may not realize that 
the wait happened during this creation attempt.
   
   For example, SCM could wait 80 ms for the lock and then spend 20 ms creating 
the pipeline. A connected trace should help the operator see both parts of that 
100 ms attempt.
   
   Could we also start and activate the createPipeline span before the 
safe-mode check? That would let the span capture an early rejection as well as 
the lock wait. Could we add a test that checks the lock-wait span is a child of 
createPipeline and ends once the lock is acquired?
   
   Do correct me if I am missing something here, and if its a bad idea to do so.



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