Repository navigation
Add PactNet.Extensions.Grpc package for grpc plugin support - #548
max-lancaster wants to merge 13 commits into
Conversation
c34af19 to
990939e
Compare
a827783 to
7cbeac4
Compare
d4644b3 to
079935c
Compare
|
Many thanks for the PR - I can see you've put a lot of work into this! I think a good path forward would be to create some kind of framework for plugins to be able to hook into existing PactNet internals without making those internals themselves public. A few examples of where the approach in this PR isn't desireable:
For those reasons and more, I'd prefer to see some kind of framework created, probably as part of To me, success would look like:
I think this is a great step to achieving that, and congratulations to you for this being the first time that we've been able to run plugins in PactNet. It's been a long time coming 😁 |
@adamrodger I rebased this PR on top of PR #551 and made appropriate changes here to demonstrate that this is possible now. With those changes we can now create the new The only changes in this PR that are not in PR #551 are in aba5d3d which only adds the new library and associated tests.
This was achieved in PR #551 for synchronous plugin interactions, I was thinking we could add asynchronous interactions in a separate PR.
I'll leave it up to you how you want to go about doing this but would be willing to chip in if you want to provide some guidance. |
|
@max-lancaster thanks for the effort already put into this. It would really unblock my work integrating Pact with our internal gRPC services. Happy to provide early feedback on usage etc. if needed - feel free to ping me. |
|
@max-lancaster thank you for working on this, from my side also happy to provide early testing |
|
@adamrodger what's required to move forward with this? It looks like a great and substantial change for the ecosystem! |
|
@max-lancaster @mefellows the first stage is getting the other mentioned PR merged so that we can create a generic plugin interface, and then adding a gRPC plugin would be the first to adopt it (and prove that we'd made it appropriately generic hopefully also). I'm having a look at that other PR now though. |
|
Hi @mefellows and @adamrodger, what's the current startus of this? We're currently trying to plan our involvement and how we'd like to continue with gRPC contract tests, would love to get an update if possible |
|
It looks like #551 is in decent shape now, which I think is the crucial change required to support gRPC (and other plugins). Let's see what Adam comes back with. |
This enables creating a nicer API to expose publicly for use by plugin wrappers. See: pact-foundation#492
…ilder Setting the plugin contents completes a synchronous plugin interaction, so WithContent now returns void instead of the same builder. The plugin splits one contents document into the request and its responses itself: a second call would replace the request but append another response, which is why the builder no longer allows it. Provider states stay chainable via Given. Adds unit tests for the plugin request and pact builders and a docs page for the raw plugin API, linked from the README. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
e3c29aa to
3b068c2
Compare
YOU54F
left a comment
There was a problem hiding this comment.
I've been testing this out in a local fork against a few projects, and it is a nice DSL.
I agree that we should split it out into a separate repo, especially with the newly rewritten [avro plugin](https://github.com/hominux/pact-avro-plugin, and others, with the ability to add them into pact-net, hopefully they will grow in numbers.
If we do retain in the same repo, we will have to sort the release workflow out to ensure we can release the packages independently.
I would be happy splitting out into a new repo, my only question is whether we wanted one exclusively per plugin, or if a mono repo with multiple plugin wrappers would allow us to support the community building new plugins and avoid repo sprawl.
Couple of outstanding points to get CI working in the stacked PR.
Would you like to create a repo and then transfer it into Pact-Foundation, or would you like me to create one and invite you in?
| /// <returns>Pact builder</returns> | ||
| public static IGrpcPactBuilderV4 WithGrpcInteractions(this IPactV4 pact, int? port = null, IPAddress host = IPAddress.Loopback) | ||
| { | ||
| var pluginBuilder = pact.WithSynchronousPluginInteractions("protobuf", "0.4.0", transport: "grpc", port, host); |
There was a problem hiding this comment.
I would recommend not hard coding the plugin version here.
If it is null, the framework will use the latest available version from the repository index
https://github.com/pact-foundation/pact-plugins/blob/main/repository/repository.index
I would allow for the user to be able able to optionally set it.
That way we don't need a new release for a new version of the plugin
I think it makes sense for you to create one and invite me if it's long term home is going to be pact foundation @YOU54F |
|
I’ve created https://github.com/pact-foundation/pact-net-extensions let me know how you want to proceed, I am happy to scaff out the repo, and you can fork and contribute the first plugin wrapper, or I can invite you directly as a maintainer. i am easy here, i have some time Following pact-nets structure as a basis, with the ability to support releases of multiple wrappers would probably be the route i would go down but open to ideas |
Yes I think a scaffolded monorepo makes sense for these simple wrapper libraries - that setup will make it easier for future contributors to add new libraries. If you can do that I'll contribute the first library as a PR. I don't really see the need to make me a full maintainer at this time. |
|
no worries chap! I knocked up something together earlier today and did an avro wrapper, the pattern you set worked nicely for enabling plugins for http and async too. I'll get it all pushed up along with changes for pact-net on Monday. i was able to pull along all your commit attribution for the wrapper library so that's all sorted. thanks Max. Happy to rebase from any updated commits, or pick up last tasks on the other pr. |
|
Going to close this off now, as the contributions are now in a sister repository See this #551 (comment) for more detail, on your associated plugin interface pull request Sample grpc project commit: pact-foundation/pact-net-extensions@cd94567 Really appreciate this contribution, and hope we can get #551 landed soon, as once that is in place, we can get the extension library released, and follow up with http and async plugin interfaces |
Stacked on #551. Everything except the last commit belongs to #551 and will drop out of this diff when that PR merges. The remaining commit adds the
PactNet.Extensions.Grpcpackage, which is the reference example of a wrapper library built on the raw plugin API described in docs/plugin-interactions.md.I have read through issue #492 thoroughly and examined the source code and feel that I have a decent understanding of what's involved in adding plugin support, specifically for Grpc. I was able to take @YOU54F's example and create this PR to get some sample Grpc tests working.
I have extracted a
PactNet.Interoppackage as @adamrodger suggested in Issue #492 . This was not a breaking change since all the classes in this namespace were internal,PactNetnow references this new package and none of the pre-existing interface methods have changed. Extracting this package made it possible to create bare-bones Grpc plugin tests and is effectively a very "raw" way of using any plugin. Perhaps a next step would be to wrap the bare-bones methods in a more fluent "raw" interface in a plugin package similar to implementations in other languages as @mefellows suggested.Based on above "raw" tests I was able to refactor and extract shared functionality to create a new
PactNet.Extensions.Grpclibrary that provides a fluent interface similar to the interfaces for http / rest and asynchronous messaging interactions.An alternative approach here would be to just add
<InternalsVisibleTo Include="PactNet.Extensions.Grpc" />to the PactNet.csproj file but this allows integration of other plugins in repos outside this one so it depends on whether you want to explicitly allow that or not.