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

Documentation and comments for runtime #24

Open
esnible opened this issue Aug 30, 2020 · 6 comments
Open

Documentation and comments for runtime #24

esnible opened this issue Aug 30, 2020 · 6 comments

Comments

@esnible
Copy link

esnible commented Aug 30, 2020

The runtime lacks an explanation of parameters, return enumerations, and state managment.

For example, I see onRequestBody(body_buffer_length: usize, end_of_stream: bool): FilterDataStatusValues and see that FilterDataStatusValues are

  Continue = 0,
  StopIterationAndBuffer = 1,
  StopIterationAndWatermark = 2,
  StopIterationNoBuffer = 3

There is no explanation of these values in https://github.com/proxy-wasm/spec/tree/master/abi-versions/vNEXT either (for example, see proxy-wasm/spec#7 )

I suspect these values are defined at https://github.com/envoyproxy/envoy/blob/master/include/envoy/http/filter.h and that my use of the runtime must abide by the rules of https://www.envoyproxy.io/docs/envoy/latest/faq/extensions/contract.html?highlight#is-there-a-contract-my-http-filter-must-adhere-to

It would help a lot if this repository copied or linked to the adjacent Envoy filter documentation, if applicable. I have never written a native Envoy filter and lacking the context around the conventions of filter writing impedes my use of AssemblyScript.

@yuval-k
Copy link
Member

yuval-k commented Aug 31, 2020

Yes, the semantics are indeed very similar to a native envoy filter (i.e. no co-routine magic).

I will look into improving the docs and adding more examples

@esnible
Copy link
Author

esnible commented Aug 31, 2020

Feel free to cc me if you want a review of doc changes. I feel like this repo will become important to the Istio project.

I considered doing a PR myself but I was unsure if it was reasonable to copy text from https://github.com/envoyproxy/envoy/blob/master/include/envoy/http/filter.h or if it was required that all documentation comments be original to Solo.

@esnible
Copy link
Author

esnible commented Sep 3, 2020

The C++ example at https://github.com/envoyproxy/envoy-wasm/blob/master/examples/wasm/envoy_filter_http_wasm_example.cc#L62 includes the following code to log the HTTP body:

  auto body = getBufferBytes(WasmBufferType::HttpRequestBody, 0, body_buffer_length);
  LOG_ERROR(std::string("onRequestBody ") + std::string(body->view()));

I tried to simulate this using the runtime:

    // The definition of WasmBufferType::HttpRequestBody is in
    // https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/blob/master/proxy_wasm_common.h
    let WasmBufferType_HttpRequestBody = 0
    var body = get_buffer_bytes(WasmBufferType_HttpRequestBody, 0, <u32>body_buffer_length)
    log(LogLevelValues.warn, "context id: " + this.context_id.toString() + "   : past get_buffer_bytes invocation")

The get_buffer_bytes seems to work; the past get_buffer_bytes invocation is logged, but immediately after it now logs critical envoy wasm wasm log: at: ~lib/rt/pure.ts(122:14)

What would be a correct Proxy-Runtime equivalent of the Envoy example?

@esnible
Copy link
Author

esnible commented Sep 5, 2020

See envoyproxy/envoy-wasm#634 for a discussion of difficulties with runtime state and http invocation. I am not having struggles with this runtime, but with Envoy Wasm itself. Envoy is segfaulting a lot. Any guidance?

Many AssemblyScript developers are coming from the browser world where script errors don't crash the browser.

@yuval-k
Copy link
Member

yuval-k commented Sep 9, 2020

like you mention, not much we can do to fix envoy crashes from the this code...

@esnible
Copy link
Author

esnible commented Sep 14, 2020

@yuval-k Can you give an example of how to get the httpCall() response body as a string in the callback?

I am getting a response with body_size 91. I want the body in a string. I tried and failed with

          var swd = get_status();
          var body = String.UTF8.decode(swd.data)

and

          let WasmBufferType_HttpCallResponseBody = 4
          var abbody = get_buffer_bytes(WasmBufferType_HttpCallResponseBody, 0, <u32>body_size)
          var body = String.UTF8.decode(abbody)

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

2 participants