Fix jedis missing tag: span.kind.
This commit is contained in:
parent
590d93f0ca
commit
5f6dd33ce1
|
|
@ -17,36 +17,35 @@ public enum ServiceManager {
|
|||
INSTANCE;
|
||||
|
||||
private static ILog logger = LogManager.getLogger(StatusBootService.class);
|
||||
private volatile boolean isStarted = false;
|
||||
private Map<Class, BootService> bootedServices;
|
||||
private Map<Class, BootService> bootedServices = new HashMap<Class, BootService>();
|
||||
|
||||
public void boot() {
|
||||
if (!isStarted) {
|
||||
bootedServices = loadAllServices();
|
||||
}
|
||||
|
||||
private Map<Class, BootService> loadAllServices() {
|
||||
HashMap<Class, BootService> bootedServices = new HashMap<Class, BootService>();
|
||||
Iterator<BootService> serviceIterator = load().iterator();
|
||||
while (serviceIterator.hasNext()) {
|
||||
BootService bootService = serviceIterator.next();
|
||||
try {
|
||||
bootedServices = new HashMap<Class, BootService>();
|
||||
Iterator<BootService> serviceIterator = load().iterator();
|
||||
while (serviceIterator.hasNext()) {
|
||||
BootService bootService = serviceIterator.next();
|
||||
try {
|
||||
bootService.bootUp();
|
||||
bootedServices.put(bootService.getClass(), bootService);
|
||||
} catch (Throwable e) {
|
||||
logger.error(e, "ServiceManager try to start [{}] fail.", bootService.getClass().getName());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
isStarted = true;
|
||||
bootService.bootUp();
|
||||
bootedServices.put(bootService.getClass(), bootService);
|
||||
} catch (Throwable e) {
|
||||
logger.error(e, "ServiceManager try to start [{}] fail.", bootService.getClass().getName());
|
||||
}
|
||||
}
|
||||
return bootedServices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a {@link BootService} implementation, which is already started.
|
||||
*
|
||||
* @param serviceClass class name.
|
||||
* @param <T> {@link BootService} implementation class.
|
||||
* @return {@link BootService} instance
|
||||
*/
|
||||
public <T extends BootService> T findService(Class<T> serviceClass){
|
||||
public <T extends BootService> T findService(Class<T> serviceClass) {
|
||||
return (T)bootedServices.get(serviceClass);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class SamplingService implements BootService {
|
|||
|
||||
private volatile boolean on = false;
|
||||
private volatile int rate = 0;
|
||||
private volatile int rollingSeed = 0;
|
||||
private volatile int rollingSeed = 1;
|
||||
|
||||
@Override
|
||||
public void bootUp() throws Throwable {
|
||||
|
|
@ -39,9 +39,10 @@ public class SamplingService implements BootService {
|
|||
|
||||
public void trySampling(TraceSegment segment) {
|
||||
if (on) {
|
||||
if (rollingSeed++ != rate) {
|
||||
if (rollingSeed % rate != 0) {
|
||||
segment.setSampled(false);
|
||||
}
|
||||
rollingSeed++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +60,7 @@ public class SamplingService implements BootService {
|
|||
if(on) {
|
||||
if (!segment.isSampled() && carrier.isSampled()) {
|
||||
segment.setSampled(true);
|
||||
this.rollingSeed = 0;
|
||||
this.rollingSeed = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package com.a.eye.skywalking.api.sampling;
|
||||
|
||||
import com.a.eye.skywalking.api.boot.ServiceManager;
|
||||
import com.a.eye.skywalking.api.conf.Config;
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author wusheng
|
||||
*/
|
||||
public class SamplingServiceTest {
|
||||
@Test
|
||||
public void test50Percent(){
|
||||
Config.Agent.SAMPLING_RATE = 5000;
|
||||
ServiceManager.INSTANCE.boot();
|
||||
|
||||
TraceSegment segment = new TraceSegment();
|
||||
Assert.assertTrue(segment.isSampled());
|
||||
|
||||
SamplingService service = ServiceManager.INSTANCE.findService(SamplingService.class);
|
||||
service.trySampling(segment);
|
||||
Assert.assertFalse(segment.isSampled());
|
||||
|
||||
segment = new TraceSegment();
|
||||
service.trySampling(segment);
|
||||
Assert.assertTrue(segment.isSampled());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void clear(){
|
||||
Config.Agent.SAMPLING_RATE = 10000;
|
||||
ServiceManager.INSTANCE.boot();
|
||||
}
|
||||
}
|
||||
|
|
@ -50,6 +50,7 @@ public class JedisMethodInterceptor extends NoCocurrencyAceessObject implements
|
|||
Span span = ContextManager.createSpan("Jedis/" + interceptorContext.methodName());
|
||||
Tags.COMPONENT.set(span, REDIS_COMPONENT);
|
||||
Tags.DB_TYPE.set(span, REDIS_COMPONENT);
|
||||
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
|
||||
tagPeer(span, context);
|
||||
Tags.SPAN_LAYER.asDB(span);
|
||||
if (StringUtil.isEmpty(context.get(KEY_OF_REDIS_HOST, String.class))) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue