Skip to content

Commit f6fe6c2

Browse files
committed
Add doc about gRPC (lack of) compatibility and migration path
1 parent b11a245 commit f6fe6c2

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

docs/grpc-compatibility.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# gRPC compatibility
2+
3+
Connect-Python currently does not support the gRPC protocol due to lack of support for HTTP/2 trailers
4+
in the Python ecosystem. If you have an existing codebase using grpc-python and want to introduce Connect
5+
in a transition without downtime, you will need a way for the gRPC servers to be accessible from both
6+
gRPC and Connect clients at the same time. envoy is a widely used proxy server with support for translating
7+
the Connect protocol to gRPC via the [Connect-gRPC Bridge](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/connect_grpc_bridge_filter).
8+
9+
For example, if you have a gRPC server currently listening on port 8080, you update it to use port 8081
10+
and expose the service for both Connect and gRPC clients on port 8080 with this config.
11+
12+
```yaml
13+
admin:
14+
address:
15+
socket_address: { address: 0.0.0.0, port_value: 9090 }
16+
17+
static_resources:
18+
listeners:
19+
- name: listener_0
20+
address:
21+
socket_address: { address: 0.0.0.0, port_value: 8080 }
22+
filter_chains:
23+
- filters:
24+
- name: envoy.filters.network.http_connection_manager
25+
typed_config:
26+
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
27+
stat_prefix: ingress_http
28+
codec_type: AUTO
29+
route_config:
30+
name: local_route
31+
virtual_hosts:
32+
- name: local_service
33+
domains: ["*"]
34+
routes:
35+
- match: { prefix: "/" }
36+
route: { cluster: service_0 }
37+
http_filters:
38+
- name: envoy.filters.http.connect_grpc_bridge
39+
typed_config:
40+
"@type": type.googleapis.com/envoy.extensions.filters.http.connect_grpc_bridge.v3.FilterConfig
41+
- name: envoy.filters.http.grpc_web
42+
typed_config:
43+
"@type": type.googleapis.com/envoy.extensions.filters.http.grpc_web.v3.GrpcWeb
44+
- name: envoy.filters.http.router
45+
typed_config:
46+
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
47+
clusters:
48+
- name: service_0
49+
connect_timeout: 0.25s
50+
type: STRICT_DNS
51+
lb_policy: ROUND_ROBIN
52+
load_assignment:
53+
cluster_name: service_0
54+
endpoints:
55+
- lb_endpoints:
56+
- endpoint:
57+
address:
58+
socket_address:
59+
address: 127.0.0.1
60+
port_value: 8081
61+
typed_extension_protocol_options:
62+
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
63+
"@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
64+
explicit_http_config:
65+
http2_protocol_options:
66+
max_concurrent_streams: 100
67+
```
68+
69+
Refer to [envoy docs](https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/security/ssl) for more configuration such
70+
as TLS.
71+
72+
## Migration
73+
74+
Migrating from grpc-python to Connect using envoy largely involves first adding envoy in front of the server,
75+
then migrating clients to Connect, and finally migrating servers to Connect and removing envoy.
76+
77+
The general code structure of grpc-python and Connect are very similar - if your code is configured to use a
78+
type checker, any changes to parameter names and such should be quite easy to spot.
79+
80+
1. Reconfigure your gRPC servers to include envoy in front of the server port with a config similar to above.
81+
For cloud deployments, this often means using functionality for sidecar containers.
82+
83+
1. Begin generating code with `protoc-gen-connect-python`.
84+
85+
1. Migrate clients to use Connect. Replace any special configuration of `ManagedChannel` with configured `httpx.Client` or
86+
`httpx.AsyncClient` and switch to Connect's generated client types. If passing `metadata` at the call site, change
87+
to `headers` - lists of string tuples can be passed directly to a `Headers` constructor, or can be changed to a raw
88+
dictionary. Update any error handling to catch `ConnectError`.
89+
90+
1. Complete deployment of all servers using Connect client. After this is done, your gRPC servers will only
91+
be receiving traffic using the Connect protocol.
92+
93+
1. Migrate service implementations to Connect generated stubs. It is recommended to extend the protocol classes
94+
to have type checking find differences in method names. Change uses of `abort` to directly `raise ConnectError` -
95+
for Connect services, it will be uncommon to pass the `RequestContext` into business logic code.
96+
97+
1. Reconfigure server deployment to remove the envoy proxy and deploy. You're done! You can stop generating code with
98+
gRPC.

0 commit comments

Comments
 (0)