Open walkerus opened 9 months ago
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"]
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.
Proposal
It would be great to see gRPC requests in the console just like http requests with the '-v' flag
References
No response