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);
}
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()));
}
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));
}
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()));
}
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);
}
Aggregations