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

Implement protocol plugin and rpcv2 protocol #264

Merged
merged 75 commits into from
Feb 22, 2025
Merged

Conversation

jterapin
Copy link
Contributor

@jterapin jterapin commented Feb 3, 2025

Description

This PR aims to provide the following features:

  • Ability to swap protocol for another protocol.
  • Resolve for default protocol based on what welds are applied
  • Allow customers to pass in their preferred protocol configurations if they choose to

Differences between current state of V3 and smithy-ruby:

  • There is a default protocol plugin that is codegenerated for every client gem generation
  • A new configuration, protocol on the client
  • Protocols are no longer their own individual plugins with handlers
  • ContentTypePlugin in V3 is no longer needed - moved all the logic to build_request method.

Customer Experience

Customer already has a default protocol defined on client creation:

client = Service::Client.new
client.config.protocol
=> Smithy::Client::Protocols::RPCV2.... 

Customer could overwrite the default protocol:

# custom protocol with preferred settings
custom_protocol = Smithy::Client::Protocols::CustomRPCV2.new(query_compatible: true)

# sets the custom protocol as active protocol
client = Service::Client.new(protocol: custom_protocol)
client.config.protocol
=> Smithy::Client::Protocols::CustomRPCV2.... 

Future TODOs:

  • Updating RPCV2 protocol
    • Handle eventstreams
    • Handle error handling
    • Remove Content-Length header once Content-Length Plugin/handler is implemented
  • Make any changes once Welds are updated to handle ordering
  • Add tests to validate weld ordering

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Contributor Author

@jterapin jterapin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea of codegenerated protocol plugin so may be scrapped.

I liked the idea in the beginning but there's some limitations that I need to think through and makes me lean toward V3 implementation for protocols. Open to thoughts!

@jterapin jterapin changed the title [WIP] Add protocol base and rpcv2 protocol [WIP] Implement protocol plugin and rpcv2 protocol Feb 6, 2025
Copy link
Contributor

@alextwoods alextwoods left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looking good - I like the weld based mapping of service traits to ruby protocol implementations.

Copy link
Contributor

@mullermp mullermp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can discuss offline later.

@@ -198,6 +211,7 @@ class StructureShape < Shape
def initialize(options = {})
super
@members = {}
@members_by_name = {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically - any shapes that involves members - we want to retain their member names to reference for (de)serialization process. (AKA the location_name in Shape ref)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea. I think we should choose a different name though..

# @return [Boolean]
def member?(name)
@members.key?(name)
@members.key?(name) || @members_by_name.key?(name)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want flexibility to check members existence whether by the symbolized member name (:city_id) vs the member name defined on the shape (cityName). I also did this for member(name) method

nil
else
format_data(value, shape.value.shape)
end
end
end

def format_structure(values, shape)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to implement the (de)serialization of union shapes in a separate PR since I have some questions before implementing. Will be a small follow-up PR most likely.

# @api private
class Error < Smithy::Client::Handler
def call(context)
@handler.call(context).on(300..599) do |response|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately s3 has errors at 200 level, so this may need to be 0..599 or some way to control/customize this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense - we should do some brainstorm work when we start looking into error handling.

# This configuration is required to build requests and parse responses.
# In Smithy, a protocol is a named set of rules that defines the syntax
# and semantics of how a client and server communicate. The given protocol
# must provide the following functionalities: `build`, `parse` and `error`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to reword this to "should respond to build(context), parse(context) etc"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make the changes in a separate PR.

module Smithy
module Welds
# Provides map of protocol trait id and its Ruby class name.
# TODO: Update Welds to have a functionality to control ordering since there
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can add another method (later) for protocol ordering, and in aws-sdk-core, we have a plugin that defines the order (it would also have a reference to any in smithy-client).

@@ -198,6 +211,7 @@ class StructureShape < Shape
def initialize(options = {})
super
@members = {}
@members_by_name = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea. I think we should choose a different name though..

@mullermp mullermp merged commit 9bb9460 into decaf Feb 22, 2025
8 checks passed
@mullermp mullermp deleted the add_cbor_protocol branch February 22, 2025 21:14
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.

3 participants