http: add per-cluster upstream client codec factory seam
Commit Message: http: add per-cluster upstream client codec factory seam
Additional Description:
Adds Http::ClientCodecFactory, an optional per-cluster extension point for building the upstream
(client) HTTP codec. It is discovered from typed_extension_protocol_options and surfaced via a new
non-pure ClusterInfo::upstreamHttpClientCodecFactory() accessor that defaults to empty.
CodecClientProd invokes the factory when present, handing it a thunk that builds the stock codec,
so an implementation can either decorate the stock codec or return a fresh one. With no factory
configured the stock codec is built exactly as before and behavior is unchanged.
Motivating use case: reverse tunnels invert the HTTP roles -- the connection is dialed from the
downstream to the upstream, but HTTP requests then flow from the upstream to the downstream over
that tunnel, so the upstream is the HTTP/2 client and the downstream is the HTTP/2 server. Graceful
drain of such a tunnel needs cooperation in both directions and both land on the upstream (client)
codec: when the upstream is draining it must signal the downstream to dial a replacement connection
while in-flight requests finish; when the downstream is draining it must tell the upstream to stop
sending new requests and let the downstream re-establish, again finishing in-flight requests.
Neither is expressible with the stock upstream codec, and Envoy currently has no per-cluster hook to
substitute the upstream (client) codec (CodecClientProd hard-codes it by protocol). This change
adds that hook generically; the reverse-tunnel codec that uses it is a follow-up change.
Reverse-tunnel implementation that uses this seam (in the ivpr/envoy fork): the upstream drain-aware client codec (https://github.com/ivpr/envoy/pull/4) and the downstream drain-aware HCM that dials a replacement tunnel (https://github.com/ivpr/envoy/pull/5).
Reverse-tunnel graceful drain (sequence diagram)
sequenceDiagram
autonumber
participant D as Downstream
participant U as Upstream
Note over D,U: Reverse tunnel setup - unlike a normal hop, the downstream dials OUT to the upstream
D->>U: open TCP connection and initiate reverse tunnel
U-->>D: tunnel established
Note over D,U: On the established tunnel the upstream is the HTTP/2 client and the downstream is the HTTP/2 server, so requests flow from upstream to downstream
U->>D: request over tunnel
D-->>U: 200
Note over D,U: Upstream graceful drain
U->>D: GOAWAY - drain signal toward downstream
D->>D: dial a replacement tunnel to a healthy upstream
U->>D: in-flight request continues on the old tunnel
D-->>U: 200
Note over D,U: old tunnel closes once idle, new requests use the replacement
Note over D,U: Downstream graceful drain
D->>U: GOAWAY - tell upstream to stop sending new requests
U->>U: drain pool, route new requests to the replacement tunnel
U->>D: in-flight request continues on the old tunnel
D-->>U: 200
Note over D,U: downstream re-establishes, old tunnel closes once idle
Risk Level: Low -- new, opt-in per-cluster extension point. When no factory is configured the stock codec is used and there is no behavior change.
Testing: //test/common/http:codec_client_test covers the unchanged no-factory path. A dedicated
unit test for the factory-injection path is a planned follow-up.
Docs Changes: None (the new interface is documented inline in envoy/http/client_codec_factory.h).
Release Notes: None (extension point only; no user-facing behavior change on its own).
Platform Specific Features: None.
Runtime guard: None (this PR adds no runtime-guarded behavior).
API Considerations: No xDS/proto API changes. Adds one new C++ extension interface
(envoy/http/client_codec_factory.h) and a non-pure ClusterInfo::upstreamHttpClientCodecFactory()
accessor that defaults to empty, so existing ClusterInfo implementations are unaffected.
@agrawroh / @basundhara-c Can you please review and assign to folks who can review this
/gemini-review
/retest
/gemini review
/retest
/gemini review
/gemini review
/assign @yanavlasov
@yanavlasov Can you please review this
/retest