Skip to content

Commit dea04cb

Browse files
authored
A89: Backend Service Metric Label (#471)
1 parent 413b966 commit dea04cb

2 files changed

Lines changed: 146 additions & 2 deletions

File tree

A75-xds-aggregate-cluster-behavior-fixes.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,17 @@ priorities.
6262
* [A60: xDS-Based Stateful Session Affinity for Weighted Clusters][A60]
6363
* [A56: Priority LB policy][A56]
6464
* [A61: IPv4 and IPv6 Dualstack Backend Support][A61]
65-
* [A74: xDS Config Tears (pending)][A74]
65+
* [A74: xDS Config Tears][A74]
66+
* [A89: Backend Service Metric Label][A89]
6667

6768
[A37]: A37-xds-aggregate-and-logical-dns-clusters.md
6869
[A50]: A50-xds-outlier-detection.md
6970
[A55]: A55-xds-stateful-session-affinity.md
7071
[A56]: A56-priority-lb-policy.md
7172
[A60]: A60-xds-stateful-session-affinity-weighted-clusters.md
7273
[A61]: A61-IPv4-IPv6-dualstack-backends.md
73-
[A74]: https://github.com/grpc/proposal/pull/404
74+
[A74]: A74-xds-config-tears.md
75+
[A89]: A89-backend-service-metric-label.md
7476

7577
## Proposal
7678

@@ -278,6 +280,14 @@ def Pick(pick_args):
278280
return result
279281
```
280282

283+
#### Changes to Backend Service metric label plumbing
284+
285+
[gRFC A89 Backend Service Metric Label][A89] has a different implementation
286+
approach dependent on whether this gRFC has been implemented. If A89 was
287+
implemented before this gRFC, then backend service plumbing needs to change to
288+
go through the `cds` policy instead of the `xds_cluster_impl` policy, as
289+
documented in A89.
290+
281291
### Temporary environment variable protection
282292

283293
This design makes significant structural changes in the LB policy tree,
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
A89: Backend Service Metric Label
2+
----
3+
* Author(s): [Eric Anderson](https://github.com/ejona86)
4+
* Approver: @markdroth
5+
* Status: Ready for Implementation
6+
* Implemented in: <language, ...>
7+
* Last updated: 2025-04-01
8+
* Discussion at: https://groups.google.com/g/grpc-io/c/s4tm26RiMyI
9+
10+
## Abstract
11+
12+
Add a new optional label to per-call metrics containing the "backend service"
13+
being used for the RPC. When using xDS, the backend service would be the xDS
14+
cluster name.
15+
16+
## Background
17+
18+
[gRFC A78][] added the `grpc.lb.locality` per-call optional label, which also
19+
added the infrastructure to support LBs adding optional labels to per-call
20+
metrics. The optional label can be enabled in the gRPC/OpenTelemetry integration
21+
API added in [gRFC A79][].
22+
23+
Similar to how locality metrics are useful for analyzing _where_ traffic is
24+
being routed, the xDS cluster is useful for knowing _to whom_ it is being
25+
routed. `grpc.target` is generally all that's necessary to know which service is
26+
receiving traffic, but non-deterministic routing in xDS like weighted clusters,
27+
aggregate clusters, and cluster specifier plugins mean different clusters (and
28+
thus potentially different services or service versions) would comingle metrics
29+
unless the selected cluster is added as a label. It can also be helpful to know
30+
the selected cluster to confirm that deterministic routing, like path matching,
31+
is behaving as expected.
32+
33+
### Related Proposals:
34+
* [gRFC A66: OpenTelemetry Metrics][gRFC A66]
35+
* [gRFC A78: gRPC OTel Metrics for WRR, Pick First, and XdsClient][gRFC A78]
36+
* [gRFC A79: Non-per-call Metrics Architecture][gRFC A79]
37+
* [gRFC A75: xDS Aggregate Cluster Behavior Fixes][gRFC A75]
38+
39+
[gRFC A66]: A66-otel-stats.md
40+
[gRFC A78]: A78-grpc-metrics-wrr-pf-xds.md#per-call-metrics
41+
[gRFC A79]: A79-non-per-call-metrics-architecture.md
42+
[gRFC A75]: A75-xds-aggregate-cluster-behavior-fixes.md
43+
44+
## Proposal
45+
46+
### Add grpc.lb.backend_service to per-call metrics
47+
48+
We will add the `grpc.lb.backend_service` optional label to the following
49+
per-call metrics defined in [gRFC A66]:
50+
- `grpc.client.attempt.duration`
51+
- `grpc.client.attempt.sent_total_compressed_message_size`
52+
- `grpc.client.attempt.rcvd_total_compressed_message_size`
53+
54+
Label definition:
55+
56+
| Name | Disposition | Description |
57+
| ----------- | ----------- | ----------- |
58+
| grpc.lb.backend_service | optional | The backend service to which the traffic is being sent. This is relevant when a single channel target can be sent to different sets of servers. When using xDS, this will be the cluster name. When not relevant, the value will be the empty string. |
59+
60+
The value will be communicated to the gRPC OpenTelemetry module by the call
61+
attempt tracer. When an LB policy provides the label value to the tracer it
62+
will do so each pick that the information is available, regardless of the pick's
63+
result. This allows metrics for DEADLINE_EXCEEDED and UNAVAILABLE failures to
64+
include a relevant backend service. It is possible for later picks for the same
65+
RPC to have a different value. This is the case for locality as well, and the
66+
last pick's value should be used by the OpenTelemetry module.
67+
68+
If A75 has not been implemented, the LB policy `xds_cluster_impl` will notify
69+
the call attempt tracer of the `grpc.lb.backend_service` label. The value will
70+
be copied from `xds_cluster_impl`'s service config `cluster` key.
71+
72+
If A75 has been implemented, the LB policy `cds` for non-aggregate clusters will
73+
notify the call attempt tracer of the `grpc.lb.backend_service` label. The value
74+
will be copied from `cds`'s service config `cluster` key.
75+
76+
### Add grpc.lb.backend_service to WRR metrics
77+
78+
We will add the `grpc.lb.backend_service` optional label, with the same
79+
definition as for per-RPC metrics, to all existing WRR metrics defined in [gRFC
80+
A78]:
81+
- `grpc.lb.wrr.rr_fallback`
82+
- `grpc.lb.wrr.endpoint_weight_not_yet_usable`
83+
- `grpc.lb.wrr.endpoint_weight_stale`
84+
- `grpc.lb.wrr.endpoint_weights`
85+
86+
The `weighted_round_robin` LB policy will read a resolver attribute that
87+
indicates the name of the backend service. This resolver attribute should not be
88+
considered limited to xDS. However, only xds will set the attribute at this
89+
time.
90+
91+
If A75 has not been implemented, the LB policy `xds_cluster_impl` will set the
92+
backend service resolver attribute to the same value as used for the per-call
93+
metrics.
94+
95+
If A75 has been implemented, the LB policy `cds` for non-aggregate clusters will
96+
set the backend service resolver attribute to the same value as used for the
97+
per-call metrics.
98+
99+
### Temporary environment variable protection
100+
101+
The new optional label requires calling an API to activate, so environment
102+
variable protection is unnecessary.
103+
104+
## Rationale
105+
106+
We define a new concept "backend service" so that we can add this label to
107+
non-xDS-specific code like the gRPC OpenTelemetry module. "Backend service"
108+
isn't the best of names, but all other names seemed to be obviously worse (e.g.,
109+
cluster) or no better. It is more important that the name not be misunderstood
110+
than for the name to be meaningful.
111+
112+
Prior to A75 the only LB policy with a backend service concept is
113+
`xds_cluster_impl`, as it needs to be below the `priority` policy. After A75
114+
`cds` also have the code to provide the label instead. This has the advantage of
115+
allowing outlier detection to use the backend service in its own metrics.
116+
117+
gRFC A78 added `grpc.lb.locality` to per-call and WRR metrics, and this is
118+
mirroring that approach with backend service. Adding backend service to WRR is
119+
less essential than per-call metrics, simply because the WRR metrics are more
120+
rarely used. But users of WRR would benefit from backend service. In general,
121+
any metrics that have a locality label should probably also have backend
122+
service.
123+
124+
In xDS, which "cluster" is used for a request is ambiguous when using aggregate
125+
clusters, as multiple clusters are involved. For placing in a label, there are
126+
two potential choices: the top-level aggregate cluster and the leaf cluster.
127+
Using the leaf cluster seems to provide the most insight when using aggregate
128+
clusters as failing over to a different priority would be significant. If the
129+
top-level cluster is needed in the future, it can be added as well.
130+
131+
## Implementation
132+
133+
@ejona86 will immediately implement in gRPC Java. Other languages will follow as
134+
able.

0 commit comments

Comments
 (0)