-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MINOR] improvement(server) Add context to rpc audit log to output necessary context #2088
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,24 +18,33 @@ | |
package org.apache.uniffle.common.audit; | ||
|
||
import java.io.Closeable; | ||
import java.util.Optional; | ||
|
||
import org.slf4j.Logger; | ||
|
||
import org.apache.uniffle.common.rpc.StatusCode; | ||
|
||
/** Context for rpc audit logging. */ | ||
public abstract class RpcAuditContext implements Closeable { | ||
private static final ThreadLocal<RpcAuditContext> RPC_AUDIT_CONTEXT_THREAD_LOCAL = | ||
new ThreadLocal<>(); | ||
private final Logger log; | ||
private String command; | ||
private String statusCode; | ||
private String args; | ||
private String returnValue; | ||
private String context; | ||
private String from; | ||
private long creationTimeNs; | ||
protected long executionTimeNs; | ||
|
||
public RpcAuditContext(Logger log) { | ||
this.log = log; | ||
RPC_AUDIT_CONTEXT_THREAD_LOCAL.set(this); | ||
} | ||
|
||
public static final Optional<RpcAuditContext> getRpcAuditContext() { | ||
return Optional.ofNullable(RPC_AUDIT_CONTEXT_THREAD_LOCAL.get()); | ||
} | ||
|
||
protected abstract String content(); | ||
|
@@ -119,6 +128,21 @@ public RpcAuditContext withFrom(String from) { | |
return this; | ||
} | ||
|
||
/** | ||
* Sets context field, context can be concat by invoke multiply time. | ||
* | ||
* @param contextPart the new context part | ||
* @return this {@link RpcAuditContext} instance | ||
*/ | ||
public RpcAuditContext withContext(String contextPart) { | ||
if (context == null) { | ||
context = contextPart; | ||
} else { | ||
this.context += ", " + contextPart; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks strange, from my thought, If want to record the whole up/downstream context tips. Maybe we need to introduce the dedicated Context class to record the all children context? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like this?
|
||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
if (log == null) { | ||
|
@@ -140,6 +164,9 @@ public String toString() { | |
if (returnValue != null) { | ||
line += String.format("\treturn{%s}", returnValue); | ||
} | ||
if (context != null) { | ||
line += String.format("\tcontext{%s}", context); | ||
} | ||
return line; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ | |
import org.apache.uniffle.common.ShuffleIndexResult; | ||
import org.apache.uniffle.common.ShufflePartitionedBlock; | ||
import org.apache.uniffle.common.ShufflePartitionedData; | ||
import org.apache.uniffle.common.audit.RpcAuditContext; | ||
import org.apache.uniffle.common.config.RssBaseConf; | ||
import org.apache.uniffle.common.exception.FileNotFoundException; | ||
import org.apache.uniffle.common.exception.InvalidRequestException; | ||
|
@@ -641,9 +642,20 @@ public byte[] getFinishedBlockIds( | |
Roaring64NavigableMap res = Roaring64NavigableMap.bitmapOf(); | ||
for (Map.Entry<Integer, Set<Integer>> entry : bitmapIndexToPartitions.entrySet()) { | ||
Set<Integer> requestPartitions = entry.getValue(); | ||
Roaring64NavigableMap bitmap = blockIds[entry.getKey()]; | ||
int bitmapIndex = entry.getKey(); | ||
Roaring64NavigableMap bitmap = blockIds[bitmapIndex]; | ||
getBlockIdsByPartitionId(requestPartitions, bitmap, res, blockIdLayout); | ||
RpcAuditContext.getRpcAuditContext() | ||
.ifPresent( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ifPresent is a good practise, because this avoids unnessary cpu cost if having the much string operations. |
||
context -> | ||
context.withContext( | ||
String.format( | ||
"bitmap[%d].<size,byte>=<%d,%d>", | ||
bitmapIndex, bitmap.getLongCardinality(), bitmap.getLongSizeInBytes()))); | ||
} | ||
RpcAuditContext.getRpcAuditContext() | ||
.ifPresent( | ||
context -> context.withContext("partitionBlockCount=" + res.getLongCardinality())); | ||
|
||
if (res.getLongCardinality() != expectedBlockNumber) { | ||
throw new RssException( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If having performance degression, can we disable this by config? @maobaolong I see some time consuming operations in the hotspot path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can disable the rpc audit log by
rss.server.rpc.audit.log.enabled
andrss.coordinator.rpc.audit.log.enabled