Saturday, March 09, 2019

Key components of Envoy - making routing decisions in Envoy with LUA



Shows some key parts of the Envoy architecture.   Envoy lets you create LUA filters that can programmatically determine routing paths.

 https://www.envoyproxy.io/docs/envoy/latest/configuration/http_filters/lua_filter

The HTTP Lua filter allows Lua scripts to be run during both the request and response flows. LuaJITis used as the runtime. Because of this, the supported Lua version is mostly 5.1 with some 5.2 features. See the LuaJIT documentation for more details.

..


  • Inspection of headers, body, and trailers while streaming in either the request flow, response flow, or both.
  • Modification of headers and trailers.
  • Blocking and buffering the full request/response body for inspection.
  • Performing an outbound async HTTP call to an upstream host. Such a call can be performed while buffering body data so that when the call completes upstream headers can be modified.
  • Performing a direct response and skipping further filter iteration. For example, a script could make an upstream HTTP call for authentication, and then directly respond with a 403 response code.

In a dynamic system that can change in response to request data, the buffering of body data could hold back a request from being processed until 2 things happen:

1. the request is tagged or categorized based on content
2. the routing paths for that tag are created

Filters can communicate and pass data to one another.  This could make it possible to create "divide and conquer" type logic where a single filter does not contain all the business logic.  





An example of using a Lua library to process an HTTP service call from inside a Lua script.





https://istio.io/docs/reference/config/istio.networking.v1alpha3/#EnvoyFilter
The following example for Kubernetes enables Envoy’s Lua filter for all inbound calls arriving at service port 8080 of the reviews service pod with labels “app: reviews”.
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: reviews-lua
spec:
  workloadLabels:
    app: reviews
  filters:
  - listenerMatch:
      portNumber: 8080
      listenerType: SIDECAR_INBOUND #will match with the inbound listener for reviews:8080
    filterName: envoy.lua
    filterType: HTTP
    filterConfig:
      inlineCode: |
        ... lua code ...

No comments: