[Improvement]: Load balance across all targets when upstream.main/sandbox uses ref to a multi-target upstream definition

Đang mở
#4,181 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
api, backend

Hướng nghiên cứu

Start in gateway/gateway-controller/pkg/transform/restapi.go at resolveUpstreamURL and the main or sandbox cluster construction around line 676; compare how upstream definitions keep all targets in lines 295-347 and in gateway/gateway-controller/pkg/xds/translator.go around line 649. Trace how the referenced definition's cluster is selected, then check the Envoy route configuration. Done when main and sandbox refs route across every target using its weight, without requiring dynamic-endpoint.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Aspect/API Type/Improvement
Please select the area the issue is related to

Gateway

Please select the aspect the issue is related to

Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)

Suggested Improvement

Current limitation

When upstream.main or upstream.sandbox references an upstream definition with ref, the gateway uses only the first target in that definition and ignores the rest. resolveUpstreamURL returns def.Upstreams[0].Url (gateway/gateway-controller/pkg/transform/restapi.go:781), and the main or sandbox cluster is built with that single endpoint (restapi.go:676).

Nothing tells the user. The deployment succeeds, and an API that lists three backends quietly sends all its traffic to the first one. The only hint is a sentence in the weight field's description in the spec. The obvious reading of a definition with several weighted targets is that the API's traffic is balanced across them.

Today, balancing across targets only works if the user also attaches the dynamic-endpoint policy pointing at the same definition. That's undocumented and not what a user would expect to need.

The gateway already builds a cluster for every upstream definition that keeps all its targets and weights (restapi.go:295-347, gateway/gateway-controller/pkg/xds/translator.go:649). The main and sandbox routes just don't use it.

Reproduced on a running gateway built from main at 9ceea25b8, with two hashicorp/http-echo backends that reply backend-a and backend-b:

apiVersion: gateway.api-platform.wso2.com/v1
kind: RestApi
metadata:
  name: ref-only
spec:
  displayName: ref-only
  version: v1.0
  context: /ref-only/v1.0
  upstreamDefinitions:
    - name: pool
      upstreams:
        - url: http://backend-a:5000
          weight: 50
        - url: http://backend-b:5000
          weight: 50
  upstream:
    main:
      ref: pool
  operations:
    - method: GET
      path: /echo
  • The deployment succeeds (201) with no warning.
  • Of 400 requests to /ref-only/v1.0/echo, all 400 went to backend-a and none to backend-b.
  • In Envoy's /config_dump, the route uses a main cluster that contains only backend-a. The definition's own cluster (upstream_RestApi_<id>_pool) exists with both endpoints weighted 50/50, but nothing routes to it.
  • The same definition behind the dynamic-endpoint policy splits 200/200, so the multi-target cluster itself works.

Suggested improvement

When upstream.main or upstream.sandbox references a definition, route to that definition's own multi-target cluster instead of building a separate single-endpoint cluster from its first URL. The API then load-balances across all targets with their weights, with no extra policy needed.

If that isn't possible yet, at least make the behaviour visible:

  • Reject at deploy time a ref to a definition with more than one target, or return a deployment warning.
  • Document the limitation on upstream.ref, not only on weight.
Related Issues

#4176

Ngôn ngữ chính
Go
Star
85
Fork
137
Merge trung bình
1 ngày 12 giờ
Pull request đã merge (30 ngày)
247

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của wso2/api-platform

Tất cả issue của wso2/api-platform

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.