From eb9912469901e0a05f921a1cb24c51a9cd2dc57c Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Fri, 20 Dec 2024 00:16:10 +0000 Subject: [PATCH] CURATOR-726: Improve tracing for MultiTransaction and GetChildren (#513) --- .../curator/drivers/OperationTrace.java | 20 +++++++++++++++++++ .../imps/CuratorMultiTransactionImpl.java | 13 +++++++----- .../imps/GetChildrenBuilderImpl.java | 8 +++++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/curator-client/src/main/java/org/apache/curator/drivers/OperationTrace.java b/curator-client/src/main/java/org/apache/curator/drivers/OperationTrace.java index 8ef3de09f..d4827ac9c 100644 --- a/curator-client/src/main/java/org/apache/curator/drivers/OperationTrace.java +++ b/curator-client/src/main/java/org/apache/curator/drivers/OperationTrace.java @@ -33,8 +33,10 @@ public class OperationTrace { private int returnCode = KeeperException.Code.OK.intValue(); private long latencyMs; + private int requestTransactionCount; private long requestBytesLength; private long responseBytesLength; + private int responseChildrenCount = -1; private String path; private boolean withWatcher; private long sessionId; @@ -57,6 +59,11 @@ public OperationTrace setReturnCode(int returnCode) { return this; } + public OperationTrace setRequestTransactionCount(int transactionCount) { + this.requestTransactionCount = transactionCount; + return this; + } + public OperationTrace setRequestBytesLength(long length) { this.requestBytesLength = length; return this; @@ -97,6 +104,11 @@ public OperationTrace setResponseBytesLength(byte[] data) { return this.setResponseBytesLength(data.length); } + public OperationTrace setResponseChildrenCount(int responseChildrenCount) { + this.responseChildrenCount = responseChildrenCount; + return this; + } + public OperationTrace setPath(String path) { this.path = path; return this; @@ -124,6 +136,10 @@ public long getLatencyMs() { return this.latencyMs; } + public int getRequestTransactionCount() { + return this.requestTransactionCount; + } + public long getRequestBytesLength() { return this.requestBytesLength; } @@ -132,6 +148,10 @@ public long getResponseBytesLength() { return this.responseBytesLength; } + public int getResponseChildrenCount() { + return this.responseChildrenCount; + } + public long getSessionId() { return this.sessionId; } diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorMultiTransactionImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorMultiTransactionImpl.java index befe46d06..9e0bd2265 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorMultiTransactionImpl.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorMultiTransactionImpl.java @@ -26,7 +26,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.Executor; import org.apache.curator.RetryLoop; -import org.apache.curator.TimeTrace; +import org.apache.curator.drivers.OperationTrace; import org.apache.curator.framework.api.BackgroundCallback; import org.apache.curator.framework.api.CuratorEvent; import org.apache.curator.framework.api.CuratorEventType; @@ -160,11 +160,13 @@ public CuratorEventType getBackgroundEventType() { public void performBackgroundOperation(final OperationAndData operationAndData) throws Exception { try { - final TimeTrace trace = client.getZookeeperClient().startTracer("CuratorMultiTransactionImpl-Background"); + final OperationTrace trace = + client.getZookeeperClient().startAdvancedTracer("CuratorMultiTransactionImpl-Background"); AsyncCallback.MultiCallback callback = new AsyncCallback.MultiCallback() { @Override public void processResult(int rc, String path, Object ctx, List opResults) { - trace.commit(); + trace.setRequestTransactionCount(operationAndData.getData().size()) + .commit(); List curatorResults = (opResults != null) ? CuratorTransactionImpl.wrapResults(client, opResults, operationAndData.getData()) : null; @@ -192,7 +194,8 @@ public void processResult(int rc, String path, Object ctx, List opResu private List forOperationsInForeground(final CuratorMultiTransactionRecord record) throws Exception { - TimeTrace trace = client.getZookeeperClient().startTracer("CuratorMultiTransactionImpl-Foreground"); + OperationTrace trace = + client.getZookeeperClient().startAdvancedTracer("CuratorMultiTransactionImpl-Foreground"); List responseData = RetryLoop.callWithRetry(client.getZookeeperClient(), new Callable>() { @Override @@ -200,7 +203,7 @@ public List call() throws Exception { return client.getZooKeeper().multi(record); } }); - trace.commit(); + trace.setRequestTransactionCount(record.size()).commit(); return CuratorTransactionImpl.wrapResults(client, responseData, record); } diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetChildrenBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetChildrenBuilderImpl.java index 6be18d4d2..ddf975cab 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetChildrenBuilderImpl.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetChildrenBuilderImpl.java @@ -165,14 +165,15 @@ public void performBackgroundOperation(final OperationAndData operationA @Override public void processResult(int rc, String path, Object o, List strings, Stat stat) { watching.commitWatcher(rc, false); + if (strings == null) { + strings = Lists.newArrayList(); + } trace.setReturnCode(rc) .setPath(path) .setWithWatcher(watching.hasWatcher()) .setStat(stat) + .setResponseChildrenCount(strings.size()) .commit(); - if (strings == null) { - strings = Lists.newArrayList(); - } CuratorEventImpl event = new CuratorEventImpl( client, CuratorEventType.CHILDREN, @@ -241,6 +242,7 @@ public List call() throws Exception { trace.setPath(path) .setWithWatcher(watching.hasWatcher()) .setStat(responseStat) + .setResponseChildrenCount(children != null ? children.size() : 0) .commit(); return children; }