Search in sources :

Example 6 with SofaTracerSpan

use of com.alipay.common.tracer.core.span.SofaTracerSpan in project sofa-rpc by sofastack.

the class PressureMarkTransformFilterTest method before.

@Before
public void before() {
    SofaTracerSpan span = (SofaTracerSpan) tracer.buildSpan("test").start();
    SofaTraceContextHolder.getSofaTraceContext().push(span);
}
Also used : SofaTracerSpan(com.alipay.common.tracer.core.span.SofaTracerSpan) Before(org.junit.Before)

Example 7 with SofaTracerSpan

use of com.alipay.common.tracer.core.span.SofaTracerSpan in project sofa-rpc by sofastack.

the class PressureMarkTransformFilterTest method testConsumerPressure.

@Test
public void testConsumerPressure() {
    // consumer side
    SofaTracerSpan currentSpan = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan();
    Map<String, String> bizBaggage = currentSpan.getSofaTracerSpanContext().getBizBaggage();
    bizBaggage.put("mark", "T");
    Assert.assertTrue(TracerUtils.isLoadTest(currentSpan));
    PressureMarkTransformFilter filter = new PressureMarkTransformFilter();
    filter.invoke(invoker, request);
    Assert.assertEquals(PRESSURE, invoker.getMetaHolder().get(HEAD_KEY_TRAFFIC_TYPE.name()));
}
Also used : SofaTracerSpan(com.alipay.common.tracer.core.span.SofaTracerSpan) Test(org.junit.Test)

Example 8 with SofaTracerSpan

use of com.alipay.common.tracer.core.span.SofaTracerSpan in project sofa-rpc by sofastack.

the class PressureMarkTransformFilterTest method testNoProviderPressure.

@Test
public void testNoProviderPressure() {
    Metadata metadata = new Metadata();
    Context context = Context.current().withValue(TracingContextKey.getKeyMetadata(), metadata);
    context.attach();
    PressureMarkTransformFilter filter = new PressureMarkTransformFilter();
    filter.invoke(invoker, request);
    SofaTracerSpan currentSpan = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan();
    Assert.assertFalse(TracerUtils.isLoadTest(currentSpan));
}
Also used : Context(io.grpc.Context) RpcInvokeContext(com.alipay.sofa.rpc.context.RpcInvokeContext) SofaTracerSpan(com.alipay.common.tracer.core.span.SofaTracerSpan) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 9 with SofaTracerSpan

use of com.alipay.common.tracer.core.span.SofaTracerSpan in project sofa-rpc by sofastack.

the class PressureMarkTransformFilterTest method testNoConsumerPressure.

@Test
public void testNoConsumerPressure() {
    SofaTracerSpan currentSpan = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan();
    Assert.assertFalse(TracerUtils.isLoadTest(currentSpan));
    PressureMarkTransformFilter filter = new PressureMarkTransformFilter();
    filter.invoke(invoker, request);
    Assert.assertNull(invoker.getMetaHolder().get(HEAD_KEY_TRAFFIC_TYPE.name()));
}
Also used : SofaTracerSpan(com.alipay.common.tracer.core.span.SofaTracerSpan) Test(org.junit.Test)

Example 10 with SofaTracerSpan

use of com.alipay.common.tracer.core.span.SofaTracerSpan in project sofa-rpc by sofastack.

the class PressureMarkTransformFilter method invoke.

@Override
public SofaResponse invoke(FilterInvoker invoker, SofaRequest request) throws SofaRpcException {
    // consumer side, if in provider side,loadTest always false
    SofaTracerSpan currentSpan = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan();
    boolean loadTest = TracerUtils.isLoadTest(currentSpan);
    if (loadTest) {
        RpcInvokeContext.getContext().addCustomHeader(HEAD_KEY_TRAFFIC_TYPE.name(), PRESSURE);
    }
    // provider side ,if in consumer side, metadata == null
    Metadata metadata = TracingContextKey.getKeyMetadata().get();
    if (metadata != null) {
        String s = metadata.get(HEAD_KEY_TRAFFIC_TYPE);
        if (PRESSURE.equals(s)) {
            currentSpan.getSofaTracerSpanContext().setBizBaggageItem(MARK, T);
        }
    }
    return invoker.invoke(request);
}
Also used : SofaTracerSpan(com.alipay.common.tracer.core.span.SofaTracerSpan) Metadata(io.grpc.Metadata)

Aggregations

SofaTracerSpan (com.alipay.common.tracer.core.span.SofaTracerSpan)35 SofaTraceContext (com.alipay.common.tracer.core.context.trace.SofaTraceContext)25 RpcInternalContext (com.alipay.sofa.rpc.context.RpcInternalContext)12 Test (org.junit.Test)12 SofaTracerSpanContext (com.alipay.common.tracer.core.context.span.SofaTracerSpanContext)6 RpcInvokeContext (com.alipay.sofa.rpc.context.RpcInvokeContext)6 HashMap (java.util.HashMap)6 Metadata (io.grpc.Metadata)4 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)3 Context (io.grpc.Context)3 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)2 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)2 SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)2 FlexibleTracer (com.alipay.sofa.tracer.plugin.flexible.FlexibleTracer)2 InetSocketAddress (java.net.InetSocketAddress)2 Before (org.junit.Before)2 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)1 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)1 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)1