You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by ad...@apache.org on 2023/02/16 21:55:03 UTC

[ozone] branch master updated: HDDS-7976. FsShell creates unrelated trace spans (#4281)

This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 88c0a6621a HDDS-7976. FsShell creates unrelated trace spans (#4281)
88c0a6621a is described below

commit 88c0a6621a0a55c2fa4dc400c01346fbf02e27a0
Author: Doroszlai, Attila <64...@users.noreply.github.com>
AuthorDate: Thu Feb 16 22:54:57 2023 +0100

    HDDS-7976. FsShell creates unrelated trace spans (#4281)
---
 .../org/apache/hadoop/hdds/tracing/TracingUtil.java   | 19 +++++++++++++++++++
 .../java/org/apache/hadoop/fs/ozone/OzoneFsShell.java | 14 ++++++++++----
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java
index 4985c6f281..2270db79c3 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java
@@ -19,6 +19,7 @@ package org.apache.hadoop.hdds.tracing;
 
 import java.io.IOException;
 import java.lang.reflect.Proxy;
+import java.util.concurrent.Callable;
 import java.util.function.Supplier;
 
 import org.apache.hadoop.hdds.conf.ConfigurationSource;
@@ -140,6 +141,24 @@ public final class TracingUtil {
         ScmConfigKeys.HDDS_TRACING_ENABLED_DEFAULT);
   }
 
+  /**
+   * Call {@code callee} in a new active span.
+   */
+  public static <T> T executeInNewSpan(String spanName,
+      Callable<T> callee)
+      throws Exception {
+    Span span = GlobalTracer.get()
+        .buildSpan(spanName).start();
+    try (Scope ignored = GlobalTracer.get().activateSpan(span)) {
+      return callee.call();
+    } catch (Exception ex) {
+      span.setTag("failed", true);
+      throw ex;
+    } finally {
+      span.finish();
+    }
+  }
+
   /**
    * Execute a new function inside an activated span.
    */
diff --git a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzoneFsShell.java b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzoneFsShell.java
index 46a4c1c364..4ff4916b61 100644
--- a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzoneFsShell.java
+++ b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzoneFsShell.java
@@ -26,6 +26,8 @@ import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.apache.hadoop.hdds.tracing.TracingUtil;
 import org.apache.hadoop.util.ToolRunner;
 
+import java.util.concurrent.Callable;
+
 /** Provide command line access to a Ozone FileSystem. */
 @InterfaceAudience.Private
 public class OzoneFsShell extends FsShell {
@@ -78,13 +80,17 @@ public class OzoneFsShell extends FsShell {
     TracingUtil.initTracing("FsShell", conf);
     conf.setQuietMode(false);
     shell.setConf(conf);
-    int res;
+    int res = TracingUtil.executeInNewSpan("main",
+        (Callable<Integer>) () -> shell.execute(argv));
+    System.exit(res);
+  }
+
+  private int execute(String[] argv) throws Exception {
     try {
-      res = ToolRunner.run(shell, argv);
+      return ToolRunner.run(this, argv);
     } finally {
-      shell.close();
+      close();
     }
-    System.exit(res);
   }
 
   // TODO: this should be abstract in a base class


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