修复部分问题

This commit is contained in:
ascrutae 2016-12-04 16:16:07 +08:00
parent 6fd3ce2d3f
commit 5b9b7abeb7
8 changed files with 36 additions and 44 deletions

View File

@ -9,8 +9,8 @@ import io.grpc.ManagedChannelBuilder;
public class Client {
private ManagedChannel channel;
public Client(String ip, int address) {
channel = ManagedChannelBuilder.forAddress(ip, address).usePlaintext(true).build();
public Client(String ip, int port) {
channel = ManagedChannelBuilder.forAddress(ip, port).usePlaintext(true).build();
}
public SpanStorageClient newSpanStorageClient(StorageClientListener listener) {

View File

@ -14,7 +14,7 @@ message AckSpan {
string userId = 8;
string applicationId = 9;
int64 routeKey = 10;
int32 routeKey = 10;
}
message RequestSpan {
@ -32,7 +32,7 @@ message RequestSpan {
int32 processNo = 13;
string address = 14;
int64 routeKey = 15;
int32 routeKey = 15;
}
message TraceId{

View File

@ -67,7 +67,7 @@ public class Span {
*/
private String userId;
private String viewPointId;
private long routeKey;
private int routeKey;
public Span(TraceId traceId, String applicationId, String userId) {
this.traceId = traceId;
@ -210,11 +210,11 @@ public class Span {
return builder;
}
public void setRouteKey(long routeKey) {
public void setRouteKey(int routeKey) {
this.routeKey = routeKey;
}
public long getRouteKey() {
public int getRouteKey() {
return routeKey;
}
}

View File

@ -1,8 +1,8 @@
package com.a.eye.skywalking.util;
import com.a.eye.skywalking.conf.Config;
import com.a.eye.skywalking.model.ContextData;
import com.a.eye.skywalking.context.CurrentThreadSpanStack;
import com.a.eye.skywalking.model.ContextData;
import com.a.eye.skywalking.model.Identification;
import com.a.eye.skywalking.model.Span;
@ -27,9 +27,9 @@ public final class ContextGenerator {
*/
public static Span generateSpanFromContextData(ContextData context, Identification id) {
Span spanData = CurrentThreadSpanStack.peek();
if (context != null && context.getTraceId() != null && spanData == null){
if (context != null && context.getTraceId() != null && spanData == null) {
spanData = new Span(context.getTraceId(), context.getParentLevel(), context.getLevelId(), Config.SkyWalking.APPLICATION_CODE, Config.SkyWalking.USER_ID);
}else{
} else {
spanData = getSpanFromThreadLocal(id);
}
@ -41,11 +41,11 @@ public final class ContextGenerator {
// 1.获取Context从ThreadLocal栈中获取中
final Span parentSpan = CurrentThreadSpanStack.peek();
// 2 校验ContextContext是否存在
long routeKey = 0;
int routeKey;
if (parentSpan == null) {
// 不存在新创建一个Context
span = new Span(TraceIdGenerator.generate(), Config.SkyWalking.APPLICATION_CODE, Config.SkyWalking.USER_ID);
routeKey = TokenGenerator.generate(id.getViewPoint());
routeKey = RoutingKeyGenerator.generate(id.getViewPoint());
} else {
// 根据ParentContextData的TraceId和RPCID

View File

@ -0,0 +1,20 @@
package com.a.eye.skywalking.util;
/**
* Created data xin on 2016/12/4.
*/
public class RoutingKeyGenerator {
public static int generate(String originData) {
char[] value = originData.toCharArray();
int h = 0;
if (h == 0 && value.length > 0) {
char val[] = value;
for (int i = 0; i < value.length; i++) {
h = 31 * h + val[i];
}
}
return h;
}
}

View File

@ -1,28 +0,0 @@
package com.a.eye.skywalking.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* Created data xin on 2016/12/4.
*/
public class TokenGenerator {
public static long generate(String originData) {
long value = 0;
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(originData.getBytes());
byte[] data = messageDigest.digest();
//
for (int i = 0; i < data.length; i++) {
value = (value << 8) + (data[i] & 0xff);
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return value;
}
}

View File

@ -47,7 +47,7 @@ public class StorageClientCachePool {
spanStorageClientPool.put(connectionURL, client.newSpanStorageClient(listener));
traceSearchClientPool.put(connectionURL, client.newTraceSearchClient());
}
return spanStorageClient;
return spanStorageClientPool.get(connectionURL);
} finally {
lock.unlock();
}

View File

@ -37,9 +37,9 @@ public class RouteSendRequestSpanEventHandler extends AbstractRouteSpanEventHand
if (stop) {
try {
for (RequestSpan ackSpan : buffer) {
SpanDisruptor spanDisruptor = RoutingService.getRouter().lookup(ackSpan);
spanDisruptor.saveSpan(ackSpan);
for (RequestSpan requestSpan : buffer) {
SpanDisruptor spanDisruptor = RoutingService.getRouter().lookup(requestSpan);
spanDisruptor.saveSpan(requestSpan);
}
} finally {
buffer.clear();