Document/example how to make httpCall out to other service under Consul Envoy Extensions

Hi All,

Does anyone know of an example how to make httpCall out to external service, especially adding the envoy custom cluster (the first argument of the httpCall) within the ServiceDefaults resource?
Example:

apiVersion: consul.hashicorp.com/v1alpha1
kind: ServiceDefaults
metadata:
  name: my-service
spec:
  protocol: http
  envoyExtensions:
  - name: "builtin/lua"
    required: true
    arguments:
      proxyType: "connect-proxy"
      listener: "outbound"
      script: |-
        function envoy_on_request(request_handle)

          -- Make an HTTP call.
          headers, body = request_handle:httpCall(
          "custom-cluster",
          {
            [":method"] = "GET",
            [":path"] = "/api/abc/v1/session",
            [":authority"] = "abc",
            ["authorization"] = abc
          },
          "test",
          5000)

          
          local headers = request_handle:headers()
          for key, value in pairs(headers) do
            request_handle:headers():add(key, value)
          end
        end

Thanks!
~K

I finally was able to get it worked by adding ‘envoy_extra_static_clusters_json’ to ProxyDefaults under config. I hope it’s the right way to do.

@kha7281, I’m glad you were able to figure it out. Confirming that adding the cluster via envoy_extra_static_clusters_json is the right solution. :+1:

1 Like

Glad to hear that! Thank you, @blake
~K

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.