提交 8c9c3e65 编写于 作者: wu-sheng's avatar wu-sheng

Finish some grpc client codes.

上级 11b4dc7b
package org.skywalking.apm.agent.core.boot;
/**
* The <code>BootService</code> is an interface to all services, which need to boot when plugin mechanism begins to
* The <code>BootService</code> is an interface to all remote, which need to boot when plugin mechanism begins to
* work.
* {@link #bootUp()} will be called when <code>BootService</code> start up.
*
......
......@@ -5,7 +5,7 @@ package org.skywalking.apm.agent.core.context.ids;
* <p>
* This call chain has an unique (service) entrance,
* <p>
* such as: Service : http://www.skywalking.com/cust/query, all the services, called behind this service, rest services,
* such as: Service : http://www.skywalking.com/cust/query, all the remote, called behind this service, rest remote,
* db executions, are using the same <code>DistributedTraceId</code> even in different JVM.
* <p>
* The <code>DistributedTraceId</code> contains only one string, and can NOT be reset, creating a new instance is the
......
......@@ -13,11 +13,11 @@ public interface AbstractSpan {
* Set the component id, which defines in {@link org.skywalking.apm.network.trace.component.ComponentsDefine}
* @param component
*/
void setComponent(Component component);
AbstractSpan setComponent(Component component);
void setComponent(String componentName);
AbstractSpan setComponent(String componentName);
void setLayer(SpanLayer layer);
AbstractSpan setLayer(SpanLayer layer);
/**
* Set a key:value tag on the Span.
......@@ -34,7 +34,7 @@ public interface AbstractSpan {
*/
AbstractSpan log(Throwable t);
void errorOccurred();
AbstractSpan errorOccurred();
/**
* @return true if the actual span is an entry span.
......
......@@ -108,8 +108,9 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
return this;
}
public void errorOccurred() {
public AbstractSpan errorOccurred() {
this.errorOccurred = true;
return this;
}
public int getSpanId() {
......@@ -121,17 +122,20 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
}
@Override
public void setLayer(SpanLayer layer) {
public AbstractSpan setLayer(SpanLayer layer) {
this.layer = layer;
return this;
}
@Override
public void setComponent(Component component) {
public AbstractSpan setComponent(Component component) {
this.componentId = component.getId();
return this;
}
@Override
public void setComponent(String componentName) {
public AbstractSpan setComponent(String componentName) {
this.componentName = componentName;
return this;
}
}
......@@ -3,10 +3,10 @@ package org.skywalking.apm.agent.core.context.trace;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
/**
* The <code>ExitSpan</code> represents a service consumer point, such as Feign, Okhttp client for a Http service.
* The <code>ExitSpan</code> represents a service consumer point, such as Feign, Okhttp discovery for a Http service.
*
* It is an exit point or a leaf span(our old name) of trace tree.
* In a single rpc call, because of a combination of client libs, there maybe contain multi exit point.
* In a single rpc call, because of a combination of discovery libs, there maybe contain multi exit point.
*
* The <code>ExitSpan</code> only presents the first one.
*
......
package org.skywalking.apm.agent.core.context.trace;
import org.skywalking.apm.agent.core.context.IgnoredTracerContext;
import org.skywalking.apm.network.trace.component.Component;
/**
* The <code>NoopSpan</code> represents a span implementation without any actual operation.
......@@ -18,10 +19,26 @@ public class NoopSpan implements AbstractSpan {
return this;
}
@Override public AbstractSpan errorOccurred() {
return null;
}
public void finish(){
}
@Override public AbstractSpan setComponent(Component component) {
return this;
}
@Override public AbstractSpan setComponent(String componentName) {
return this;
}
@Override public AbstractSpan setLayer(SpanLayer layer) {
return this;
}
@Override
public AbstractSpan tag(String key, String value) {
return this;
......
package org.skywalking.apm.agent.core.client;
package org.skywalking.apm.agent.core.discovery;
import org.skywalking.apm.agent.core.boot.StatusBootService;
import org.skywalking.apm.agent.core.remote.DiscoveryRestServiceClient;
/**
* The <code>CollectorDiscoveryService</code> is responsible for start {@link DiscoveryRestServiceClient}.
......
package org.skywalking.apm.agent.core.remote;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.internal.DnsNameResolverProvider;
import io.grpc.netty.NettyChannelBuilder;
import org.skywalking.apm.agent.core.boot.BootService;
import org.skywalking.apm.logging.ILog;
import org.skywalking.apm.logging.LogManager;
/**
* @author wusheng
*/
public class GRPCChannelManager implements BootService, Runnable {
private static final ILog logger = LogManager.getLogger(DiscoveryRestServiceClient.class);
private volatile Thread channelManagerThread = null;
private volatile ManagedChannel managedChannel = null;
@Override
public void bootUp() throws Throwable {
this.startupInBackground();
}
private void startupInBackground() {
if (channelManagerThread == null || !channelManagerThread.isAlive()) {
synchronized (this) {
if (channelManagerThread == null || !channelManagerThread.isAlive()) {
if (managedChannel == null || managedChannel.isTerminated() || managedChannel.isShutdown()) {
managedChannel.shutdownNow();
Thread channelManagerThread = new Thread(this, "ChannelManagerThread");
channelManagerThread.setDaemon(true);
channelManagerThread.start();
}
}
}
}
}
@Override
public void run() {
ManagedChannelBuilder<?> channelBuilder =
NettyChannelBuilder.forAddress("127.0.0.1", 808)
.nameResolverFactory(new DnsNameResolverProvider())
.maxInboundMessageSize(1024 * 1024 * 50)
.usePlaintext(true);
managedChannel = channelBuilder.build();
}
public static void main(String[] args) throws Throwable {
new GRPCChannelManager().bootUp();
Thread.sleep(60 * 1000);
}
}
package org.skywalking.apm.agent.core.client;
package org.skywalking.apm.agent.core.remote;
/**
* The <code>RESTResponseStatusError</code> represents the REST-Service client got an unexpected response code.
* The <code>RESTResponseStatusError</code> represents the REST-Service discovery got an unexpected response code.
* Most likely, the response code is not 200.
*
* @author wusheng
......
package org.skywalking.apm.agent.core.remote;
/**
* @author wusheng
*/
public class TraceSegmentServiceClient {
public void start() {
}
public void switchChannel(){
}
}
org.skywalking.apm.agent.core.datacarrier.DataBufferService
org.skywalking.apm.agent.core.context.ContextManager
org.skywalking.apm.agent.core.client.CollectorDiscoveryService
org.skywalking.apm.agent.core.discovery.CollectorDiscoveryService
org.skywalking.apm.agent.core.sampling.SamplingService
org.skywalking.apm.agent.core.remote.GRPCChannelManager
package org.skywalking.apm.agent.core.client;
package org.skywalking.apm.agent.core.discovery;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
......@@ -19,7 +19,7 @@ import java.io.IOException;
/**
* This is a small application, test for http restful service.
* Use APACHE HttpClient as client, nanohttpd as server.
* Use APACHE HttpClient as discovery, nanohttpd as server.
*
* @author wusheng
*/
......
......@@ -14,7 +14,7 @@ public final class BugFixActive {
private static boolean ACTIVE = false;
/**
* Set active status, before startup dubbo services.
* Set active status, before startup dubbo remote.
*/
public static void active() {
BugFixActive.ACTIVE = true;
......
......@@ -12,8 +12,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link DefaultHttpClientInstrumentation} presents that skywalking intercepts {@link
* feign.Client.Default#execute(feign.Request, feign.Request.Options)} by using {@link DefaultHttpClientInterceptor}.
* If feign did't run in default mode, the instrumentation depend on the http client implementation.
* e.g. okhttp client implementation depend on okhttp-plugin.
* If feign did't run in default mode, the instrumentation depend on the http discovery implementation.
* e.g. okhttp discovery implementation depend on okhttp-plugin.
*
* @author pengys5
*/
......
......@@ -104,7 +104,7 @@ public class DefaultHttpClientInterceptorTest {
Assert.assertEquals("skywalking.org", span.getPeerHost());
Assert.assertEquals(-1, span.getPort());
Assert.assertEquals("FeignDefaultHttp", StringTagReader.get(span, Tags.COMPONENT));
Assert.assertEquals("client", StringTagReader.get(span, Tags.SPAN_KIND));
Assert.assertEquals("discovery", StringTagReader.get(span, Tags.SPAN_KIND));
Assert.assertEquals("", StringTagReader.get(span, Tags.URL));
}
......
......@@ -18,7 +18,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
*/
public class AbstractHttpClientInstrumentation extends HttpClientInstrumentation {
private static final String ENHANCE_CLASS = "org.apache.http.impl.client.AbstractHttpClient";
private static final String ENHANCE_CLASS = "org.apache.http.impl.discovery.AbstractHttpClient";
@Override
public String enhanceClassName() {
......
......@@ -19,7 +19,7 @@ public class DefaultRequestDirectorInstrumentation extends HttpClientInstrumenta
/**
* Enhance class.
*/
private static final String ENHANCE_CLASS = "org.apache.http.impl.client.DefaultRequestDirector";
private static final String ENHANCE_CLASS = "org.apache.http.impl.discovery.DefaultRequestDirector";
/**
* DefaultRequestDirector is default implement.<br/>
......
......@@ -15,7 +15,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
*/
public class InternalHttpClientInstrumentation extends HttpClientInstrumentation {
private static final String ENHANCE_CLASS = "org.apache.http.impl.client.InternalHttpClient";
private static final String ENHANCE_CLASS = "org.apache.http.impl.discovery.InternalHttpClient";
@Override
public String enhanceClassName() {
......
......@@ -18,7 +18,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
*/
public class MinimalHttpClientInstrumentation extends HttpClientInstrumentation {
private static final String ENHANCE_CLASS = "org.apache.http.impl.client.MinimalHttpClient";
private static final String ENHANCE_CLASS = "org.apache.http.impl.discovery.MinimalHttpClient";
@Override
public String enhanceClassName() {
......
......@@ -327,7 +327,7 @@ public class SWConnectionTest extends AbstractStatementTest {
swConnection.setHoldability(1);
swConnection.getHoldability();
swConnection.setReadOnly(false);
swConnection.setClientInfo("test-client", "test-client");
swConnection.setClientInfo("test-discovery", "test-discovery");
swConnection.getClientInfo("test");
swConnection.setSavepoint();
swConnection.getMetaData();
......
......@@ -16,7 +16,7 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsA
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
/**
* {@link RealCallInterceptor} intercept the synchronous http calls by the client of okhttp.
* {@link RealCallInterceptor} intercept the synchronous http calls by the discovery of okhttp.
*
* @author pengys5
*/
......
......@@ -111,7 +111,7 @@ public class RealCallInterceptorTest {
Assert.assertEquals("skywalking.org", span.getPeerHost());
Assert.assertEquals(80, span.getPort());
Assert.assertEquals("OKHttp", StringTagReader.get(span, Tags.COMPONENT));
Assert.assertEquals("client", StringTagReader.get(span, Tags.SPAN_KIND));
Assert.assertEquals("discovery", StringTagReader.get(span, Tags.SPAN_KIND));
Assert.assertEquals("/", StringTagReader.get(span, Tags.URL));
}
......
......@@ -6,7 +6,7 @@ import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
/**
* The <code>DubboSpanGenerator</code> generates all possible spans, by tracing Dubbo rpc.
* Including client/server side span.
* Including discovery/server side span.
*
* @author wusheng
*/
......
......@@ -5,7 +5,7 @@ import org.skywalking.apm.agent.core.context.tag.Tags;
import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
/**
* The <code>MySQLGenerator</code> generates all possible spans, by tracing mysql client access.
* The <code>MySQLGenerator</code> generates all possible spans, by tracing mysql discovery access.
*
* @author wusheng
*/
......
......@@ -9,7 +9,7 @@ import org.skywalking.apm.agent.core.context.trace.TraceSegment;
/**
* A Trace segment contains two spans with ChildOf relations,
* the parent is a Tomcat span,
* the child is a Dubbo client span.
* the child is a Dubbo discovery span.
*
* @author wusheng
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册