Search in sources :

Example 1 with UpstreamSegment

use of org.apache.skywalking.apm.network.proto.UpstreamSegment in project incubator-skywalking by apache.

the class GRPCNoServerTest method main.

public static void main(String[] args) throws InterruptedException {
    ManagedChannelBuilder<?> channelBuilder = NettyChannelBuilder.forAddress("127.0.0.1", 8080).nameResolverFactory(new DnsNameResolverProvider()).maxInboundMessageSize(1024 * 1024 * 50).usePlaintext(true);
    ManagedChannel channel = channelBuilder.build();
    TraceSegmentServiceGrpc.TraceSegmentServiceStub serviceStub = TraceSegmentServiceGrpc.newStub(channel);
    final Status[] status = { null };
    StreamObserver<UpstreamSegment> streamObserver = serviceStub.collect(new StreamObserver<Downstream>() {

        @Override
        public void onNext(Downstream value) {
        }

        @Override
        public void onError(Throwable t) {
            status[0] = ((StatusRuntimeException) t).getStatus();
        }

        @Override
        public void onCompleted() {
        }
    });
    streamObserver.onNext(null);
    streamObserver.onCompleted();
    Thread.sleep(2 * 1000);
    Assert.assertEquals(status[0].getCode(), Status.UNAVAILABLE.getCode());
}
Also used : Status(io.grpc.Status) UpstreamSegment(org.apache.skywalking.apm.network.proto.UpstreamSegment) TraceSegmentServiceGrpc(org.apache.skywalking.apm.network.proto.TraceSegmentServiceGrpc) DnsNameResolverProvider(io.grpc.internal.DnsNameResolverProvider) StatusRuntimeException(io.grpc.StatusRuntimeException) ManagedChannel(io.grpc.ManagedChannel) Downstream(org.apache.skywalking.apm.network.proto.Downstream)

Example 2 with UpstreamSegment

use of org.apache.skywalking.apm.network.proto.UpstreamSegment in project incubator-skywalking by apache.

the class TraceSegmentServiceClientTest method testSendTraceSegmentWithoutException.

@Test
public void testSendTraceSegmentWithoutException() throws InvalidProtocolBufferException {
    grpcServerRule.getServiceRegistry().addService(serviceImplBase);
    AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", null);
    firstEntrySpan.setComponent(ComponentsDefine.TOMCAT);
    Tags.HTTP.METHOD.set(firstEntrySpan, "GET");
    Tags.URL.set(firstEntrySpan, "127.0.0.1:8080");
    SpanLayer.asHttp(firstEntrySpan);
    ContextManager.stopSpan();
    serviceClient.consume(storage.getTraceSegments());
    assertThat(upstreamSegments.size(), is(1));
    UpstreamSegment upstreamSegment = upstreamSegments.get(0);
    assertThat(upstreamSegment.getGlobalTraceIdsCount(), is(1));
    TraceSegmentObject traceSegmentObject = TraceSegmentObject.parseFrom(upstreamSegment.getSegment());
    assertThat(traceSegmentObject.getSpans(0).getRefsCount(), is(0));
    assertThat(traceSegmentObject.getSpansCount(), is(1));
    SpanObject spanObject = traceSegmentObject.getSpans(0);
    assertThat(spanObject.getSpanType(), is(SpanType.Entry));
    assertThat(spanObject.getSpanId(), is(0));
    assertThat(spanObject.getParentSpanId(), is(-1));
}
Also used : UpstreamSegment(org.apache.skywalking.apm.network.proto.UpstreamSegment) TraceSegmentObject(org.apache.skywalking.apm.network.proto.TraceSegmentObject) SpanObject(org.apache.skywalking.apm.network.proto.SpanObject) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 3 with UpstreamSegment

use of org.apache.skywalking.apm.network.proto.UpstreamSegment in project incubator-skywalking by apache.

the class TraceSegment method transform.

/**
 * This is a high CPU cost method, only called when sending to collector or test cases.
 *
 * @return the segment as GRPC service parameter
 */
public UpstreamSegment transform() {
    UpstreamSegment.Builder upstreamBuilder = UpstreamSegment.newBuilder();
    for (DistributedTraceId distributedTraceId : getRelatedGlobalTraces()) {
        upstreamBuilder = upstreamBuilder.addGlobalTraceIds(distributedTraceId.toUniqueId());
    }
    TraceSegmentObject.Builder traceSegmentBuilder = TraceSegmentObject.newBuilder();
    /**
     * Trace Segment
     */
    traceSegmentBuilder.setTraceSegmentId(this.traceSegmentId.transform());
    // SpanObject
    for (AbstractTracingSpan span : this.spans) {
        traceSegmentBuilder.addSpans(span.transform());
    }
    traceSegmentBuilder.setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID);
    traceSegmentBuilder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID);
    traceSegmentBuilder.setIsSizeLimited(this.isSizeLimited);
    upstreamBuilder.setSegment(traceSegmentBuilder.build().toByteString());
    return upstreamBuilder.build();
}
Also used : DistributedTraceId(org.apache.skywalking.apm.agent.core.context.ids.DistributedTraceId) NewDistributedTraceId(org.apache.skywalking.apm.agent.core.context.ids.NewDistributedTraceId) UpstreamSegment(org.apache.skywalking.apm.network.proto.UpstreamSegment) TraceSegmentObject(org.apache.skywalking.apm.network.proto.TraceSegmentObject)

Example 4 with UpstreamSegment

use of org.apache.skywalking.apm.network.proto.UpstreamSegment in project incubator-skywalking by apache.

the class TraceSegmentServiceClient method consume.

@Override
public void consume(List<TraceSegment> data) {
    if (CONNECTED.equals(status)) {
        final GRPCStreamServiceStatus status = new GRPCStreamServiceStatus(false);
        StreamObserver<UpstreamSegment> upstreamSegmentStreamObserver = serviceStub.collect(new StreamObserver<Downstream>() {

            @Override
            public void onNext(Downstream downstream) {
            }

            @Override
            public void onError(Throwable throwable) {
                status.finished();
                if (logger.isErrorEnable()) {
                    logger.error(throwable, "Send UpstreamSegment to collector fail with a grpc internal exception.");
                }
                ServiceManager.INSTANCE.findService(GRPCChannelManager.class).reportError(throwable);
            }

            @Override
            public void onCompleted() {
                status.finished();
            }
        });
        for (TraceSegment segment : data) {
            try {
                UpstreamSegment upstreamSegment = segment.transform();
                upstreamSegmentStreamObserver.onNext(upstreamSegment);
            } catch (Throwable t) {
                logger.error(t, "Transform and send UpstreamSegment to collector fail.");
            }
        }
        upstreamSegmentStreamObserver.onCompleted();
        if (status.wait4Finish(TIMEOUT)) {
            segmentUplinkedCounter += data.size();
        }
    } else {
        segmentAbandonedCounter += data.size();
    }
    printUplinkStatus();
}
Also used : UpstreamSegment(org.apache.skywalking.apm.network.proto.UpstreamSegment) Downstream(org.apache.skywalking.apm.network.proto.Downstream) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)

Example 5 with UpstreamSegment

use of org.apache.skywalking.apm.network.proto.UpstreamSegment in project incubator-skywalking by apache.

the class ContextManagerTest method testTransform.

@Test
public void testTransform() throws InvalidProtocolBufferException {
    ContextCarrier contextCarrier = new ContextCarrier().deserialize("1.234.1983829|3|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|1.2343.234234234");
    assertTrue(contextCarrier.isValid());
    AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", contextCarrier);
    firstEntrySpan.setComponent(ComponentsDefine.TOMCAT);
    Tags.HTTP.METHOD.set(firstEntrySpan, "GET");
    Tags.URL.set(firstEntrySpan, "127.0.0.1:8080");
    SpanLayer.asHttp(firstEntrySpan);
    AbstractSpan secondEntrySpan = ContextManager.createEntrySpan("/testSecondEntry", contextCarrier);
    secondEntrySpan.setComponent(ComponentsDefine.DUBBO);
    Tags.URL.set(firstEntrySpan, "dubbo://127.0.0.1:8080");
    SpanLayer.asRPCFramework(secondEntrySpan);
    ContextCarrier injectContextCarrier = new ContextCarrier();
    AbstractSpan exitSpan = ContextManager.createExitSpan("/textExitSpan", injectContextCarrier, "127.0.0.1:12800");
    exitSpan.errorOccurred();
    exitSpan.log(new RuntimeException("exception"));
    exitSpan.setComponent(ComponentsDefine.HTTPCLIENT);
    SpanLayer.asHttp(exitSpan);
    ContextManager.stopSpan();
    ContextManager.stopSpan();
    ContextManager.stopSpan();
    TraceSegment actualSegment = tracingData.getTraceSegments().get(0);
    UpstreamSegment upstreamSegment = actualSegment.transform();
    assertThat(upstreamSegment.getGlobalTraceIdsCount(), is(1));
    TraceSegmentObject traceSegmentObject = TraceSegmentObject.parseFrom(upstreamSegment.getSegment());
    TraceSegmentReference reference = traceSegmentObject.getSpans(1).getRefs(0);
    assertThat(reference.getEntryServiceName(), is("/portal/"));
    assertThat(reference.getNetworkAddress(), is("127.0.0.1:8080"));
    assertThat(reference.getParentSpanId(), is(3));
    assertThat(traceSegmentObject.getApplicationId(), is(1));
    assertThat(traceSegmentObject.getSpans(1).getRefsCount(), is(1));
    assertThat(traceSegmentObject.getSpansCount(), is(2));
    SpanObject actualSpan = traceSegmentObject.getSpans(1);
    assertThat(actualSpan.getComponentId(), is(3));
    assertThat(actualSpan.getComponent(), is(""));
    assertThat(actualSpan.getOperationName(), is("/testSecondEntry"));
    assertThat(actualSpan.getParentSpanId(), is(-1));
    assertThat(actualSpan.getSpanId(), is(0));
    assertThat(actualSpan.getSpanType(), is(SpanType.Entry));
    SpanObject exitSpanObject = traceSegmentObject.getSpans(0);
    assertThat(exitSpanObject.getComponentId(), is(2));
    assertThat(exitSpanObject.getComponent(), is(""));
    assertThat(exitSpanObject.getSpanType(), is(SpanType.Exit));
    assertThat(exitSpanObject.getOperationName(), is("/textExitSpan"));
    assertThat(exitSpanObject.getParentSpanId(), is(0));
    assertThat(exitSpanObject.getSpanId(), is(1));
    assertThat(exitSpanObject.getLogsCount(), is(1));
    LogMessage logMessage = exitSpanObject.getLogs(0);
    assertThat(logMessage.getDataCount(), is(4));
    List<KeyWithStringValue> values = logMessage.getDataList();
    assertThat(values.get(0).getValue(), is("error"));
    assertThat(values.get(1).getValue(), is(RuntimeException.class.getName()));
    assertThat(values.get(2).getValue(), is("exception"));
    assertTrue(values.get(2).getValue().length() <= 4000);
}
Also used : UpstreamSegment(org.apache.skywalking.apm.network.proto.UpstreamSegment) LogMessage(org.apache.skywalking.apm.network.proto.LogMessage) KeyWithStringValue(org.apache.skywalking.apm.network.proto.KeyWithStringValue) TraceSegmentObject(org.apache.skywalking.apm.network.proto.TraceSegmentObject) TraceSegmentReference(org.apache.skywalking.apm.network.proto.TraceSegmentReference) SpanObject(org.apache.skywalking.apm.network.proto.SpanObject) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Aggregations

UpstreamSegment (org.apache.skywalking.apm.network.proto.UpstreamSegment)5 TraceSegmentObject (org.apache.skywalking.apm.network.proto.TraceSegmentObject)3 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)2 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)2 Downstream (org.apache.skywalking.apm.network.proto.Downstream)2 SpanObject (org.apache.skywalking.apm.network.proto.SpanObject)2 ManagedChannel (io.grpc.ManagedChannel)1 Status (io.grpc.Status)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 DnsNameResolverProvider (io.grpc.internal.DnsNameResolverProvider)1 DistributedTraceId (org.apache.skywalking.apm.agent.core.context.ids.DistributedTraceId)1 NewDistributedTraceId (org.apache.skywalking.apm.agent.core.context.ids.NewDistributedTraceId)1 KeyWithStringValue (org.apache.skywalking.apm.network.proto.KeyWithStringValue)1 LogMessage (org.apache.skywalking.apm.network.proto.LogMessage)1 TraceSegmentReference (org.apache.skywalking.apm.network.proto.TraceSegmentReference)1 TraceSegmentServiceGrpc (org.apache.skywalking.apm.network.proto.TraceSegmentServiceGrpc)1