-
Notifications
You must be signed in to change notification settings - Fork 85
2 initial stress tests for the http wasm filters #72
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| all: headers_cpp.wasm async_call_cpp.wasm metadata_cpp.wasm grpc_call_cpp.wasm shared_cpp.wasm queue_cpp.wasm | ||
| all: headers_cpp.wasm async_call_cpp.wasm metadata_cpp.wasm grpc_call_cpp.wasm shared_cpp.wasm queue_cpp.wasm http_callout_cpp.wasm grpc_callout_cpp.wasm | ||
|
|
||
| include ../../../../../../api/wasm/cpp/Makefile.base_lite |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // NOLINT(namespace-envoy) | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include "proxy_wasm_intrinsics.h" | ||
| #include "proxy_wasm_intrinsics_lite.pb.h" | ||
|
|
||
| class RequestContext : public Context { | ||
| public: | ||
| explicit RequestContext(uint32_t id, RootContext *root) : Context(id, root) {} | ||
|
|
||
| FilterHeadersStatus onRequestHeaders() override; | ||
| }; | ||
|
|
||
| class ServiceContext : public RootContext { | ||
| public: | ||
| explicit ServiceContext(uint32_t id, StringView root_id) : RootContext(id, root_id) {} | ||
|
|
||
| void onStart() override { | ||
| callout_success_counter_ = defineMetric(MetricType::Counter, "test_callout_successes"); | ||
| callout_failure_counter_ = defineMetric(MetricType::Counter, "test_callout_failures"); | ||
| } | ||
|
|
||
| void incrementCalloutSuccesses(uint32_t inc_amount = 1U) { | ||
| incrementMetric(callout_success_counter_, inc_amount); | ||
| } | ||
|
|
||
| void incrementCalloutFailures(uint32_t inc_amount = 1U) { | ||
| incrementMetric(callout_failure_counter_, inc_amount); | ||
| } | ||
|
|
||
| private: | ||
| uint32_t callout_success_counter_; | ||
| uint32_t callout_failure_counter_; | ||
| }; | ||
|
|
||
| static RegisterContextFactory | ||
| register_ExampleContext(CONTEXT_FACTORY(RequestContext), ROOT_FACTORY(ServiceContext)); | ||
|
|
||
| class CalloutResponseHandler : public GrpcCallHandler<google::protobuf::Value> { | ||
| public: | ||
| CalloutResponseHandler(RequestContext *context) | ||
| : GrpcCallHandler<google::protobuf::Value>(context), context_(context) {} | ||
| void onCreateInitialMetadata() override {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we convert these from pure virtuals to having a default implementation of {} so that we can avoid requiring handlers which are used?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, would you like me to do that in this PR?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing, just wondering if you thought that was a good idea.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I'm pretty neutral on that. Most people will copy the boilerplate anyways and then hack it up. |
||
| void onSuccess(google::protobuf::Value &&response) override { | ||
| logDebug(response.string_value()); | ||
|
|
||
| serviceContext()->incrementCalloutSuccesses(); | ||
|
|
||
| continueRequest(); | ||
| } | ||
| void onFailure(GrpcStatus status, | ||
| std::unique_ptr<WasmData> error_message) override { | ||
| logInfo(std::string("failure ") + std::to_string(static_cast<int>(status)) + | ||
| std::string(error_message->view())); | ||
|
|
||
| serviceContext()->incrementCalloutFailures(); | ||
|
|
||
| // TODO wasm engine must support fail closed: expose abortRequest() or similar | ||
| continueRequest(); | ||
jplevyak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private: | ||
| ServiceContext *serviceContext() { | ||
| return static_cast<ServiceContext *>(context_->root()); | ||
| } | ||
|
|
||
| RequestContext *context_; | ||
| }; | ||
|
|
||
| FilterHeadersStatus RequestContext::onRequestHeaders() { | ||
| GrpcService grpc_service; | ||
| grpc_service.mutable_envoy_grpc()->set_cluster_name("callout_cluster"); | ||
| std::string grpc_service_string; | ||
| grpc_service.SerializeToString(&grpc_service_string); | ||
|
|
||
| google::protobuf::Value value; | ||
| value.set_string_value("request"); | ||
|
|
||
| grpcCallHandler(grpc_service_string, "service", "method", value, 1000, | ||
| std::unique_ptr<GrpcCallHandlerBase>(new CalloutResponseHandler(this))); | ||
| return FilterHeadersStatus::StopIteration; | ||
| } | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // NOLINT(namespace-envoy) | ||
| #include <string> | ||
| #include <unordered_map> | ||
|
|
||
| #include "proxy_wasm_intrinsics.h" | ||
|
|
||
| class ExampleContext : public Context { | ||
| public: | ||
| explicit ExampleContext(uint32_t id, RootContext *root) : Context(id, root) {} | ||
|
|
||
| FilterHeadersStatus onRequestHeaders() override; | ||
| }; | ||
| static RegisterContextFactory | ||
| register_ExampleContext(CONTEXT_FACTORY(ExampleContext)); | ||
|
|
||
| FilterHeadersStatus ExampleContext::onRequestHeaders() { | ||
| try { | ||
| WasmDataPtr data = getRequestHeader("x-callout-url"); | ||
|
|
||
| if (!data) { | ||
| logWarn("Missing x-callout-url header, cannot forward"); | ||
| return FilterHeadersStatus::Continue; | ||
| } | ||
|
|
||
| StringView callout_url{data->view()}; | ||
|
|
||
| logInfo("Forwarding to: " + std::string(callout_url)); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jplevyak take note. After 20 or so iterations the callout_url will log something that looks corrupted
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we can use fmt::format here
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this is disable for the exception issue. |
||
|
|
||
| auto callback = [](std::unique_ptr<WasmData> response_headers, | ||
| std::unique_ptr<WasmData> body, | ||
| std::unique_ptr<WasmData> response_trailers) { | ||
| logInfo("Got response"); | ||
| }; | ||
| httpCall(callout_url, | ||
| {{":method", "POST"}, {":path", "/"}, {":authority", "foo"}}, | ||
| "hello world", | ||
| {{"trail", "cow"}}, | ||
| 1000, | ||
| callback); | ||
| } catch (const std::exception &ex) { | ||
| logError("Caught exception: " + std::string{ex.what()}); | ||
| } catch (const std::string &ex) { | ||
| logError("Caught exception: " + ex); | ||
| } catch (...) { | ||
| logError("Caught exception"); | ||
| } | ||
|
|
||
| return FilterHeadersStatus::StopIteration; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And all the other filters used this REGISTER_FACTORY macro so added that too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL