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

Support headers #40

Merged
merged 2 commits into from
May 29, 2019
Merged

Support headers #40

merged 2 commits into from
May 29, 2019

Conversation

mxpv
Copy link
Member

@mxpv mxpv commented May 24, 2019

This PR adds headers support to ttrpc.

Signed-off-by: Maksym Pavlenko makpav@amazon.com

Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
@crosbymichael
Copy link
Member

LGTM

@crosbymichael
Copy link
Member

I tested this and have code to update the namespaces package in containerd to pass the context's namespace to ttrpc services

@cpuguy83
Copy link
Member

Just a nit, does it make sense to call this Headers when it's not really a header? Seems like metadata to attach to a request.

re: using this for namespaces.
Why wouldn't the namespace be passed as an argument to the rpc request?

@mxpv
Copy link
Member Author

mxpv commented May 24, 2019

Just a nit, does it make sense to call this Headers when it's not really a header? Seems like metadata to attach to a request.

This can be called in many different ways, but the concept remains the same - send arbitrary data with a request. IMO name 'headers' make the intention of this a bit clearer for a user - pass an extra information with a request, similarly to what http headers are used for.

Why wouldn't the namespace be passed as an argument to the rpc request?

That would work, but you'd need to modify each request to add 'namespace' field to use namespaces.
In containerd there is already a good way to do this:
client, err := containerd.New(address, containerd.WithDefaultNamespace("docker")) <-- all requests from this client use docker ns
or

docker = namespaces.WithNamespace(context, "docker")
containerd, err := client.NewContainer(docker, "id")

So it'd be nice to use the same mechanism for ttrpc as well.

@cpuguy83
Copy link
Member

Headers are items that are sent at the beginning of a request. These really aren't headers.
Metadata would be fitting, IMO. Also similar to grpc.

I'm not sure I agree with stuffing data into the protocol that changes the behavior of the rpc endpoint.. but I guess that's not really an argument for this repo.

Being able to attach metadata to a request does make sense though, e.g. for distributed tracing.

@crosbymichael
Copy link
Member

crosbymichael commented May 24, 2019 via email

@mxpv
Copy link
Member Author

mxpv commented May 25, 2019

@crosbymichael @cpuguy83 done

Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

@crosbymichael
Copy link
Member

LGTM

@crosbymichael crosbymichael merged commit a5bd8ce into containerd:master May 29, 2019
@mxpv mxpv deleted the headers branch May 29, 2019 19:49
import "context"

// Metadata represents the key-value pairs (similar to http.Header) to be passed to ttrpc server from a client.
type Metadata map[string]StringList
Copy link
Member

Choose a reason for hiding this comment

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

This type is not well supported by protobuf.

"testing"
)

func TestMetadata_Get(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use underscores in test names.

Copy link
Member

@stevvooe stevvooe left a comment

Choose a reason for hiding this comment

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

NOT LGTM

Sorry for coming in late here, but this needs a few fixes on the protocol serialization/support.

  1. Metadata needs to be defined as part of types.go. That documents the entire protocol. If there are metadata helpers, you can include them in a separate file.
  2. The StringList approach is incompatible with the way grpc represents maps. You really need to have a list of key-value pairs. This does repeat keys, but repeated keys is not a common use case, so its not worth breaking generating compatibility. I'd recommend separating the serialization types from the user types.
  3. GetMetadataValue needs to return multiple strings, so be compatible with grpc's headers, which allow multiple values.
    4. We should use a model closer to net/http headers than the metadata interface in grpc-go. net/http headers let's you control set vs add, etc. User type looks good here.

We should get another PR on this before we can't go back on it.

@@ -61,6 +61,7 @@ func (tc *testingClient) Test(ctx context.Context, req *testPayload) (*testPaylo
type testPayload struct {
Foo string `protobuf:"bytes,1,opt,name=foo,proto3"`
Deadline int64 `protobuf:"varint,2,opt,name=deadline,proto3"`
Metadata string `protobuf:"bytes,3,opt,name=metadata,proto3"`
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this line adds any value.

@stevvooe
Copy link
Member

#43 covers the concerns here.

@mxpv
Copy link
Member Author

mxpv commented Jun 14, 2019

#43 covers the concerns here.

@stevvooe a bit late for the party :( Let me know if anything left to address.

thaJeztah added a commit to thaJeztah/docker that referenced this pull request Aug 26, 2019
full diff: containerd/ttrpc@699c4e4...1fb3814

changes included:

- containerd/ttrpc#37 Handle EOF to prevent file descriptor leak
- containerd/ttrpc#38 Improve connection error handling
- containerd/ttrpc#40 Support headers
- containerd/ttrpc#41 Add client and server unary interceptors
- containerd/ttrpc#42 Refactor close handling for ttrpc clients
- containerd/ttrpc#43 metadata as KeyValue type

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/docker that referenced this pull request Aug 28, 2019
full diff: containerd/ttrpc@699c4e4...92c8520

changes:

- containerd/ttrpc#37 Handle EOF to prevent file descriptor leak
- containerd/ttrpc#38 Improve connection error handling
- containerd/ttrpc#40 Support headers
- containerd/ttrpc#41 Add client and server unary interceptors
- containerd/ttrpc#43 metadata as KeyValue type
- containerd/ttrpc#42 Refactor close handling for ttrpc clients
- containerd/ttrpc#44 Fix method full name generation
- containerd/ttrpc#46 Client.Call(): do not return error if no Status is set (gRPC v1.23 and up)
- containerd/ttrpc#49 Handle ok status

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
docker-jenkins pushed a commit to docker-archive/docker-ce that referenced this pull request Sep 3, 2019
full diff: containerd/ttrpc@699c4e4...92c8520

changes:

- containerd/ttrpc#37 Handle EOF to prevent file descriptor leak
- containerd/ttrpc#38 Improve connection error handling
- containerd/ttrpc#40 Support headers
- containerd/ttrpc#41 Add client and server unary interceptors
- containerd/ttrpc#43 metadata as KeyValue type
- containerd/ttrpc#42 Refactor close handling for ttrpc clients
- containerd/ttrpc#44 Fix method full name generation
- containerd/ttrpc#46 Client.Call(): do not return error if no Status is set (gRPC v1.23 and up)
- containerd/ttrpc#49 Handle ok status

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 8769255d1bb9c469d4f2966e7e9869a9f126f9e9
Component: engine
thaJeztah added a commit to thaJeztah/docker that referenced this pull request Sep 12, 2019
full diff: containerd/ttrpc@699c4e4...92c8520

changes:

- containerd/ttrpc#37 Handle EOF to prevent file descriptor leak
- containerd/ttrpc#38 Improve connection error handling
- containerd/ttrpc#40 Support headers
- containerd/ttrpc#41 Add client and server unary interceptors
- containerd/ttrpc#43 metadata as KeyValue type
- containerd/ttrpc#42 Refactor close handling for ttrpc clients
- containerd/ttrpc#44 Fix method full name generation
- containerd/ttrpc#46 Client.Call(): do not return error if no Status is set (gRPC v1.23 and up)
- containerd/ttrpc#49 Handle ok status

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 8769255)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
docker-jenkins pushed a commit to docker-archive/docker-ce that referenced this pull request Sep 23, 2019
full diff: containerd/ttrpc@699c4e4...92c8520

changes:

- containerd/ttrpc#37 Handle EOF to prevent file descriptor leak
- containerd/ttrpc#38 Improve connection error handling
- containerd/ttrpc#40 Support headers
- containerd/ttrpc#41 Add client and server unary interceptors
- containerd/ttrpc#43 metadata as KeyValue type
- containerd/ttrpc#42 Refactor close handling for ttrpc clients
- containerd/ttrpc#44 Fix method full name generation
- containerd/ttrpc#46 Client.Call(): do not return error if no Status is set (gRPC v1.23 and up)
- containerd/ttrpc#49 Handle ok status

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 8769255d1bb9c469d4f2966e7e9869a9f126f9e9)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 525e8ed3febff46d07cb01961601824b5f8b301b
Component: engine
burnMyDread pushed a commit to burnMyDread/moby that referenced this pull request Oct 21, 2019
full diff: containerd/ttrpc@699c4e4...92c8520

changes:

- containerd/ttrpc#37 Handle EOF to prevent file descriptor leak
- containerd/ttrpc#38 Improve connection error handling
- containerd/ttrpc#40 Support headers
- containerd/ttrpc#41 Add client and server unary interceptors
- containerd/ttrpc#43 metadata as KeyValue type
- containerd/ttrpc#42 Refactor close handling for ttrpc clients
- containerd/ttrpc#44 Fix method full name generation
- containerd/ttrpc#46 Client.Call(): do not return error if no Status is set (gRPC v1.23 and up)
- containerd/ttrpc#49 Handle ok status

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: zach <Zachary.Joyner@linux.com>
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.

5 participants