Skip to content

Commit c84504c

Browse files
muqingCaijingmu
authored andcommitted
Add recorder support (#351)
* feat: add recorder support * upgrade version to 1.6.10 --------- Co-authored-by: jingmu <[email protected]>
1 parent ccf721f commit c84504c

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<modelVersion>4.0.0</modelVersion>
2323
<groupId>com.alipay.sofa</groupId>
2424
<artifactId>bolt</artifactId>
25-
<version>1.6.9</version>
25+
<version>1.6.10</version>
2626
<packaging>jar</packaging>
2727

2828
<name>${project.groupId}:${project.artifactId}</name>
@@ -85,7 +85,7 @@
8585

8686
<project.encoding>UTF-8</project.encoding>
8787
<slf4j.version>1.7.21</slf4j.version>
88-
<sofa.common.tools>1.0.12</sofa.common.tools>
88+
<sofa.common.tools>1.4.0</sofa.common.tools>
8989
<sortpom.maven.plugin>2.4.0</sortpom.maven.plugin>
9090
</properties>
9191

src/main/java/com/alipay/remoting/InvokeContext.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package com.alipay.remoting;
1818

19+
import com.alipay.sofa.common.insight.RecordContext;
20+
1921
import java.util.concurrent.ConcurrentHashMap;
2022

2123
/**
@@ -68,13 +70,19 @@ public class InvokeContext {
6870
// ~~~ constants
6971
public final static int INITIAL_SIZE = 8;
7072

73+
/**
74+
* record context
75+
*/
76+
private RecordContext recordContext;
77+
7178
/** context */
7279
private ConcurrentHashMap<String, Object> context;
7380

7481
/**
7582
* default construct
7683
*/
7784
public InvokeContext() {
85+
this.recordContext = new RecordContext();
7886
this.context = new ConcurrentHashMap<String, Object>(INITIAL_SIZE);
7987
}
8088

@@ -126,6 +134,16 @@ public <T> T get(String key, T defaultIfNotFound) {
126134
* clear all mappings.
127135
*/
128136
public void clear() {
137+
this.recordContext = new RecordContext();
129138
this.context.clear();
130139
}
131-
}
140+
141+
/**
142+
* Gets get record context.
143+
*
144+
* @return the get record context
145+
*/
146+
public RecordContext getRecordContext() {
147+
return recordContext;
148+
}
149+
}

src/main/java/com/alipay/remoting/rpc/protocol/RpcRequestProcessor.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import java.util.concurrent.ExecutorService;
2121
import java.util.concurrent.RejectedExecutionException;
2222

23+
import com.alipay.sofa.common.insight.RecordContext;
24+
import com.alipay.sofa.common.insight.RecordScene;
25+
import com.alipay.sofa.common.insight.RecorderManager;
2326
import org.slf4j.Logger;
2427

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

136-
preProcessRemotingContext(ctx, cmd, currentTimestamp);
137-
if (ctx.isTimeoutDiscard() && ctx.isRequestTimeout()) {
138-
timeoutLog(cmd, currentTimestamp, ctx);// do some log
139-
return;// then, discard this request
140-
}
141-
debugLog(ctx, cmd, currentTimestamp);
142-
// decode request all
143-
if (!deserializeRequestCommand(ctx, cmd, RpcDeserializeLevel.DESERIALIZE_ALL)) {
144-
return;
140+
RecorderManager.getRecorder().start(RecordScene.BOLT_REQUEST_HANDLE,
141+
new RecordContext(cmd.getId()));
142+
143+
preProcessRemotingContext(ctx, cmd, currentTimestamp);
144+
if (ctx.isTimeoutDiscard() && ctx.isRequestTimeout()) {
145+
timeoutLog(cmd, currentTimestamp, ctx);// do some log
146+
return;// then, discard this request
147+
}
148+
debugLog(ctx, cmd, currentTimestamp);
149+
// decode request all
150+
if (!deserializeRequestCommand(ctx, cmd, RpcDeserializeLevel.DESERIALIZE_ALL)) {
151+
return;
152+
}
153+
dispatchToUserProcessor(ctx, cmd);
154+
} finally {
155+
RecorderManager.getRecorder().stop(RecordScene.BOLT_REQUEST_HANDLE,
156+
ctx.getInvokeContext().getRecordContext());
145157
}
146-
dispatchToUserProcessor(ctx, cmd);
147158
}
148159

149160
/**

0 commit comments

Comments
 (0)