Skip to content
This repository was archived by the owner on Dec 16, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions api/wasm/cpp/proxy_wasm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ class RootContext : public ContextBase {
// Low level HTTP/gRPC interface.
virtual void onHttpCallResponse(uint32_t token, uint32_t headers, size_t body_size,
uint32_t trailers);
virtual void onGrpcCreateInitialMetadata(uint32_t token, uint32_t headers);
virtual void onGrpcReceiveInitialMetadata(uint32_t token, uint32_t headers);
virtual void onGrpcReceiveTrailingMetadata(uint32_t token, uint32_t trailers);
virtual void onGrpcReceive(uint32_t token, size_t body_size);
Expand Down Expand Up @@ -1251,23 +1250,6 @@ inline void GrpcStreamHandlerBase::send(StringView message, bool end_of_stream)
}
}

inline void RootContext::onGrpcCreateInitialMetadata(uint32_t token, uint32_t headers) {
{
auto it = grpc_calls_.find(token);
if (it != grpc_calls_.end()) {
it->second->onCreateInitialMetadata(headers);
return;
}
}
{
auto it = grpc_streams_.find(token);
if (it != grpc_streams_.end()) {
it->second->onCreateInitialMetadata(headers);
return;
}
}
}

inline void RootContext::onGrpcReceiveInitialMetadata(uint32_t token, uint32_t headers) {
{
auto it = grpc_streams_.find(token);
Expand Down
11 changes: 5 additions & 6 deletions api/wasm/cpp/proxy_wasm_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ enum class HeaderMapType : int32_t {
RequestTrailers = 1, // During the onLog callback these are immutable
ResponseHeaders = 2, // During the onLog callback these are immutable
ResponseTrailers = 3, // During the onLog callback these are immutable
GrpcCreateInitialMetadata = 4,
GrpcReceiveInitialMetadata = 5, // Immutable
GrpcReceiveTrailingMetadata = 6, // Immutable
HttpCallResponseHeaders = 7, // Immutable
HttpCallResponseTrailers = 8, // Immutable
MAX = 8,
GrpcReceiveInitialMetadata = 4, // Immutable
GrpcReceiveTrailingMetadata = 5, // Immutable
HttpCallResponseHeaders = 6, // Immutable
HttpCallResponseTrailers = 7, // Immutable
MAX = 7,
};
enum class BufferType : int32_t {
HttpRequestBody = 0, // During the onLog callback these are immutable
Expand Down
2 changes: 0 additions & 2 deletions api/wasm/cpp/proxy_wasm_externs.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ extern "C" FilterMetadataStatus proxy_on_response_metadata(uint32_t context_id,
// HTTP/gRPC.
extern "C" void proxy_on_http_call_response(uint32_t context_id, uint32_t token, uint32_t headers,
uint32_t body_size, uint32_t trailers);
extern "C" void proxy_on_grpc_create_initial_metadata(uint32_t context_id, uint32_t token,
uint32_t headers);
extern "C" void proxy_on_grpc_receive_initial_metadata(uint32_t context_id, uint32_t token,
uint32_t headers);
extern "C" void proxy_on_grpc_trailing_metadata(uint32_t context_id, uint32_t token,
Expand Down
5 changes: 0 additions & 5 deletions api/wasm/cpp/proxy_wasm_intrinsics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@ extern "C" PROXY_WASM_KEEPALIVE void proxy_on_http_call_response(uint32_t contex
->onHttpCallResponse(token, headers, static_cast<size_t>(body_size), trailers);
}

extern "C" PROXY_WASM_KEEPALIVE void
proxy_on_grpc_create_initial_metadata(uint32_t context_id, uint32_t token, uint32_t headers) {
getRootContext(context_id)->onGrpcCreateInitialMetadata(token, headers);
}

extern "C" PROXY_WASM_KEEPALIVE void
proxy_on_grpc_receive_initial_metadata(uint32_t context_id, uint32_t token, uint32_t headers) {
getRootContext(context_id)->onGrpcReceiveInitialMetadata(token, headers);
Expand Down
Binary file modified examples/wasm/envoy_filter_http_wasm_example.wasm
Binary file not shown.
21 changes: 0 additions & 21 deletions source/extensions/common/wasm/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,6 @@ Http::HeaderMap* Context::getMap(HeaderMapType type) {
return response_headers_;
case HeaderMapType::ResponseTrailers:
return response_trailers_;
case HeaderMapType::GrpcCreateInitialMetadata:
return grpc_create_initial_metadata_;
default:
return nullptr;
}
Expand Down Expand Up @@ -690,8 +688,6 @@ const Http::HeaderMap* Context::getConstMap(HeaderMapType type) {
return access_log_response_trailers_;
}
return response_trailers_;
case HeaderMapType::GrpcCreateInitialMetadata:
return rootContext()->grpc_create_initial_metadata_;
case HeaderMapType::GrpcReceiveInitialMetadata:
return rootContext()->grpc_receive_initial_metadata_.get();
case HeaderMapType::GrpcReceiveTrailingMetadata:
Expand Down Expand Up @@ -967,9 +963,6 @@ WasmResult Context::grpcCall(const GrpcService& grpc_service, absl::string_view
hash_policy.Add()->mutable_header()->set_header_name(Http::Headers::get().Host.get());
options.setHashPolicy(hash_policy);

// NB: this call causes the onCreateInitialMetadata callback to occur inline *before* this call
// returns. Consequently the grpc_request is not available. Attempting to close or reset from
// that callback will fail.
auto grpc_request =
grpc_client->sendRaw(service_name, method_name, std::make_unique<Buffer::OwnedImpl>(request),
handler, Tracing::NullSpan::instance(), options);
Expand Down Expand Up @@ -1014,9 +1007,6 @@ WasmResult Context::grpcStream(const GrpcService& grpc_service, absl::string_vie
hash_policy.Add()->mutable_header()->set_header_name(Http::Headers::get().Host.get());
options.setHashPolicy(hash_policy);

// NB: this call causes the onCreateInitialMetadata callback to occur inline *before* this call
// returns. Consequently the grpc_stream is not available. Attempting to close or reset from
// that callback will fail.
auto grpc_stream = grpc_client->startRaw(service_name, method_name, handler, options);
if (!grpc_stream) {
grpc_stream_.erase(token);
Expand Down Expand Up @@ -1392,17 +1382,6 @@ void Context::onQueueReady(uint32_t token) {
}
}

void Context::onGrpcCreateInitialMetadata(uint32_t token, Http::HeaderMap& metadata) {
if (!wasm_->on_grpc_create_initial_metadata_) {
return;
}
DeferAfterCallActions actions(this);
grpc_create_initial_metadata_ = &metadata;
wasm_->on_grpc_create_initial_metadata_(this, id_, token,
headerSize(grpc_create_initial_metadata_));
grpc_create_initial_metadata_ = nullptr;
}

void Context::onGrpcReceiveInitialMetadata(uint32_t token, Http::HeaderMapPtr&& metadata) {
if (!wasm_->on_grpc_receive_initial_metadata_) {
return;
Expand Down
11 changes: 2 additions & 9 deletions source/extensions/common/wasm/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,7 @@ class Context : public Logger::Loggable<Logger::Id::wasm>,

struct GrpcCallClientHandler : public Grpc::RawAsyncRequestCallbacks {
// Grpc::AsyncRequestCallbacks
void onCreateInitialMetadata(Http::RequestHeaderMap& metadata) override {
context_->onGrpcCreateInitialMetadata(token_, metadata);
}
void onCreateInitialMetadata(Http::RequestHeaderMap&) override {}
void onSuccessRaw(Buffer::InstancePtr&& response, Tracing::Span& /* span */) override {
context_->onGrpcReceive(token_, std::move(response));
}
Expand All @@ -369,9 +367,7 @@ class Context : public Logger::Loggable<Logger::Id::wasm>,

struct GrpcStreamClientHandler : public Grpc::RawAsyncStreamCallbacks {
// Grpc::AsyncStreamCallbacks
void onCreateInitialMetadata(Http::RequestHeaderMap& metadata) override {
context_->onGrpcCreateInitialMetadata(token_, metadata);
}
void onCreateInitialMetadata(Http::RequestHeaderMap&) override {}
void onReceiveInitialMetadata(Http::ResponseHeaderMapPtr&& metadata) override {
context_->onGrpcReceiveInitialMetadata(token_, std::move(metadata));
}
Expand All @@ -398,8 +394,6 @@ class Context : public Logger::Loggable<Logger::Id::wasm>,
void onHttpCallSuccess(uint32_t token, Envoy::Http::ResponseMessagePtr& response);
void onHttpCallFailure(uint32_t token, Http::AsyncClient::FailureReason reason);

virtual void onGrpcCreateInitialMetadata(uint32_t token,
Http::HeaderMap& metadata); // For both Call and Stream.
virtual void onGrpcReceive(uint32_t token,
Buffer::InstancePtr response); // Call (implies OK close) and Stream.
virtual void onGrpcClose(uint32_t token, const Grpc::Status::GrpcStatus& status,
Expand Down Expand Up @@ -463,7 +457,6 @@ class Context : public Logger::Loggable<Logger::Id::wasm>,
// Only available during onHttpCallResponse.
Envoy::Http::ResponseMessagePtr* http_call_response_{};

Http::HeaderMap* grpc_create_initial_metadata_{};
Http::HeaderMapPtr grpc_receive_initial_metadata_{};
Http::HeaderMapPtr grpc_receive_trailing_metadata_{};

Expand Down
10 changes: 0 additions & 10 deletions source/extensions/common/wasm/null/null_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ void NullPlugin::getFunction(absl::string_view function_name, WasmCallVoid<3>* f
SaveRestoreContext saved_context(context);
plugin->onGrpcReceive(context_id.u64_, token.u64_, body_size.u64_);
};
} else if (function_name == "proxy_on_grpc_create_initial_metadata") {
*f = [plugin](Common::Wasm::Context* context, Word context_id, Word token, Word headers) {
SaveRestoreContext saved_context(context);
plugin->onGrpcCreateInitialMetadata(context_id.u64_, token.u64_, headers.u64_);
};
} else if (function_name == "proxy_on_grpc_receive_initial_metadata") {
*f = [plugin](Common::Wasm::Context* context, Word context_id, Word token, Word headers) {
SaveRestoreContext saved_context(context);
Expand Down Expand Up @@ -431,11 +426,6 @@ void NullPlugin::onGrpcClose(uint64_t context_id, uint64_t token, uint64_t statu
getRootContext(context_id)->onGrpcClose(token, static_cast<Plugin::GrpcStatus>(status_code));
}

void NullPlugin::onGrpcCreateInitialMetadata(uint64_t context_id, uint64_t token,
uint64_t headers) {
getRootContext(context_id)->onGrpcCreateInitialMetadata(token, headers);
}

void NullPlugin::onGrpcReceiveInitialMetadata(uint64_t context_id, uint64_t token,
uint64_t headers) {
getRootContext(context_id)->onGrpcReceiveInitialMetadata(token, headers);
Expand Down
1 change: 0 additions & 1 deletion source/extensions/common/wasm/null/null_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class NullPlugin : public NullVmPlugin {

void onGrpcReceive(uint64_t context_id, uint64_t token, size_t body_size);
void onGrpcClose(uint64_t context_id, uint64_t token, uint64_t status_code);
void onGrpcCreateInitialMetadata(uint64_t context_id, uint64_t token, uint64_t headers);
void onGrpcReceiveInitialMetadata(uint64_t context_id, uint64_t token, uint64_t headers);
void onGrpcReceiveTrailingMetadata(uint64_t context_id, uint64_t token, uint64_t trailers);

Expand Down
1 change: 0 additions & 1 deletion source/extensions/common/wasm/wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ void Wasm::getFunctions() {
_GET_PROXY(on_http_call_response);
_GET_PROXY(on_grpc_receive);
_GET_PROXY(on_grpc_close);
_GET_PROXY(on_grpc_create_initial_metadata);
_GET_PROXY(on_grpc_receive_initial_metadata);
_GET_PROXY(on_grpc_receive_trailing_metadata);
_GET_PROXY(on_queue_ready);
Expand Down
1 change: 0 additions & 1 deletion source/extensions/common/wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ class Wasm : public Logger::Loggable<Logger::Id::wasm>, public std::enable_share

WasmCallVoid<3> on_grpc_receive_;
WasmCallVoid<3> on_grpc_close_;
WasmCallVoid<3> on_grpc_create_initial_metadata_;
WasmCallVoid<3> on_grpc_receive_initial_metadata_;
WasmCallVoid<3> on_grpc_receive_trailing_metadata_;

Expand Down
Binary file modified test/extensions/access_loggers/wasm/test_data/logging.wasm
Binary file not shown.
Binary file modified test/extensions/filters/http/wasm/test_data/async_call_cpp.wasm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ static RegisterContextFactory register_ExampleContext(CONTEXT_FACTORY(ExampleCon
class MyGrpcCallHandler : public GrpcCallHandler<google::protobuf::Value> {
public:
MyGrpcCallHandler() : GrpcCallHandler<google::protobuf::Value>() {}
void onCreateInitialMetadata(uint32_t) override {}
void onSuccess(size_t body_size) override {
auto response = getBufferBytes(BufferType::GrpcReceiveBuffer, 0, body_size);
logDebug(response->proto<google::protobuf::Value>().string_value());
Expand All @@ -35,11 +34,6 @@ class MyGrpcStreamHandler
: public GrpcStreamHandler<google::protobuf::Value, google::protobuf::Value> {
public:
MyGrpcStreamHandler() : GrpcStreamHandler<google::protobuf::Value, google::protobuf::Value>() {}
void onCreateInitialMetadata(uint32_t) override {
google::protobuf::Value value;
value.set_string_value("request");
send(value, false);
}
void onReceiveInitialMetadata(uint32_t) override {}
void onReceiveTrailingMetadata(uint32_t) override {}
void onReceive(size_t body_size) override {
Expand Down
Binary file modified test/extensions/filters/http/wasm/test_data/grpc_call_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/filters/http/wasm/test_data/headers_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/filters/http/wasm/test_data/metadata_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/filters/http/wasm/test_data/queue_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/filters/http/wasm/test_data/shared_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/wasm/test_data/asm2wasm_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/wasm/test_data/bad_signature_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/wasm/test_data/emscripten_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/wasm/test_data/logging_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/wasm/test_data/missing_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/wasm/test_data/segv_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/wasm/test_data/speed_cpp.wasm
Binary file not shown.
Binary file modified test/extensions/wasm/test_data/stats_cpp.wasm
Binary file not shown.