EnvoyFilter - redirect Http calls

Hello,

I have a situation where we need to redirect all the calls which contain the string “/checkout/dist” to an external URL which should look like “external.com/xxx/yyy/checkout/dist

TO do this we have written following Envoy filter:

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
  name: envoy-filter-callforward
  namespace: ui-relqa
spec:
  filters:
  - filterConfig:
      inlineCode: |
        function envoy_on_request(request_handle)
          local path= request_handle:headers():get(":path");
          local host= request_handle:headers():get(":authority");
          if path~="/health" then
              request_handle:logWarn("loooking for path");
              request_handle:logWarn(path);
            if string.match(path,"checkout/dist") then
              request_handle:logWarn("inside http call method");
              request_handle:logWarn("looking for host in dev dist");
              request_handle:logWarn(host);
              request_handle:logWarn("loooking for path dev dist");
              request_handle:logWarn(path);

               local auth_host = "external.com"
               local cluster = "outbound|80||external.com"
               local request_headers = {
                [":method"] = "GET",
                [":path"] = "xxx/yyy/" .. path,
                [":authority"] = auth_host
                }

                local request_body = ""
                local timeout = 5000 --ms

                request_handle:logWarn("http call method executed successfully");

                request_handle:httpCall(
                cluster,
                request_headers,
                request_body,
                timeout
                )
              end
            end
            end
    filterName: envoy.lua
    filterType: HTTP
    insertPosition:
      index: FIRST
    listenerMatch:
      listenerType: GATEWAY
      portNumber: 443
  workloadLabels:
    app: istio-ingressgateway

but this is giving me error:

PANIC: unprotected error in call to Lua API ([string "function envoy_on_request(request_handle)..."]:27: http call cluster invalid. Must be configured)

Can anybody tell me what I am doing wrong here and how to correct it.

2 Likes

I have the exact same problem. Were you able to solve this?

I have found that Envoy either needs to discover your “cluster” (I tried adding a service point, it didn’t help) or you need to define one (not to sure how to configure envoy in Istio).