The Practice to Monitor Sharing-Sphere Application Performance

  1. Introduction of Sharding-Opentracing
public final class ShardingJDBCTracer {

/**
* 通过读取系统属性进行注册
* -Dshardingjdbc.opentracing.tracer.class=*****
*/

public static void init() {...}

/**
* 通过方法参数进行注册
*/

public static void init(final Tracer tracer) {...}

}
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>sharding-opentracing</artifactId>
<version>3.0.0.M2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-opentracing</artifactId>
<version>5.0.0-beta</version>
</dependency>
ShardingJDBCTracer.init(new SkywalkingTracer());
public class ResultSetMergeInterceptor implements AroundInterceptor1 {

private final TraceContext traceContext;
private final MethodDescriptor descriptor;
private final PLogger logger = PLoggerFactory.getLogger(getClass());

public ResultSetMergeInterceptor(TraceContext traceContext, MethodDescriptor descriptor) {
this.traceContext = traceContext;
this.descriptor = descriptor;
}

@Override
public void before(Object target, Object arg0) {
if (logger.isDebugEnabled()) {
logger.beforeInterceptor(target, new Object[]{arg0});
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
trace.traceBlockBegin();
}

@Override
public void after(Object target, Object arg0, Object result, Throwable throwable) {
if (logger.isDebugEnabled()) {
logger.afterInterceptor(target, new Object[]{arg0}, result, throwable);
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
try {
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordServiceType(ShardingSphereConstants.SHARDING_SPHERE_MERGE);
recorder.recordApi(descriptor);
recorder.recordException(throwable);
} finally {
trace.traceBlockEnd();
}
}
}
public class ShardingSpherePlugin implements ProfilerPlugin, TransformTemplateAware {

private final PLogger logger = PLoggerFactory.getLogger(this.getClass());

private static final String SHARDINGSPHERE_SCOPE = "SHARDINGSPHERE_SCOPE";

private TransformTemplate transformTemplate;

@Override
public void setup(ProfilerPluginSetupContext context) {
ShardingSphereConfig config = new ShardingSphereConfig(context.getConfig());
logger.debug("[ShardingSphere] pluginEnable={}", config.isPluginEnable());
if (config.isPluginEnable()) {
addSqlRouteTransformer();
addSqlExecutorTransformer();
addResultMergeTransformer();
}
}

@Override
public void setTransformTemplate(TransformTemplate transformTemplate) {
this.transformTemplate = transformTemplate;
}

private void addResultMergeTransformer() {
TransformCallback transformCallback = new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);
InstrumentMethod method = target.getDeclaredMethod("merge", "io.shardingsphere.core.merger.MergeEngine");
method.addScopedInterceptor("com.navercorp.pinpoint.plugin.shardingsphere.interceptor.ResultSetMergeInterceptor", SHARDINGSPHERE_SCOPE);
return target.toBytecode();
}
};
transformTemplate.transform("io.shardingsphere.core.jdbc.core.statement.ShardingPreparedStatement", transformCallback);
transformTemplate.transform("io.shardingsphere.core.jdbc.core.statement.ShardingStatement", transformCallback);
}

}

--

--

--

Transform any DBMS in a distributed database system & enhance it with sharding, elastic scaling features & more. https://linktr.ee/ApacheShardingSphere

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What is the best method to calculate background-position for these icons?

Creating and compiling Java Packages on Windows Command line Tutorial for Beginners

Creating and compiling Java Packages on Windows Command line Tutorial for Beginners

Hiring a Voice Actor as an Alexa Skill Developer

The terminal command I always use during development

Install SonarQube on Ubuntu 21 Using PostgreSQL

AAD-20-Debugging

Working with LiDAR — Webinar 1 Getting Started with Sensor Data

LaTeX in the Browser

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Apache ShardingSphere

Apache ShardingSphere

Transform any DBMS in a distributed database system & enhance it with sharding, elastic scaling features & more. https://linktr.ee/ApacheShardingSphere

More from Medium

Pulsar Pseudo Cluster Deployment

Kafka DR Strategy Using MirrorMaker 2

Historize elastic APM server data

Containers for embedded systems