Skip to content

gRPC client to be used by ext_proc filter#14283

Merged
htuch merged 3 commits intoenvoyproxy:masterfrom
gbrail:ext-proc-2
Dec 10, 2020
Merged

gRPC client to be used by ext_proc filter#14283
htuch merged 3 commits intoenvoyproxy:masterfrom
gbrail:ext-proc-2

Conversation

@gbrail
Copy link
Contributor

@gbrail gbrail commented Dec 4, 2020

This is a set of classes that the ext_proc server will use to abstract talking to the remote server via a gRPC stream.

@gbrail gbrail force-pushed the ext-proc-2 branch 2 times, most recently from 44a439b to cbe129f Compare December 4, 2020 21:17
The ext_proc filter will use this set of classes to abstract
handling the gRPC stream it'll use to talk to the remote server.

Signed-off-by: Gregory Brail <gregbrail@google.com>
@gbrail gbrail marked this pull request as ready for review December 5, 2020 00:41
@gbrail gbrail requested a review from htuch as a code owner December 5, 2020 00:41
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.

Exciting to see the implementation arriving :) Mostly just some Envoy-style comments..
/wait

public:
virtual ~ExternalProcessorCallbacks() = default;
virtual void onReceiveMessage(
std::unique_ptr<envoy::service::ext_proc::v3alpha::ProcessingResponse>&& response) = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: prefer using PURE in Envoy style

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack.

: callbacks_(callbacks) {
client_ = std::move(client);
auto descriptor = Protobuf::DescriptorPool::generated_pool()->FindMethodByName(kExternalMethod);
assert(descriptor != nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

No need for an assert here, since it will crash immediately if not true. Also, we don't use lower case assert in Envoy, prefer ASSERT, RELEASE_ASSERT or `ENVOY_BUG.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack. No assert needed for now then.


using ExternalProcessorStreamPtr = std::unique_ptr<ExternalProcessorStream>;

class ExternalProcessorCallbacks {
Copy link
Member

Choose a reason for hiding this comment

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

Does this wrapper layer give you much over the existing stream callbacks? Maybe you are planning on doing more in here later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. In general I wanted to have a clean abstraction to ease unit testing. One difference is that I don't think that we'll be needing to handle the metadata callbacks and this abstraction takes care of them for me.

Grpc::Status::GrpcStatus grpc_status_ = Grpc::Status::WellKnownGrpcStatus::Ok;
bool grpc_closed_ = false;

std::unique_ptr<ExternalProcessorClientImpl> client_;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: we usually setup an alias with using ExternalProcessClientImplPtr = std::unique.. for these smart pointer types in Envoy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack.

static constexpr char kExternalMethod[] =
"envoy.service.ext_proc.v3alpha.ExternalProcessor.Process";

ExternalProcessorClientImpl::ExternalProcessorClientImpl(
Copy link
Member

Choose a reason for hiding this comment

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

FYI, we're going to want to have a thread-local cache of aync clients for ext_proc similar to what is done for the gRPC access loggers and ext_authz. This is what I referenced in my comment on your doc a while back. But, I'm hoping that we can land #12598 soon to avoid you needing to have to do this explicitly.

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 see that in the ext_authz filter and I was planning to first get the basic thing working and then add that. However I'm watching that PR and if it comes in soon, then even better.

Signed-off-by: Gregory Brail <gregbrail@google.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.

LGTM modulo nits.
/wait

)

envoy_cc_library(
name = "client_impl",
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Envoy convention is typically client_lib.

TEST_F(ExtProcStreamTest, SendToStream) {
auto stream = client_->start(*this, 200ms);
// Send something and ensure that we get it. Doesn't really matter what.
EXPECT_CALL(stream_, sendMessageRaw_(_, false)).Times(1);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Times(1) is redundant.

Signed-off-by: Gregory Brail <gregbrail@google.com>
@gbrail
Copy link
Contributor Author

gbrail commented Dec 9, 2020

Ready, I think, but Azure won't let me re-run the failed ARM build.

@dio dio assigned htuch Dec 9, 2020
auto stream = client_->start(*this, 200ms);
// Send something and ensure that we get it. Doesn't really matter what.
EXPECT_CALL(stream_, sendMessageRaw_(_, false)).Times(1);
EXPECT_CALL(stream_, sendMessageRaw_(_, false));
Copy link
Member

Choose a reason for hiding this comment

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

Lots more of these in this PR, but I actually think I should just add a format check for this and stop harassing people :)

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, thanks!

@htuch htuch merged commit 04b75b1 into envoyproxy:master Dec 10, 2020
mpuncel added a commit to mpuncel/envoy that referenced this pull request Dec 11, 2020
* master:
  buffer: Optimize the layout of Slices in Buffer::OwnedImpl by removing subclassing and storing slice info directly in the SliceDeque (envoyproxy#14282)
  gRPC client to be used by ext_proc filter (envoyproxy#14283)
  http2: Add integration tests for PRIORITY frame flood mitigation for upstream servers (envoyproxy#14328)
  event: touch watchdog before execution of each post callback and before deferred deletion (envoyproxy#14339)
  stale: more allowed ops (envoyproxy#14345)
  stale: more changes (envoyproxy#14344)
  test: TODO fixup making enable_half_close private envoyproxy#14330)
  event: Reduce potential for lock contention while executing dispatcher post callbacks. (envoyproxy#14289)
  stale: fix config (envoyproxy#14337)
  metrics service sink: generalize the sink and grpc streamer for external use (envoyproxy#13919)
  wasm: update V8 to v8.8.278.8. (envoyproxy#14298)
  repo: switch to actions based stale bot (envoyproxy#14335)
  buffer: Use WatermarkFactory to create most WatermarkBuffer instances (envoyproxy#14256)

Signed-off-by: Michael Puncel <mpuncel@squareup.com>
@gbrail gbrail deleted the ext-proc-2 branch December 11, 2020 23:10
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