Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions api/v1alpha1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ type Cookie struct {
// - JSON: `endpoint-load-metrics` with JSON-encoded `OrcaLoadReport` proto, e.g., `JSON {"cpu_utilization": 0.3}`.
// - TEXT: `endpoint-load-metrics` with comma-separated key-value pairs, e.g., `TEXT cpu=0.3,mem=0.8`.
//
// By default, Envoy will forward these ORCA response headers/trailers from the upstream service to the downstream client.
// If the downstream client also uses this information for load balancing, it might lead to unexpected behavior.
// To avoid this, you can use the `HTTPRoute` or `BackendTrafficPolicy` to remove the load report headers before sending the response to the client.
// By default, Envoy Gateway removes these ORCA response headers/trailers before sending the response to the client
// (see KeepResponseHeaders). If you need the downstream client to see them, set KeepResponseHeaders to true.
//
// See Envoy proto: envoy.extensions.load_balancing_policies.client_side_weighted_round_robin.v3.ClientSideWeightedRoundRobin
// See ORCA Load Report proto: xds.data.orca.v3.orca_load_report.proto
Expand All @@ -197,9 +196,6 @@ type BackendUtilization struct {
// - 120 => 1.2x
// - 200 => 2.0x
//
// Note: In the internal IR/XDS configuration this value is converted back to a
// floating point multiplier (value / 100.0).
//
// Must be non-negative.
// +kubebuilder:validation:Minimum=0
// +optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12204,9 +12204,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down Expand Up @@ -13686,9 +13683,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down Expand Up @@ -15327,9 +15321,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down Expand Up @@ -16883,9 +16874,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1548,9 +1548,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down Expand Up @@ -2904,9 +2901,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down Expand Up @@ -4517,9 +4511,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down Expand Up @@ -6152,9 +6143,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12203,9 +12203,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down Expand Up @@ -13685,9 +13682,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down Expand Up @@ -15326,9 +15320,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down Expand Up @@ -16882,9 +16873,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1547,9 +1547,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down Expand Up @@ -2903,9 +2900,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down Expand Up @@ -4516,9 +4510,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down Expand Up @@ -6151,9 +6142,6 @@ spec:
- 120 => 1.2x
- 200 => 2.0x

Note: In the internal IR/XDS configuration this value is converted back to a
floating point multiplier (value / 100.0).

Must be non-negative.
format: int32
minimum: 0
Expand Down
21 changes: 21 additions & 0 deletions examples/backend-utilization/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM golang:1.26.1 AS builder

ARG GO_LDFLAGS=""

WORKDIR /workspace
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg/mod \
go mod download

COPY . ./
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 \
GOOS=${TARGETOS} \
GOARCH=${TARGETARCH} \
go build -o /bin/backend-utilization -ldflags "${GO_LDFLAGS}" .

FROM gcr.io/distroless/static-debian11
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /bin/backend-utilization /

ENTRYPOINT ["/backend-utilization"]
9 changes: 9 additions & 0 deletions examples/backend-utilization/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

IMAGE_PREFIX ?= envoyproxy/gateway-
APP_NAME ?= backend-utilization
TAG ?= latest
GO_LDFLAGS ?=

.PHONY: docker-buildx
docker-buildx:
docker buildx build . -t $(IMAGE_PREFIX)$(APP_NAME):$(TAG) --build-arg GO_LDFLAGS="$(GO_LDFLAGS)" --load
3 changes: 3 additions & 0 deletions examples/backend-utilization/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/envoyproxy/gateway-backend-utilization

go 1.26.1
Empty file.
64 changes: 64 additions & 0 deletions examples/backend-utilization/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package main

import (
"encoding/json"
"fmt"
"log"
"maps"
"net/http"
"os"
)

type response struct {
Path string `json:"path"`
Host string `json:"host"`
Method string `json:"method"`
Protocol string `json:"proto"`
Headers map[string][]string `json:"headers"`
Namespace string `json:"namespace"`
Pod string `json:"pod"`
ServiceName string `json:"service_name"`
}

func main() {
podName := os.Getenv("POD_NAME")
namespace := os.Getenv("NAMESPACE")
serviceName := os.Getenv("SERVICE_NAME")
cpuUtil := os.Getenv("ORCA_CPU_UTILIZATION")
if cpuUtil == "" {
cpuUtil = "0.0"
}

orcaHeader := fmt.Sprintf(`JSON {"cpu_utilization": %s, "rps_fractional": 1000}`, cpuUtil)

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("endpoint-load-metrics", orcaHeader)

headers := make(map[string][]string, len(r.Header))
maps.Copy(headers, r.Header)

resp := response{
Path: r.URL.Path,
Host: r.Host,
Method: r.Method,
Protocol: r.Proto,
Headers: headers,
Namespace: namespace,
Pod: podName,
ServiceName: serviceName,
}

if err := json.NewEncoder(w).Encode(resp); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})

log.Printf("Starting ORCA backend on :3000 (cpu_utilization=%s)", cpuUtil)
log.Fatal(http.ListenAndServe(":3000", nil))
}
7 changes: 3 additions & 4 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,8 @@ The backend should report these metrics in header/trailer as one of the followin
- JSON: `endpoint-load-metrics` with JSON-encoded `OrcaLoadReport` proto, e.g., `JSON {"cpu_utilization": 0.3}`.
- TEXT: `endpoint-load-metrics` with comma-separated key-value pairs, e.g., `TEXT cpu=0.3,mem=0.8`.

By default, Envoy will forward these ORCA response headers/trailers from the upstream service to the downstream client.
If the downstream client also uses this information for load balancing, it might lead to unexpected behavior.
To avoid this, you can use the `HTTPRoute` or `BackendTrafficPolicy` to remove the load report headers before sending the response to the client.
By default, Envoy Gateway removes these ORCA response headers/trailers before sending the response to the client
(see KeepResponseHeaders). If you need the downstream client to see them, set KeepResponseHeaders to true.

See Envoy proto: envoy.extensions.load_balancing_policies.client_side_weighted_round_robin.v3.ClientSideWeightedRoundRobin
See ORCA Load Report proto: xds.data.orca.v3.orca_load_report.proto
Expand All @@ -596,7 +595,7 @@ _Appears in:_
| `blackoutPeriod` | _[Duration](https://gateway-api.sigs.k8s.io/reference/1.4/spec/#duration)_ | false | | A given endpoint must report load metrics continuously for at least this long before the endpoint weight will be used.<br />Default is 10s. |
| `weightExpirationPeriod` | _[Duration](https://gateway-api.sigs.k8s.io/reference/1.4/spec/#duration)_ | false | | If a given endpoint has not reported load metrics in this long, stop using the reported weight. Defaults to 3m. |
| `weightUpdatePeriod` | _[Duration](https://gateway-api.sigs.k8s.io/reference/1.4/spec/#duration)_ | false | | How often endpoint weights are recalculated. Values less than 100ms are capped at 100ms. Default 1s. |
| `errorUtilizationPenaltyPercent` | _integer_ | false | | ErrorUtilizationPenaltyPercent adjusts endpoint weights based on the error rate (eps/qps).<br />This is expressed as a percentage-based integer where 100 represents 1.0, 150 represents 1.5, etc.<br />For example:<br />- 100 => 1.0x<br />- 120 => 1.2x<br />- 200 => 2.0x<br />Note: In the internal IR/XDS configuration this value is converted back to a<br />floating point multiplier (value / 100.0).<br />Must be non-negative. |
| `errorUtilizationPenaltyPercent` | _integer_ | false | | ErrorUtilizationPenaltyPercent adjusts endpoint weights based on the error rate (eps/qps).<br />This is expressed as a percentage-based integer where 100 represents 1.0, 150 represents 1.5, etc.<br />For example:<br />- 100 => 1.0x<br />- 120 => 1.2x<br />- 200 => 2.0x<br />Must be non-negative. |
| `metricNamesForComputingUtilization` | _string array_ | false | | Metric names used to compute utilization if application_utilization is not set.<br />For map fields in ORCA proto, use the form "<map_field>.<key>", e.g., "named_metrics.foo". |
| `keepResponseHeaders` | _boolean_ | false | false | KeepResponseHeaders keeps the ORCA load report headers/trailers before sending the response to the client.<br />Defaults to false. |

Expand Down
Loading
Loading