Skip to content

Commit

Permalink
feat: add recorder support
Browse files Browse the repository at this point in the history
  • Loading branch information
jingmu committed May 13, 2024
1 parent db18386 commit 00f381f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alipay.sofa</groupId>
<artifactId>bolt</artifactId>
<version>1.6.9</version>
<version>1.6.10-SNAPSHOT</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down Expand Up @@ -85,7 +85,7 @@

<project.encoding>UTF-8</project.encoding>
<slf4j.version>1.7.21</slf4j.version>
<sofa.common.tools>1.0.12</sofa.common.tools>
<sofa.common.tools>1.4.0</sofa.common.tools>
<sortpom.maven.plugin>2.4.0</sortpom.maven.plugin>
</properties>

Expand Down
20 changes: 19 additions & 1 deletion src/main/java/com/alipay/remoting/InvokeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.alipay.remoting;

import com.alipay.sofa.common.insight.RecordContext;

import java.util.concurrent.ConcurrentHashMap;

/**
Expand Down Expand Up @@ -68,13 +70,19 @@ public class InvokeContext {
// ~~~ constants
public final static int INITIAL_SIZE = 8;

/**
* record context
*/
private RecordContext recordContext;

/** context */
private ConcurrentHashMap<String, Object> context;

/**
* default construct
*/
public InvokeContext() {
this.recordContext = new RecordContext();
this.context = new ConcurrentHashMap<String, Object>(INITIAL_SIZE);
}

Expand Down Expand Up @@ -126,6 +134,16 @@ public <T> T get(String key, T defaultIfNotFound) {
* clear all mappings.
*/
public void clear() {
this.recordContext = new RecordContext();
this.context.clear();
}
}

/**
* Gets get record context.
*
* @return the get record context
*/
public RecordContext getRecordContext() {
return recordContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;

import com.alipay.sofa.common.insight.RecordContext;
import com.alipay.sofa.common.insight.RecordScene;
import com.alipay.sofa.common.insight.RecorderManager;
import org.slf4j.Logger;

import com.alipay.remoting.AbstractRemotingProcessor;
Expand Down Expand Up @@ -131,19 +134,27 @@ public void process(RemotingContext ctx, RpcRequestCommand cmd, ExecutorService
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void doProcess(final RemotingContext ctx, RpcRequestCommand cmd) throws Exception {
long currentTimestamp = System.currentTimeMillis();
try {
long currentTimestamp = System.currentTimeMillis();

preProcessRemotingContext(ctx, cmd, currentTimestamp);
if (ctx.isTimeoutDiscard() && ctx.isRequestTimeout()) {
timeoutLog(cmd, currentTimestamp, ctx);// do some log
return;// then, discard this request
}
debugLog(ctx, cmd, currentTimestamp);
// decode request all
if (!deserializeRequestCommand(ctx, cmd, RpcDeserializeLevel.DESERIALIZE_ALL)) {
return;
RecorderManager.getRecorder().start(RecordScene.BOLT_REQUEST_HANDLE,
new RecordContext(cmd.getId()));

preProcessRemotingContext(ctx, cmd, currentTimestamp);
if (ctx.isTimeoutDiscard() && ctx.isRequestTimeout()) {
timeoutLog(cmd, currentTimestamp, ctx);// do some log
return;// then, discard this request
}
debugLog(ctx, cmd, currentTimestamp);
// decode request all
if (!deserializeRequestCommand(ctx, cmd, RpcDeserializeLevel.DESERIALIZE_ALL)) {
return;
}
dispatchToUserProcessor(ctx, cmd);
} finally {
RecorderManager.getRecorder().stop(RecordScene.BOLT_REQUEST_HANDLE,
ctx.getInvokeContext().getRecordContext());
}
dispatchToUserProcessor(ctx, cmd);
}

/**
Expand Down

0 comments on commit 00f381f

Please sign in to comment.