Kong / ngx_wasm_module

Nginx + WebAssembly
Apache License 2.0
79 stars 7 forks source link

Support remote cluster call in proxywasm go-sdk DispatchHttpCall? #563

Closed ray1888 closed 2 months ago

ray1888 commented 2 months ago

i cant use the go code below with envoy config which specified cluster

if _, err := proxywasm.DispatchHttpCall("acl-service", [][2]string{
        {":path", "/api/v1/match"},
        {":method", "POST"},
        {":scheme", "http"},
        {":authority", "*"},
    }, body, nil,
        3000, httpCallResponseCallback); err != nil {
        proxywasm.LogCriticalf("dipatch httpcall failed: %v", err)
        return types.ActionContinue
    }

// Envoy Config

static_resources:
  listeners:
    - name: main
      address:
        socket_address:
          address: 0.0.0.0
          port_value: 18000
      filter_chains:
        - filters:
            - name: envoy.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                stat_prefix: ingress_http
                codec_type: auto
                route_config:
                  name: local_route
                  virtual_hosts:
                    - name: local_service
                      domains:
                        - "*"
                      routes:
                        - match:
                            prefix: "/"
                          route:
                            cluster: normal_service
                http_filters:
                  - name: envoy.filters.http.wasm
                    typed_config:
                      "@type": type.googleapis.com/udpa.type.v1.TypedStruct
                      type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
                      value:
                        config:
                          configuration:
                            "@type": "type.googleapis.com/google.protobuf.StringValue"
                            value: |
                              {"acl_service_host":"127.0.0.1", "acl_service_port":"10000", "cluster_name":"acl-service"}
                          vm_config:
                            runtime: "envoy.wasm.runtime.v8"
                            code:
                              local:
                                filename: "./build/gitee-acl.wasm"
                            configuration:
                              "@type": "type.googleapis.com/google.protobuf.StringValue"
                              value: |
                                {}

                  - name: envoy.filters.http.router
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

  clusters:
    - name: normal_service
      connect_timeout: 5000s
      type: strict_dns
      lb_policy: round_robin
      load_assignment:
        cluster_name: httpbin
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      address: 127.0.0.1
                      port_value: 10001
    - name: acl-service
      connect_timeout: 5000s
      type: strict_dns
      lb_policy: round_robin
      load_assignment:
        cluster_name: httpbin
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      address: 127.0.0.1
                      port_value: 10000

admin:
  access_log_path: "/dev/null"
  address:
    socket_address:
      address: 0.0.0.0
      port_value: 8001

but i can't use kong upstream to call a remote cluster , it can't find it anywhere

_format_version: "1.1"
_transform: true

services:
- name: demo
  url: http://my-service
  routes:
  - name: my-route
    paths:
    - /
    strip_path: false
    filter_chains:
    - filters:
      - name: gitee-acl
        config: 
          cluster_name: acl-service
          acl_service_host: 127.0.0.1
          acl_service_port: "10000"

upstreams:
  - name: my-service
    targets:
      - target: 127.0.0.1:10001
        weight: 100
  - name: acl-service
    targets:
      - target: 127.0.0.1:10000
        weight: 100

kong calling plugin error is below picture

image

is there any support of this remote cluster call in ngx_wasm_module implemetation?

thibaultcha commented 2 months ago

The module does support external dispatch calls (proxywasm.DispatchHttpCall) but not via "cluster name". Instead, directly pass an IP address or a hostname to the call, like so: proxywasm.DispatchHttpCall(127.0.0.1:10000) or proxywasm.DispatchHttpCall(acl-service.com). Kong does not support specifying service clusters names for external HTTP calls (whether in Lua or in Wasm), and neither does this module by itself.