htrace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iwasak...@apache.org
Subject incubator-htrace git commit: HTRACE-313. htraced span receiver clientDropped file should include timestamps (Colin Patrick McCabe via iwasakims)
Date Tue, 01 Dec 2015 17:36:06 GMT
Repository: incubator-htrace
Updated Branches:
  refs/heads/master eb5955da5 -> 2ccb38813


HTRACE-313. htraced span receiver clientDropped file should include timestamps (Colin Patrick
McCabe via iwasakims)


Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/2ccb3881
Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/2ccb3881
Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/2ccb3881

Branch: refs/heads/master
Commit: 2ccb38813c4d7260c6a257e5c005341c9719b4d6
Parents: eb5955d
Author: Masatake Iwasaki <iwasakims@apache.org>
Authored: Wed Dec 2 00:56:29 2015 +0900
Committer: Masatake Iwasaki <iwasakims@apache.org>
Committed: Wed Dec 2 00:56:29 2015 +0900

----------------------------------------------------------------------
 .../apache/htrace/impl/HTracedSpanReceiver.java | 36 +++++++++++++++++++-
 .../apache/htrace/impl/TestDroppedSpans.java    |  6 ++--
 2 files changed, 38 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2ccb3881/htrace-htraced/src/main/java/org/apache/htrace/impl/HTracedSpanReceiver.java
----------------------------------------------------------------------
diff --git a/htrace-htraced/src/main/java/org/apache/htrace/impl/HTracedSpanReceiver.java
b/htrace-htraced/src/main/java/org/apache/htrace/impl/HTracedSpanReceiver.java
index 4e6d56a..6e6bb22 100644
--- a/htrace-htraced/src/main/java/org/apache/htrace/impl/HTracedSpanReceiver.java
+++ b/htrace-htraced/src/main/java/org/apache/htrace/impl/HTracedSpanReceiver.java
@@ -27,8 +27,16 @@ import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.Files;
+import java.nio.file.FileSystems;
 import java.nio.file.Paths;
 import java.nio.file.StandardOpenOption;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TimeZone;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantLock;
@@ -88,6 +96,26 @@ public class HTracedSpanReceiver extends SpanReceiver {
 
   private long unbufferableSpans = 0;
 
+  private static final SimpleDateFormat ISO_DATE_FORMAT;
+
+  private static final Set<PosixFilePermission> DROPPED_SPANS_FILE_PERMS;
+
+  static {
+    ISO_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
+    ISO_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
+    if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
+      DROPPED_SPANS_FILE_PERMS = new HashSet<PosixFilePermission>();
+      DROPPED_SPANS_FILE_PERMS.add(PosixFilePermission.OWNER_READ);
+      DROPPED_SPANS_FILE_PERMS.add(PosixFilePermission.OWNER_WRITE);
+      DROPPED_SPANS_FILE_PERMS.add(PosixFilePermission.GROUP_READ);
+      DROPPED_SPANS_FILE_PERMS.add(PosixFilePermission.GROUP_WRITE);
+      DROPPED_SPANS_FILE_PERMS.add(PosixFilePermission.OTHERS_READ);
+      DROPPED_SPANS_FILE_PERMS.add(PosixFilePermission.OTHERS_WRITE);
+    } else {
+      DROPPED_SPANS_FILE_PERMS = null;
+    }
+  }
+
   static class FaultInjector {
     static FaultInjector NO_OP = new FaultInjector();
     public void handleContentLengthTrigger(int len) { }
@@ -368,8 +396,9 @@ public class HTracedSpanReceiver extends SpanReceiver {
       return;
     }
     FileLock lock = null;
+    String msg = ISO_DATE_FORMAT.format(new Date()) + ": " + text;
     ByteBuffer bb = ByteBuffer.wrap(
-        text.getBytes(StandardCharsets.UTF_8));
+        msg.getBytes(StandardCharsets.UTF_8));
     // FileChannel locking corresponds to advisory locking on UNIX.  It will
     // protect multiple processes from attempting to write to the same dropped
     // spans log at once.  However, within a single process, we need this
@@ -386,6 +415,11 @@ public class HTracedSpanReceiver extends SpanReceiver {
           throw new IOException("Dropped spans log " +
               conf.droppedSpansLogPath + " is already " + size +
               " bytes; will not add to it.");
+        } else if ((size == 0) && (DROPPED_SPANS_FILE_PERMS != null)) {
+          // Set the permissions of the dropped spans file so that other
+          // processes can write to it.
+          Files.setPosixFilePermissions(Paths.get(conf.droppedSpansLogPath),
+              DROPPED_SPANS_FILE_PERMS);
         }
         channel.write(bb);
       } finally {

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2ccb3881/htrace-htraced/src/test/java/org/apache/htrace/impl/TestDroppedSpans.java
----------------------------------------------------------------------
diff --git a/htrace-htraced/src/test/java/org/apache/htrace/impl/TestDroppedSpans.java b/htrace-htraced/src/test/java/org/apache/htrace/impl/TestDroppedSpans.java
index 8947365..3f336f1 100644
--- a/htrace-htraced/src/test/java/org/apache/htrace/impl/TestDroppedSpans.java
+++ b/htrace-htraced/src/test/java/org/apache/htrace/impl/TestDroppedSpans.java
@@ -105,7 +105,7 @@ public class TestDroppedSpans {
           put(Conf.ADDRESS_KEY, "127.0.0.1:8080");
           put(TracerId.TRACER_ID_KEY, "testWriteToDroppedSpansLog");
           put(Conf.DROPPED_SPANS_LOG_PATH_KEY, logPath);
-          put(Conf.DROPPED_SPANS_LOG_MAX_SIZE_KEY, "78");
+          put(Conf.DROPPED_SPANS_LOG_MAX_SIZE_KEY, "128");
         }});
     HTracedSpanReceiver rcvr = new HTracedSpanReceiver(conf);
     try {
@@ -123,8 +123,8 @@ public class TestDroppedSpans {
       List<String> lines =
           Files.readAllLines(Paths.get(logPath), StandardCharsets.UTF_8);
       Assert.assertEquals(2, lines.size());
-      Assert.assertEquals(LINE1, lines.get(0));
-      Assert.assertEquals(LINE2, lines.get(1));
+      Assert.assertEquals(LINE1, lines.get(0).substring(25));
+      Assert.assertEquals(LINE2, lines.get(1).substring(25));
     } finally {
       rcvr.close();
     }


Mime
View raw message