googleapis / python-api-core

https://googleapis.dev/python/google-api-core/latest
Apache License 2.0
118 stars 85 forks source link

Enable DirectPath support for gRPC workflows #482

Closed dilipped closed 7 months ago

dilipped commented 1 year ago

Is your feature request related to a problem? Please describe. The current behavior for grpc does not utilize DirectPath. DirectPath leads to improved latency for request originating from GCE VMs and gcloud storage relies on this feature.

Describe the solution you'd like Two changes are needed:

  1. Replace: https://github.com/googleapis/python-api-core/blob/b6eb6dee2762b602d553ace510808afd67af461d/google/api_core/grpc_helpers.py#L267 with:

    if compute_engine_channel_credentials_requested:
    return grpc.compute_engine_channel_credentials(google_auth_credentials)
    else:
    grpc.composite_channel_credentials(ssl_credentials, google_auth_credentials)

    where, compute_engine_channel_credentials_requested will be a bool passed to the create_channel call. Alternatively, it can rely on the env variable like it's done for other languages

  2. Add the google-c2p resolver. This can be similar to how other languages e.g. go handles it https://github.com/googleapis/google-api-go-client/blob/8d8f0a70d0bd6ba4daaa08370d1420f759ff7f9d/transport/grpc/dial.go#L182

    Describe alternatives you've considered For #2 above, we can potentially update the GAPIC client generator to create the host name with google-c2p:/// prefixed. But I think given that all other languages are handling it in the middleware, it is appropriate to make this change in this library.

    Additional context There is an internal bug related to this, but I'm not sure if I link it on a public repo.

daniel-sanche commented 1 year ago

+1, this change is also likely needed for the new BigTable library

atulep commented 1 year ago

Can you include the link to DirectPath docs ?

parthea commented 1 year ago

Googlers see go/enable-directpath-grpc-python