Skip to content
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

Add recorder support #351

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
chuailiwu marked this conversation as resolved.
Show resolved Hide resolved
<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>
chuailiwu marked this conversation as resolved.
Show resolved Hide resolved
<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
Loading