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/20 18:51:12 UTC

[ozone] branch master updated: HDDS-7064. S3 get-object response emits tracing spans outside ObjectEndpoint#get (#4288)

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 cafb372799 HDDS-7064. S3 get-object response emits tracing spans outside ObjectEndpoint#get (#4288)
cafb372799 is described below

commit cafb372799260581132cc694ac44a0f6b768db9a
Author: Ivan Andika <36...@users.noreply.github.com>
AuthorDate: Tue Feb 21 02:51:06 2023 +0800

    HDDS-7064. S3 get-object response emits tracing spans outside ObjectEndpoint#get (#4288)
---
 .../org/apache/hadoop/ozone/s3/TracingFilter.java  | 29 +++++++++++++++++++---
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/TracingFilter.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/TracingFilter.java
index 28e5665579..2a1b258273 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/TracingFilter.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/TracingFilter.java
@@ -30,6 +30,10 @@ import io.opentracing.ScopeManager;
 import io.opentracing.Span;
 import io.opentracing.util.GlobalTracer;
 
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
 /**
  * Filter used to add jaeger tracing span.
  */
@@ -60,19 +64,36 @@ public class TracingFilter implements ContainerRequestFilter,
   @Override
   public void filter(ContainerRequestContext requestContext,
       ContainerResponseContext responseContext) {
-    Scope scope = (Scope)requestContext.getProperty(TRACING_SCOPE);
+    final Scope scope = (Scope) requestContext.getProperty(TRACING_SCOPE);
+    final Span span = (Span) requestContext.getProperty(TRACING_SPAN);
+    // HDDS-7064: Operation performed while writing StreamingOutput response
+    // should only be closed once the StreamingOutput callback has completely
+    // written the data to the destination
+    OutputStream out = responseContext.getEntityStream();
+    if (out != null) {
+      responseContext.setEntityStream(new FilterOutputStream(out) {
+        @Override
+        public void close() throws IOException {
+          super.close();
+          finishAndClose(scope, span);
+        }
+      });
+    } else {
+      finishAndClose(scope, span);
+    }
+  }
+
+  private static void finishAndClose(Scope scope, Span span) {
     if (scope != null) {
       scope.close();
     }
-    Span span = (Span) requestContext.getProperty(TRACING_SPAN);
     if (span != null) {
       span.finish();
     }
-
     finishAndCloseActiveSpan();
   }
 
-  private void finishAndCloseActiveSpan() {
+  private static void finishAndCloseActiveSpan() {
     ScopeManager scopeManager = GlobalTracer.get().scopeManager();
     if (scopeManager != null && scopeManager.activeSpan() != null) {
       scopeManager.activeSpan().finish();


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