Skip to content

grpc: add a raw (Buffer::Instance) interface#6525

Merged
htuch merged 23 commits intoenvoyproxy:masterfrom
jplevyak:raw-grpc-interface
Jun 6, 2019
Merged

grpc: add a raw (Buffer::Instance) interface#6525
htuch merged 23 commits intoenvoyproxy:masterfrom
jplevyak:raw-grpc-interface

Conversation

@jplevyak
Copy link
Contributor

@jplevyak jplevyak commented Apr 9, 2019

For an explanation of how to fill out the fields, please see the relevant section
in PULL_REQUESTS.md

Description: Add a raw (Buffer::Instance) gRPC interface. The existing interface is layered on top
of a new raw interface which takes the service and method names as absl::string_view and which
passes the data to be sent and data received as Buffer::Instance(s). This is similar to the way
the existing typed interface is layered on the untyped interface. This enables extensions and
plugins to use gRPC without the gRPC service protobufs being compiled into envoy. This can also
support general gRPC proxies.
Risk Level: Medium
Testing: all existing tests pass.
Docs Changes: N/A (no externally visible change)
Release Notes: N/A
[Optional Fixes #Issue]
[Optional Deprecated:]

Signed-off-by: John Plevyak <jplevyak@gmail.com>
Copy link
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Let's start from some interface level comments.

/wait

@htuch htuch self-assigned this Apr 10, 2019
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Thanks @jplevyak, this is going to be super neat for #4272. Some high level structural comments to get started.
/wait

Signed-off-by: John Plevyak <jplevyak@gmail.com>
Signed-off-by: John Plevyak <jplevyak@gmail.com>
@mattklein123
Copy link
Member

Can I ask a high level probably stupid question: how is this actually going to be used? Where are the raw message bytes going to come from to send and what is the caller going to do with the raw bytes returned? I understand this change in theory but the utility is not clear to me.

@jplevyak
Copy link
Contributor Author

Can I ask a high level probably stupid question: how is this actually going to be used? Where are the raw message bytes going to come from to send and what is the caller going to do with the raw bytes returned? I understand this change in theory but the utility is not clear to me.

This is going to be used by the WASM extension system. It can also be used by any generic gRPC proxy system.

@jplevyak
Copy link
Contributor Author

I believe I have a plan to address the issue of the API:

  • make the base API the raw API
    • startRaw -> start where the clients convert Protobuf::MethodDescriptor
  • move the Untyped and Typed Callback support code to source/common/grpc/grpc_callbacks.*
    • clients will use to provide the interface used today
  • continue having mocks for the Untyped and Typed Callbacks in the test/mocks directory

I'll ping this PR when I am done.

Thanx for the comments.

@mattklein123
Copy link
Member

This is going to be used by the WASM extension system. It can also be used by any generic gRPC proxy system.

OK, thanks that makes sense. So basically the WASM code will have the protos compiled in and just use a raw API to make calls. Regarding the latter, Envoy already is a generic gRPC proxy so I'm not sure why this would ever be used in that manner, but agree it seems possible. Since this is targeted towards WASM/plugin can you update the issue description to make that more clear?

Also, more generally, @jplevyak @PiotrSikora @lizan @dio is there a design doc on the proposed WASM <-> API bindings? I've been asking for this for a while and would love to review. Thank you.

@htuch
Copy link
Member

htuch commented Apr 12, 2019

@jplevyak this seems like a good plan. Please ping me on IM if you want to chat further. The key things to preserve are economy of mechanism and mockability :)

@htuch htuch added the waiting label Apr 15, 2019
@stale
Copy link

stale bot commented Apr 19, 2019

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Apr 19, 2019
Signed-off-by: John Plevyak <jplevyak@gmail.com>
@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label Apr 19, 2019
@jplevyak
Copy link
Contributor Author

I have updated this PR as per the comments. PTAL

Signed-off-by: John Plevyak <jplevyak@gmail.com>
Copy link
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

A quick skim, will do more review on Monday.

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Great, I think this is the right direction, a few stuctural comments to start.
/wait

Signed-off-by: John Plevyak <jplevyak@gmail.com>
Copy link
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

Thanks! Overall this looks much better other than comments already pointed out by @htuch.

@htuch htuch added the waiting label Apr 24, 2019
jplevyak added 2 commits May 22, 2019 06:31
Signed-off-by: John Plevyak <jplevyak@gmail.com>
Signed-off-by: John Plevyak <jplevyak@gmail.com>
htuch
htuch previously approved these changes May 22, 2019
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM. Coverage is failing, I know we are having Envoy-wide issues with being right at 97.5% right now, but you might want to see if there is any avoidable regression in this PR.

@htuch htuch added the waiting label May 22, 2019
@jplevyak
Copy link
Contributor Author

The MacOS and coverage failures seem to be unrelated. lizan do you have any more comments?
I am not authorized to merge so I will continue to monitor this thread. Thanks for the reviews!

@htuch
Copy link
Member

htuch commented May 23, 2019

/retest

@repokitteh-read-only
Copy link

🐴 hold your horses - no failures detected, yet.

🐱

Caused by: a #6525 (comment) was created by @htuch.

see: more, trace.

@lizan
Copy link
Member

lizan commented May 23, 2019

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@htuch
Copy link
Member

htuch commented May 23, 2019

@jplevyak the coverage is below the threshold, and we're getting TSAN flakes. Can you merge master and try again, plus maybe look to see if you can fill in any trivial coverage stuff missing? This PR is good to go modulo this.

Signed-off-by: John Plevyak <jplevyak@gmail.com>
Signed-off-by: John Plevyak <jplevyak@gmail.com>
jplevyak added 3 commits June 5, 2019 10:22
Signed-off-by: John Plevyak <jplevyak@gmail.com>
See envoyproxy#6917 for details.

Signed-off-by: John Plevyak <jplevyak@gmail.com>
Signed-off-by: John Plevyak <jplevyak@gmail.com>
@jplevyak
Copy link
Contributor Author

jplevyak commented Jun 5, 2019

I think the coverage is in pretty good shape. If there is anything which stands out, please tell me.

Copy link
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

looks great, one last comment.

// lifetime of the Slice(s) exceeds our Buffer::Instance.
std::vector<grpc::Slice> slices;
byte_buffer.Dump(&slices);
if (!byte_buffer.Dump(&slices).ok()) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to mock this for testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even the gRPC library provided by Google doesn't test for Dump failure. Here is the only test:

TEST_F(ByteBufferTest, Dump) {
grpc_slice hello = grpc_slice_from_copied_string(kContent1);
grpc_slice world = grpc_slice_from_copied_string(kContent2);
std::vector slices;
slices.push_back(Slice(hello, Slice::STEAL_REF));
slices.push_back(Slice(world, Slice::STEAL_REF));
ByteBuffer buffer(&slices[0], 2);
slices.clear();
(void)buffer.Dump(&slices);
EXPECT_TRUE(SliceEqual(slices[0], hello));
EXPECT_TRUE(SliceEqual(slices[1], world));
}

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this is fine. I think if this was Envoy code we would want a test, but it's not worth the effort to deal with this in external deps that aren't written with mocking in mind.

auto byte_buffer = GoogleGrpcUtils::makeByteBuffer(std::move(buffer));
std::vector<grpc::Slice> slices;
byte_buffer.Dump(&slices);
RELEASE_ASSERT(byte_buffer.Dump(&slices).ok(), "");
Copy link
Member

Choose a reason for hiding this comment

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

When can Dump fail? We should only use RELEASE_ASSERT in situations where it's effectively OOM and some unrecoverable situation exists. Otherwise, there should be error handling.

Copy link
Contributor

Choose a reason for hiding this comment

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

See discussion in #6917.

Note: RELEASE_ASSERT is used only in tests, and failure is handled properly in the real code.

Copy link
Member

Choose a reason for hiding this comment

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

This is fine in the tests then. I would still like to see the Dump condition mocked and tested if gRPC has mocks that can support 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.

This is a test, so it is a RELEASE__ASSERT. It should never fail. For the production code I am handling the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above regarding testing Dump().

@htuch htuch added the waiting label Jun 6, 2019
Signed-off-by: John Plevyak <jplevyak@gmail.com>
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@htuch htuch merged commit d681137 into envoyproxy:master Jun 6, 2019
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