Search in sources :

Example 86 with Span

use of com.nike.wingtips.Span in project riposte by Nike-Inc.

the class VerifyProxyRouterTracingBehaviorComponentTest method proxy_endpoint_tracing_behavior_should_work_as_desired_when_orig_request_does_not_have_tracing_headers.

@DataProvider(value = { "HEADERS_ON_SUBSPAN_ON", "HEADERS_OFF_SUBSPAN_ON", "HEADERS_ON_SUBSPAN_OFF", "HEADERS_OFF_SUBSPAN_OFF" })
@Test
public void proxy_endpoint_tracing_behavior_should_work_as_desired_when_orig_request_does_not_have_tracing_headers(TracingBehaviorScenario scenario) {
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(proxyServerConfig.endpointsPort()).basePath(RouterEndpoint.MATCHING_PATH).header(SET_TRACING_HEADERS_HEADER_KEY, scenario.tracingHeadersOn).header(PERFORM_SUBSPAN_HEADER_KEY, scenario.subspanOn).log().all().when().get().then().log().headers().extract();
    assertThat(response.statusCode()).isEqualTo(200);
    assertThat(response.asString()).isEqualTo(DownstreamEndpoint.RESPONSE_PAYLOAD);
    // Verify that the proxy honored the subspan option, and get a handle on the span that surrounded the proxy
    // downstream call.
    Span spanForDownstreamCall = verifyCompletedSpansAndReturnSpanForDownstreamCall(scenario.subspanOn);
    if (scenario.tracingHeadersOn) {
        // The downstream endpoint should have received tracing headers based on the span surrounding the proxy
        // downstream call.
        verifyExpectedTracingHeadersReceivedDownstream(response, spanForDownstreamCall);
    } else {
        // Proxy had the "set tracing headers" option off, and we didn't send any in our original request, so
        // the downstream endpoint should not have received *any* tracing headers.
        verifyExpectedTracingHeadersReceivedDownstream(response, null, null, null, null);
    }
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Span(com.nike.wingtips.Span) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 87 with Span

use of com.nike.wingtips.Span in project riposte by Nike-Inc.

the class DefaultRiposteProxyRouterSpanNamingAndTaggingStrategyTest method doChangeSpanName_changes_span_name_as_expected.

@DataProvider(value = { "null           |   false", "               |   false", "[whitespace]   |   false", "fooNewName     |   true" }, splitBy = "\\|")
@Test
public void doChangeSpanName_changes_span_name_as_expected(String newName, boolean expectNameToBeChanged) {
    // given
    if ("[whitespace]".equals(newName)) {
        newName = "  \r\n\t  ";
    }
    String initialSpanName = UUID.randomUUID().toString();
    Span span = Span.newBuilder(initialSpanName, Span.SpanPurpose.CLIENT).build();
    String expectedSpanName = (expectNameToBeChanged) ? newName : initialSpanName;
    // when
    impl.doChangeSpanName(span, newName);
    // then
    assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Span(com.nike.wingtips.Span) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 88 with Span

use of com.nike.wingtips.Span in project riposte by Nike-Inc.

the class DefaultRiposteProxyRouterSpanNamingAndTaggingStrategyTest method doHandleResponseTaggingAndFinalSpanName_delegates_to_wingtips_strategy_but_reverts_span_name_if_necessary.

@DataProvider(value = { "REVERT_SCENARIO_WITH_PREFIX", "REVERT_SCENARIO_NO_PREFIX", "REQUEST_IS_NULL", "SPAN_NAME_FROM_STRATEGY_MATCHES_ORIG_SPAN_NAME", "SPAN_NAME_FROM_STRATEGY_IS_NOT_BASIC_SPAN_NAME", "ORIG_SPAN_NAME_IS_BLANK" })
@Test
public void doHandleResponseTaggingAndFinalSpanName_delegates_to_wingtips_strategy_but_reverts_span_name_if_necessary(FinalSpanNameScenario scenario) {
    // given
    DefaultRiposteProxyRouterSpanNamingAndTaggingStrategy implSpy = spy(impl);
    doAnswer(new Answer() {

        int invocationCount = 0;

        @Override
        public Object answer(InvocationOnMock invocation) {
            if (invocationCount == 0) {
                invocationCount++;
                return scenario.origSpanName;
            }
            return scenario.finalNameFromStrategy;
        }
    }).when(spanMock).getSpanName();
    doReturn(scenario.httpMethod).when(requestMock).method();
    HttpRequest requestToUse = (scenario.requestIsNull) ? null : requestMock;
    // when
    implSpy.doHandleResponseTaggingAndFinalSpanName(spanMock, requestToUse, responseMock, errorMock);
    // then
    // The strategy should always be called.
    strategyResponseTaggingArgs.get().verifyArgs(spanMock, requestToUse, responseMock, errorMock, wingtipsAdapterMock);
    // The span name may or may not have been reverted back to the original span name, though.
    if (scenario.expectSpanNameReversion) {
        verify(implSpy).doChangeSpanName(spanMock, scenario.origSpanName);
    } else {
        verify(implSpy, never()).doChangeSpanName(any(Span.class), anyString());
    }
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Span(com.nike.wingtips.Span) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 89 with Span

use of com.nike.wingtips.Span in project riposte by Nike-Inc.

the class ChannelPipelineFinalizerHandlerTest method doChannelInactive_does_what_it_can_when_the_RequestInfo_or_ResponseInfo_is_null.

@DataProvider(value = { "true   |   false", "false  |   true", "true   |   true" }, splitBy = "\\|")
@Test
public void doChannelInactive_does_what_it_can_when_the_RequestInfo_or_ResponseInfo_is_null(boolean requestInfoIsNull, boolean responseInfoIsNull) throws Exception {
    // given
    Span span = setupTracingForChannelInactive(false);
    if (requestInfoIsNull)
        state.setRequestInfo(null);
    if (responseInfoIsNull)
        state.setResponseInfo(null, null);
    // when
    PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
    // then
    Assertions.assertThat(span.isCompleted()).isTrue();
    Assertions.assertThat(state.isTraceCompletedOrScheduled()).isTrue();
    if (requestInfoIsNull)
        verifyNoInteractions(requestInfoMock);
    else
        verify(requestInfoMock).releaseAllResources();
    verify(proxyRouterStateMock).cancelRequestStreaming(any(), any());
    verify(proxyRouterStateMock).cancelDownstreamRequest(any());
    Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Span(com.nike.wingtips.Span) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 90 with Span

use of com.nike.wingtips.Span in project riposte by Nike-Inc.

the class ChannelPipelineFinalizerHandlerTest method doChannelInactive_does_what_it_can_when_the_HttpProcessingState_or_ProxyRouterProcessingState_is_null.

@DataProvider(value = { "true   |   false", "false  |   true", "true   |   true" }, splitBy = "\\|")
@Test
public void doChannelInactive_does_what_it_can_when_the_HttpProcessingState_or_ProxyRouterProcessingState_is_null(boolean httpStateIsNull, boolean proxyRouterStateIsNull) throws Exception {
    // given
    if (httpStateIsNull)
        doReturn(null).when(stateAttributeMock).get();
    if (proxyRouterStateIsNull)
        doReturn(null).when(proxyRouterProcessingStateAttributeMock).get();
    Span span = setupTracingForChannelInactive(false);
    // when
    PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
    // then
    if (httpStateIsNull)
        Assertions.assertThat(span.isCompleted()).isFalse();
    else
        Assertions.assertThat(span.isCompleted()).isTrue();
    if (httpStateIsNull)
        verifyNoInteractions(requestInfoMock);
    else
        verify(requestInfoMock).releaseAllResources();
    if (proxyRouterStateIsNull)
        verifyNoInteractions(proxyRouterStateMock);
    else {
        verify(proxyRouterStateMock).cancelRequestStreaming(any(), any());
        verify(proxyRouterStateMock).cancelDownstreamRequest(any());
    }
    Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Span(com.nike.wingtips.Span) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

Span (com.nike.wingtips.Span)103 Test (org.junit.Test)73 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)41 Map (java.util.Map)26 Deque (java.util.Deque)24 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)20 CompletableFuture (java.util.concurrent.CompletableFuture)18 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 HashMap (java.util.HashMap)10 HttpRequest (io.netty.handler.codec.http.HttpRequest)9 Before (org.junit.Before)9 RequestInfo (com.nike.riposte.server.http.RequestInfo)8 Tracer (com.nike.wingtips.Tracer)8 HttpTagAndSpanNamingAdapter (com.nike.wingtips.tags.HttpTagAndSpanNamingAdapter)7 ChannelFuture (io.netty.channel.ChannelFuture)7 ChannelHandler (io.netty.channel.ChannelHandler)7 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)7 HttpResponse (io.netty.handler.codec.http.HttpResponse)7 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)7