Mock trace segment data which sniffer from Dubbo framework.
This commit is contained in:
parent
4032e95dce
commit
56d9b2782c
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.collector.agent.grpc.provider.handler.mock;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import org.apache.skywalking.apm.network.proto.SpanLayer;
|
||||
import org.apache.skywalking.apm.network.proto.SpanObject;
|
||||
import org.apache.skywalking.apm.network.proto.SpanType;
|
||||
import org.apache.skywalking.apm.network.proto.TraceSegmentObject;
|
||||
import org.apache.skywalking.apm.network.proto.UniqueId;
|
||||
import org.apache.skywalking.apm.network.proto.UpstreamSegment;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
class ConsumerMock {
|
||||
|
||||
void mock(StreamObserver<UpstreamSegment> segmentStreamObserver, UniqueId.Builder globalTraceId,
|
||||
UniqueId.Builder segmentId, long startTimestamp) {
|
||||
UpstreamSegment.Builder upstreamSegment = UpstreamSegment.newBuilder();
|
||||
upstreamSegment.addGlobalTraceIds(globalTraceId);
|
||||
upstreamSegment.setSegment(createSegment(startTimestamp, segmentId));
|
||||
|
||||
segmentStreamObserver.onNext(upstreamSegment.build());
|
||||
}
|
||||
|
||||
private ByteString createSegment(long startTimestamp, UniqueId.Builder segmentId) {
|
||||
TraceSegmentObject.Builder segment = TraceSegmentObject.newBuilder();
|
||||
segment.setTraceSegmentId(segmentId);
|
||||
segment.setApplicationId(-1);
|
||||
segment.setApplicationInstanceId(2);
|
||||
segment.addSpans(createExitSpan(startTimestamp));
|
||||
segment.addSpans(createEntrySpan(startTimestamp));
|
||||
|
||||
return segment.build().toByteString();
|
||||
}
|
||||
|
||||
private SpanObject.Builder createExitSpan(long startTimestamp) {
|
||||
SpanObject.Builder span = SpanObject.newBuilder();
|
||||
span.setSpanId(1);
|
||||
span.setSpanType(SpanType.Exit);
|
||||
span.setSpanLayer(SpanLayer.RPCFramework);
|
||||
span.setParentSpanId(0);
|
||||
span.setStartTime(startTimestamp + 10);
|
||||
span.setEndTime(startTimestamp + 1990);
|
||||
span.setComponentId(ComponentsDefine.DUBBO.getId());
|
||||
span.setOperationName("org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()");
|
||||
span.setPeer("172.25.0.4:20880");
|
||||
span.setIsError(false);
|
||||
return span;
|
||||
}
|
||||
|
||||
private SpanObject.Builder createEntrySpan(long startTimestamp) {
|
||||
SpanObject.Builder span = SpanObject.newBuilder();
|
||||
span.setSpanId(0);
|
||||
span.setSpanType(SpanType.Entry);
|
||||
span.setSpanLayer(SpanLayer.Http);
|
||||
span.setParentSpanId(-1);
|
||||
span.setStartTime(startTimestamp);
|
||||
span.setEndTime(startTimestamp + 2000);
|
||||
span.setComponentId(ComponentsDefine.TOMCAT.getId());
|
||||
span.setOperationName("/dubbox-case/case/dubbox-rest");
|
||||
span.setIsError(false);
|
||||
return span;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.collector.agent.grpc.provider.handler.mock;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import org.apache.skywalking.apm.network.proto.RefType;
|
||||
import org.apache.skywalking.apm.network.proto.SpanLayer;
|
||||
import org.apache.skywalking.apm.network.proto.SpanObject;
|
||||
import org.apache.skywalking.apm.network.proto.SpanType;
|
||||
import org.apache.skywalking.apm.network.proto.TraceSegmentObject;
|
||||
import org.apache.skywalking.apm.network.proto.TraceSegmentReference;
|
||||
import org.apache.skywalking.apm.network.proto.UniqueId;
|
||||
import org.apache.skywalking.apm.network.proto.UpstreamSegment;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
class ProviderMock {
|
||||
|
||||
void mock(StreamObserver<UpstreamSegment> segmentStreamObserver, UniqueId.Builder globalTraceId,
|
||||
UniqueId.Builder segmentId, UniqueId.Builder parentTraceSegmentId, long startTimestamp) {
|
||||
UpstreamSegment.Builder upstreamSegment = UpstreamSegment.newBuilder();
|
||||
upstreamSegment.addGlobalTraceIds(globalTraceId);
|
||||
upstreamSegment.setSegment(createSegment(startTimestamp, segmentId, parentTraceSegmentId));
|
||||
|
||||
segmentStreamObserver.onNext(upstreamSegment.build());
|
||||
}
|
||||
|
||||
private ByteString createSegment(long startTimestamp, UniqueId.Builder segmentId,
|
||||
UniqueId.Builder parentTraceSegmentId) {
|
||||
TraceSegmentObject.Builder segment = TraceSegmentObject.newBuilder();
|
||||
segment.setTraceSegmentId(segmentId);
|
||||
segment.setApplicationId(2);
|
||||
segment.setApplicationInstanceId(3);
|
||||
segment.addSpans(createExitSpan(startTimestamp));
|
||||
segment.addSpans(createEntrySpan(startTimestamp, parentTraceSegmentId));
|
||||
|
||||
return segment.build().toByteString();
|
||||
}
|
||||
|
||||
private TraceSegmentReference.Builder createReference(UniqueId.Builder parentTraceSegmentId) {
|
||||
TraceSegmentReference.Builder reference = TraceSegmentReference.newBuilder();
|
||||
reference.setParentTraceSegmentId(parentTraceSegmentId);
|
||||
reference.setParentApplicationInstanceId(2);
|
||||
reference.setParentSpanId(1);
|
||||
reference.setParentServiceName("/dubbox-case/case/dubbox-rest");
|
||||
reference.setNetworkAddress("172.25.0.4:20880");
|
||||
reference.setEntryApplicationInstanceId(2);
|
||||
reference.setEntryServiceName("/dubbox-case/case/dubbox-rest");
|
||||
reference.setRefType(RefType.CrossProcess);
|
||||
return reference;
|
||||
}
|
||||
|
||||
private SpanObject.Builder createExitSpan(long startTimestamp) {
|
||||
SpanObject.Builder span = SpanObject.newBuilder();
|
||||
span.setSpanId(1);
|
||||
span.setSpanType(SpanType.Exit);
|
||||
span.setSpanLayer(SpanLayer.Database);
|
||||
span.setParentSpanId(0);
|
||||
span.setStartTime(startTimestamp + 510);
|
||||
span.setEndTime(startTimestamp + 1490);
|
||||
span.setComponentId(ComponentsDefine.MONGODB.getId());
|
||||
span.setOperationName("mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]");
|
||||
span.setPeer("localhost:27017");
|
||||
span.setIsError(false);
|
||||
return span;
|
||||
}
|
||||
|
||||
private SpanObject.Builder createEntrySpan(long startTimestamp, UniqueId.Builder uniqueId) {
|
||||
SpanObject.Builder span = SpanObject.newBuilder();
|
||||
span.setSpanId(0);
|
||||
span.setSpanType(SpanType.Entry);
|
||||
span.setSpanLayer(SpanLayer.RPCFramework);
|
||||
span.setParentSpanId(-1);
|
||||
span.setStartTime(startTimestamp + 500);
|
||||
span.setEndTime(startTimestamp + 1500);
|
||||
span.setComponentId(ComponentsDefine.DUBBO.getId());
|
||||
span.setOperationName("org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()");
|
||||
span.setIsError(false);
|
||||
span.addRefs(createReference(uniqueId));
|
||||
return span;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.collector.agent.grpc.provider.handler.mock;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.joda.time.DateTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public enum TimeBuilder {
|
||||
INSTANCE;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TimeBuilder.class);
|
||||
|
||||
private Duration[] durations = {
|
||||
new Duration("2017-01-01T00:02:01.001", "2017-01-01T00:05:01.001", 2),
|
||||
new Duration("2017-02-01T00:02:01.001", "2017-02-01T00:05:01.001", 2),
|
||||
new Duration("2017-03-01T00:02:01.001", "2017-03-01T00:05:01.001", 2),
|
||||
|
||||
new Duration("2017-04-01T00:02:01.001", "2017-04-01T00:05:01.001", 2),
|
||||
new Duration("2017-04-02T00:03:01.001", "2017-04-02T00:05:01.001", 2),
|
||||
new Duration("2017-04-03T00:02:01.001", "2017-04-03T00:05:01.001", 2),
|
||||
|
||||
new Duration("2017-05-01T08:02:01.001", "2017-05-01T08:05:01.001", 2),
|
||||
new Duration("2017-05-01T09:02:01.001", "2017-05-01T09:05:01.001", 2),
|
||||
new Duration("2017-05-01T10:02:01.001", "2017-05-01T10:05:01.001", 2),
|
||||
|
||||
new Duration("2017-06-01T10:02:01.001", "2017-06-01T10:05:01.001", 20),
|
||||
};
|
||||
|
||||
public Long[] generateTimes() {
|
||||
List<Long> times = new LinkedList<>();
|
||||
|
||||
for (Duration duration : durations) {
|
||||
DateTime start = new DateTime(duration.getStart());
|
||||
DateTime end = new DateTime(duration.getEnd());
|
||||
|
||||
while (!start.isAfter(end)) {
|
||||
for (int i = 0; i < duration.getTps(); i++) {
|
||||
times.add(start.getMillis());
|
||||
}
|
||||
start = start.plusSeconds(1);
|
||||
}
|
||||
}
|
||||
|
||||
return times.toArray(new Long[0]);
|
||||
}
|
||||
|
||||
class Duration {
|
||||
private String start;
|
||||
private String end;
|
||||
private int tps;
|
||||
|
||||
Duration(String start, String end, int tps) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.tps = tps;
|
||||
}
|
||||
|
||||
String getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
String getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
int getTps() {
|
||||
return tps;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Long[] times = TimeBuilder.INSTANCE.generateTimes();
|
||||
|
||||
for (Long time : times) {
|
||||
DateTime dateTime = new DateTime(time);
|
||||
logger.debug("{}-{}-{} {}:{}:{} {}", dateTime.year().getAsText(), dateTime.monthOfYear().getAsString(),
|
||||
dateTime.dayOfMonth().getAsText(), dateTime.hourOfDay().getAsText(),
|
||||
dateTime.minuteOfHour().getAsText(), dateTime.secondOfMinute().getAsText(),
|
||||
dateTime.millisOfSecond().getAsText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.collector.agent.grpc.provider.handler.mock;
|
||||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import org.apache.skywalking.apm.network.proto.Downstream;
|
||||
import org.apache.skywalking.apm.network.proto.TraceSegmentServiceGrpc;
|
||||
import org.apache.skywalking.apm.network.proto.UniqueId;
|
||||
import org.apache.skywalking.apm.network.proto.UpstreamSegment;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class TraceSegmentMock {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TraceSegmentMock.class);
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Sleeping sleeping = new Sleeping();
|
||||
|
||||
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 11800).usePlaintext(true).build();
|
||||
TraceSegmentServiceGrpc.TraceSegmentServiceStub stub = TraceSegmentServiceGrpc.newStub(channel);
|
||||
StreamObserver<UpstreamSegment> segmentStreamObserver = stub.collect(new StreamObserver<Downstream>() {
|
||||
@Override public void onNext(Downstream downstream) {
|
||||
}
|
||||
|
||||
@Override public void onError(Throwable throwable) {
|
||||
}
|
||||
|
||||
@Override public void onCompleted() {
|
||||
sleeping.setValue(Boolean.FALSE);
|
||||
}
|
||||
});
|
||||
|
||||
Long[] times = TimeBuilder.INSTANCE.generateTimes();
|
||||
logger.info("times size: {}", times.length);
|
||||
|
||||
for (int i = 0; i < times.length; i++) {
|
||||
long startTimestamp = times[i];
|
||||
|
||||
UniqueId.Builder globalTraceId = UniqueIdBuilder.INSTANCE.create();
|
||||
|
||||
ConsumerMock consumerMock = new ConsumerMock();
|
||||
UniqueId.Builder consumerSegmentId = UniqueIdBuilder.INSTANCE.create();
|
||||
consumerMock.mock(segmentStreamObserver, globalTraceId, consumerSegmentId, startTimestamp);
|
||||
|
||||
ProviderMock providerMock = new ProviderMock();
|
||||
UniqueId.Builder providerSegmentId = UniqueIdBuilder.INSTANCE.create();
|
||||
providerMock.mock(segmentStreamObserver, globalTraceId, providerSegmentId, consumerSegmentId, startTimestamp);
|
||||
|
||||
if (i % 100 == 0) {
|
||||
logger.info("sending segment number: {}", i);
|
||||
}
|
||||
}
|
||||
logger.info("sending segment number: {}", times.length);
|
||||
|
||||
segmentStreamObserver.onCompleted();
|
||||
|
||||
while (sleeping.getValue()) {
|
||||
Thread.sleep(200);
|
||||
}
|
||||
}
|
||||
|
||||
static class Sleeping {
|
||||
private Boolean value = Boolean.TRUE;
|
||||
|
||||
Boolean getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
void setValue(Boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.collector.agent.grpc.provider.handler.mock;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import org.apache.skywalking.apm.network.proto.UniqueId;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public enum UniqueIdBuilder {
|
||||
INSTANCE;
|
||||
|
||||
private AtomicLong idPart = new AtomicLong(1);
|
||||
|
||||
UniqueId.Builder create() {
|
||||
UniqueId.Builder uniqueId = UniqueId.newBuilder();
|
||||
uniqueId.addIdParts(idPart.getAndIncrement());
|
||||
uniqueId.addIdParts(idPart.getAndIncrement());
|
||||
uniqueId.addIdParts(idPart.getAndIncrement());
|
||||
return uniqueId;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
~ contributor license agreements. See the NOTICE file distributed with
|
||||
~ this work for additional information regarding copyright ownership.
|
||||
~ The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
~ (the "License"); you may not use this file except in compliance with
|
||||
~ the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
~
|
||||
-->
|
||||
|
||||
<Configuration status="debug">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout charset="UTF-8" pattern="%d - %c -%-4r [%t] %-5p %x - %m%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<logger name="org.eclipse.jetty" level="INFO"/>
|
||||
<logger name="org.apache.zookeeper" level="INFO"/>
|
||||
<logger name="org.elasticsearch.common.network.IfConfig" level="INFO"/>
|
||||
<logger name="org.apache.skywalking.apm.collector.agent.grpc.provider.handler.JVMMetricsServiceHandler" level="INFO"/>
|
||||
<logger name="org.apache.skywalking.apm.collector.analysis.worker.timer.PersistenceTimer" level="INFO"/>
|
||||
<logger name="io.grpc.netty" level="INFO"/>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
{
|
||||
"si": 0,
|
||||
"tv": 0,
|
||||
"lv": 2,
|
||||
"lv": 3,
|
||||
"ps": -1,
|
||||
"st": 1501858092409,
|
||||
"et": 1501858097033,
|
||||
|
|
|
|||
Loading…
Reference in New Issue