/service-extensions-samples

Code Samples and Recipes for Google Cloud Service Extensions

Primary LanguageC++Apache License 2.0Apache-2.0

Google Cloud Service Extensions Samples

Recipes and code samples for Google Cloud Service Extensions.

Each recipe has an example plugin written in Rust and C++, and an accompanying unit test that verifies both.

Testing

Tests (and thus plugins) can be invoked as follows:

$ bazelisk test --test_output=all --define engine=v8 samples/...

In support of unit testing, this repo contains an HttpTest fixture with a TestWasm host implementation and TestHttpContext stream handler. These minimal implementations loosely match GCP Service Extension execution environment. The contexts implement the ABI / feature set described below (mainly HTTP headers and logging), but often in a simple way (behaviors may not match GCP exactly).

Samples & Recipes

The samples folder contains Samples & Recipes to use as a reference for your own plugin. Extend them to fit your particular use case.

Feature set / ABI

Service Extensions are compiled against the ProxyWasm ABI, described here: https://github.com/proxy-wasm/spec/tree/master/abi-versions/vNEXT

Service Extensions currently support a subset of the ProxyWasm spec. Support will grow over time. The current feature set includes:

  • Root context lifecycle callbacks
    • on_context_create
    • on_vm_start
    • on_configure
    • on_done
    • on_delete
  • Stream context lifecycle callbacks
    • on_context_create
    • on_done
    • on_delete
  • Stream context HTTP callbacks
    • on_request_headers
    • on_response_headers
  • Stream context HTTP methods
    • send_local_response
    • get__header_map_value, add_header_map_value, replace_header_map_value, remove_header_map_value
    • get_header_map_pairs, set_header_map_pairs
    • get_header_map_size
  • Other methods
    • log
    • get_current_time_nanoseconds (frozen per stream)
    • get_property ("plugin_root_id" only)
    • get_buffer_status, get_buffer_bytes (PluginConfiguration only)

License

All recipes and samples within this repository are provided under the Apache 2.0 license. Please see the LICENSE file for more detailed terms and conditions.

Code of Conduct

For our code of conduct, see Code of Conduct.

Contributing

Contributions welcome! See the Contributing Guide.

TODO