PressureMarkTransformFilter extends Filter { @Override public SofaResponse invoke(FilterInvoker invoker, SofaRequest request) throws SofaRpcException { SofaTracerSpan currentSpan = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); boolean loadTest = TracerUtils.isLoadTest(currentSpan); if (loadTest) { Map<String, String> metaHolder = MetadataHolder.getMetaHolder(); metaHolder.put(HEAD_KEY_TRAFFIC_TYPE.name(), PRESSURE); } 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); } } try { return invoker.invoke(request); } finally { MetadataHolder.clear(); } }  @Override SofaResponse invoke(FilterInvoker invoker, SofaRequest request); static final String PRESSURE; static final String MARK; static final String T; }
@Test public void testConsumerPressure() { 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())); }
@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())); }
@Test public void testProviderPressure() { Metadata metadata = new Metadata(); metadata.put(HEAD_KEY_TRAFFIC_TYPE, "pressure"); Context context = Context.current().withValue(TracingContextKey.getKeyMetadata(), metadata); context.attach(); PressureMarkTransformFilter filter = new PressureMarkTransformFilter(); filter.invoke(invoker, request); SofaTracerSpan currentSpan = SofaTraceContextHolder.getSofaTraceContext().getCurrentSpan(); Assert.assertTrue(TracerUtils.isLoadTest(currentSpan)); }
@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)); }