Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no response logging on async Feign #1450

Merged

Conversation

AWinterman
Copy link
Contributor

@AWinterman AWinterman commented Jun 30, 2021

Copy log level onto asyncBuilder as well as setting it on the builder, so responses get logged in the asynchronous case.

I apologize if this is in the wrong format. You can see a test reproducing the issue below.

I have yet to build the project locally-- I likely won't have time to do that until the morning. The build failure appears to be asking me to add a license header to this file, which I can do but seems unrelated to this issue 🤷

Test Example

import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.common.Slf4jNotifier;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import feign.AsyncFeign;
import feign.Logger.ErrorLogger;
import feign.Logger.Level;
import feign.RequestLine;
import java.util.concurrent.CompletableFuture;
import org.junit.Rule;
import org.junit.Test;


public class FeignPermissionResourceTest {

  public interface ExampleApi {

    @RequestLine("GET /")
    CompletableFuture<String> hello();
  }

  @Rule
  public WireMockRule wireMockRule = new WireMockRule(
      options()
          .dynamicPort()
          .notifier(new Slf4jNotifier(true))
  );

  @Test
  public void testLoggerFailure() {

    final ExampleApi target = AsyncFeign.asyncBuilder()
        .logger(new ErrorLogger())
        .logLevel(Level.FULL)
        .target(ExampleApi.class, wireMockRule.baseUrl());

    var response = WireMock.aResponse()
        .withStatus(200)
        .withHeader("Content-Type", "text/plain")
        .withBody("hello!");

    stubFor(get(anyUrl()).willReturn(response));

    final CompletableFuture<String> hello = target.hello();

    final String responseText = hello.join();
    assertEquals("hello!", responseText);
  }
}

Output on STDERR

[ExampleApi#hello] ---> GET http://localhost:62764/ HTTP/1.1
[ExampleApi#hello] ---> END HTTP (0-byte body)

Process finished with exit code 0

Copy log level onto asyncBuilder as well as setting it on the builder, so responses get logged in the asynchronous case.
@AWinterman AWinterman changed the title Fix no response logging on async Feign. Fix no response logging on async Feign Jul 1, 2021
@velo
Copy link
Member

velo commented Jul 1, 2021

I apologize if this is in the wrong format. You can see a test reproducing the issue below.

just run maven build locally that it will fix the format for you

@AWinterman
Copy link
Contributor Author

I apologize if this is in the wrong format. You can see a test reproducing the issue below.

just run maven build locally that it will fix the format for you

Done.

@velo velo merged commit 83bb55c into OpenFeign:master Jul 1, 2021
@AWinterman
Copy link
Contributor Author

Thanks for merging this so quickly-- will this apply on the 10.X schedule as well as 11?

@AWinterman AWinterman deleted the bug/log-level-not-always-respected branch July 1, 2021 22:10
@velo
Copy link
Member

velo commented Jul 1, 2021

Thanks for merging this so quickly-- will this apply on the 10.X schedule as well as 11?

11 only.

@AWinterman
Copy link
Contributor Author

@velo apologies if this is already well documented, but when might I expect the next release to come out? Thanks!

@velo
Copy link
Member

velo commented Jul 19, 2021

Just created 11.3, will be updating release notes shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants