envoyproxy / envoyproxy/gateway

Incorrect `alt_stat_name` generation for multiple backendRefs

Open
#7,008 5 comments 0 reactions 0 assignees View on GitHub
triage
Dominant language
Go
Stars
3k
Forks
864
Avg merge
2d 2h
Merged PRs (30d)
140

Description

#### Description

When configuring an `HTTPRoute/Rule` with multiple `backendRefs` with filters, Envoy’s behaviour for alt_stat_name is incorrect.

* If **none** of the `backendRefs` have filters → Envoy generates a **single cluster** for all backends.
* If **at least one** of the `backendRefs` has a filter → Envoy generates **separate cluster** (one per backend).

This behaviour causes problems when using `alt_stat_name` with `%BACKEND_REFS%`, because it generate alt_stat_name with consolidated name of all backendRef, which removes the visibility between the individual backends.

---

#### Current Behavior

`envoy_cluster_name` is exposed in the following format:

```
%ROUTE_KIND%/%ROUTE_NAMESPACE%/%ROUTE_NAME%/rule/%ROUTE_RULE_NUMBER%
```

**Example:**

```
httproute/my-ns/my-route/rule/0
```

With multiple `backendRefs` and filters, Envoy generates different cluster names per backend:

```
1. httproute/my-ns/my-route/rule/0/backend/0
2. httproute/my-ns/my-route/rule/0/backend/1
```

**Spec example:**

```yaml
spec:
rules:
- backendRefs:
- kind: Service
name: my-svc-primary
port: 8080
weight: 90
- kind: Service
name: my-svc-canary
port: 8080
weight: 10
filters:
- responseHeaderModifier:
add:
- name: served-by
value: canary
type: ResponseHeaderModifier
```

Envoy Gateway recently introduced the support of using `alt_stat_name` with `%BACKEND_REFS%` https://gateway.envoyproxy.io/docs/api/extension_types/#proxymetrics:

```
%ROUTE_KIND%/%ROUTE_NAMESPACE%/%ROUTE_NAME%/rule/%ROUTE_RULE_NUMBER%/%BACKEND_REFS%
```

When multiple backendRefs exist, they are consolidated into a alt_stat_name for both clusters
(_httproute/my-ns/my-route/rule/0/backend/0 and httproute/my-ns/my-route/rule/0/backend/1_)

```
httproute/my-ns/my-route/rule/0/my-ns/my-svc-primary|my-ns/my-svc-canary
```

This consolidation removes visibility into metrics per backend.

---

#### Expected Behavior

Envoy Gateway should generate its own `alt_stat_name` for each cluster like below, when filters are present.

**Example:**

```
httproute/my-ns/my-route/rule/0/my-ns/my-svc-primary
httproute/my-ns/my-route/rule/0/my-ns/my-svc-canary
```

---

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.