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

verbose console output #38

Open
walkerus opened this issue Jan 4, 2024 · 2 comments
Open

verbose console output #38

walkerus opened this issue Jan 4, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@walkerus
Copy link

walkerus commented Jan 4, 2024

Proposal

It would be great to see gRPC requests in the console just like http requests with the '-v' flag

References

No response

@walkerus walkerus added the enhancement New feature or request label Jan 4, 2024
@fisco-unimatic
Copy link

I can do this in tests, e.g. I can change the config in GrpcAcceptanceTest, adding a notifier:

@RegisterExtension
public static WireMockExtension wm =
    WireMockExtension.newInstance()
        .options(
            wireMockConfig()
                .dynamicPort()
                .withRootDirectory("src/test/resources/wiremock")
                .extensions(new GrpcExtensionFactory())
                .notifier(new ConsoleNotifier(true)))
        .build();

Strangely, I also needed to create a new Wiremock object in the init method, similarly to the test in wiremock-grpc-demos

void init() {
//  wireMock = wm.getRuntimeInfo().getWireMock();
  wireMock = new WireMock(wm.getPort());

I'm using the standalone in a dockerfile, though, and I'd like to set up request logging there. I can't figure out how to do that. My dockerfile is quite simple. I set some options in the entrypoint, but there's no way I can see to add a notifier.

FROM wiremock/wiremock:3.5.4

COPY services /home/wiremock/grpc
COPY mappings /home/wiremock/mappings
COPY extensions /var/wiremock/extensions

ENTRYPOINT ["/docker-entrypoint.sh",  "--global-response-templating", "--disable-gzip", "--verbose"]

@fisco-unimatic
Copy link

I've been hacking around with the source code, and I've got something that works for me. I don't know whether it's the best way to do it, though.

In the GrpcHttpServerFactory. we can pass the configured notifier into the GrpcFilter:
final GrpcFilter grpcFilter = new GrpcFilter(stubRequestHandler, fileDescriptors, options.notifier());

The GrpcFilter stores that as a new field, and then passes it on to the handlers that it builds. (I've only tested this with the UnaryServerCallHandler.)
new UnaryServerCallHandler(stubRequestHandler, serviceDescriptor, methodDescriptor, jsonMessageConverter, notifier));

The handlers also store the notifier as a new field, and then set the it in the LocalNotifier thread-local before invoking stubRequestHandler.handle:

LocalNotifier.set(notifier);
stubRequestHandler.handle(...

I 'll create a pull request if I find time next week.

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

No branches or pull requests

2 participants