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

does it support grpc protocol process #143

Open
INT2ECALL opened this issue Sep 27, 2022 · 3 comments
Open

does it support grpc protocol process #143

INT2ECALL opened this issue Sep 27, 2022 · 3 comments

Comments

@INT2ECALL
Copy link

hello, i want to process grpc stream by this sdk,i deployment a wasm in my envoy,but i got error :
pstream connect error or disconnect/reset before headers. reset reason: protocol error

@INT2ECALL
Copy link
Author

INT2ECALL commented Sep 27, 2022

it works in http,but when i set my cluster to my grpc server i got this error

client -> envoy(wasm)-> grpc server

@INT2ECALL
Copy link
Author

INT2ECALL commented Sep 27, 2022

my wasm code is

#include <string>
#include <string_view>
#include <unordered_map>
 
#include "proxy_wasm_intrinsics.h"
 
class ExampleRootContext : public RootContext {
public:
  explicit ExampleRootContext(uint32_t id, std::string_view root_id) : RootContext(id, root_id) {}
 
  bool onStart(size_t) override;
  bool onConfigure(size_t) override;
  void onTick() override;
};
 
class ExampleContext : public Context {
public:
  explicit ExampleContext(uint32_t id, RootContext* root) : Context(id, root) {}
 
  void onCreate() override;
  FilterHeadersStatus onRequestHeaders(uint32_t headers, bool end_of_stream) override;
  FilterDataStatus onRequestBody(size_t body_buffer_length, bool end_of_stream) override;
  FilterHeadersStatus onResponseHeaders(uint32_t headers, bool end_of_stream) override;
  FilterDataStatus onResponseBody(size_t body_buffer_length, bool end_of_stream) override;
  void onDone() override;
  void onLog() override;
  void onDelete() override;
};
static RegisterContextFactory register_ExampleContext(CONTEXT_FACTORY(ExampleContext),
                                                      ROOT_FACTORY(ExampleRootContext),
                                                      "my_root_id");
 
bool ExampleRootContext::onStart(size_t) {
  LOG_TRACE("onStart");
  return true;
}
 
bool ExampleRootContext::onConfigure(size_t) {
  LOG_TRACE("onConfigure");
  proxy_set_tick_period_milliseconds(1000); // 1 sec
  return true;
}
 
void ExampleRootContext::onTick() { LOG_TRACE("onTick"); }
 
void ExampleContext::onCreate() { LOG_WARN(std::string("onCreate " + std::to_string(id()))); }
 
FilterHeadersStatus ExampleContext::onRequestHeaders(uint32_t, bool) {
  LOG_DEBUG(std::string("onRequestHeaders ") + std::to_string(id()));
  auto result = getRequestHeaderPairs();
  auto pairs = result->pairs();
  LOG_INFO(std::string("headers: ") + std::to_string(pairs.size()));
  for (auto& p : pairs) {
    LOG_INFO(std::string(p.first) + std::string(" -> ") + std::string(p.second));
  }
  return FilterHeadersStatus::Continue;
}
 
FilterHeadersStatus ExampleContext::onResponseHeaders(uint32_t, bool) {
  LOG_DEBUG(std::string("onResponseHeaders ") + std::to_string(id()));
  auto result = getResponseHeaderPairs();
  auto pairs = result->pairs();
  LOG_INFO(std::string("headers: ") + std::to_string(pairs.size()));
  for (auto& p : pairs) {
    LOG_INFO(std::string(p.first) + std::string(" -> ") + std::string(p.second));
  }
  return FilterHeadersStatus::Continue;
}
 
FilterDataStatus ExampleContext::onRequestBody(size_t body_buffer_length,
                                               bool /* end_of_stream */) {
  auto body = getBufferBytes(WasmBufferType::HttpRequestBody, 0, body_buffer_length);
  LOG_ERROR(std::string("onRequestBody ") + std::string(body->view()));
  return FilterDataStatus::Continue;
}
 
FilterDataStatus ExampleContext::onResponseBody(size_t /* body_buffer_length */,
                                                bool /* end_of_stream */) {
  setBuffer(WasmBufferType::HttpResponseBody, 0, 17, "Hello, Wasm world");
  return FilterDataStatus::Continue;
}
 
void ExampleContext::onDone() { LOG_WARN(std::string("onDone " + std::to_string(id()))); }
 
void ExampleContext::onLog() { LOG_WARN(std::string("onLog " + std::to_string(id()))); }
 
void ExampleContext::onDelete() { LOG_WARN(std::string("onDelete " + std::to_string(id()))); }

@INT2ECALL
Copy link
Author

INT2ECALL commented Sep 28, 2022

solve by add clusters http2 option

    http2_protocol_options:
      max_concurrent_streams: 100

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

No branches or pull requests

1 participant