-
Notifications
You must be signed in to change notification settings - Fork 123
impl(gax-internal): use universe_domain when creating gRPC/HTTP transport #5302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alvarowolfx
wants to merge
15
commits into
googleapis:main
Choose a base branch
from
alvarowolfx:impl-gax-universe-domain-transport
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e53507e
impl(gax-internal): use universe_domain when creating gRPC/HTTP trans…
alvarowolfx 1383d17
fix: storage test with non gdu universe
alvarowolfx 135cf20
Merge branch 'main' into impl-gax-universe-domain-transport
alvarowolfx b4efc64
impl: add universe domain mismatch err type
alvarowolfx 7f11763
fix: address review comments
alvarowolfx 20eb03d
impl: handle regional endpoint and universe domain
alvarowolfx a582c93
impl: remove universe domain parameter from hostname resolution
alvarowolfx 988e72f
test: add tests to host resolution change
alvarowolfx d5b86c8
Merge branch 'main' into impl-gax-universe-domain-transport
alvarowolfx 94ed0a3
fix: merge with tracing
alvarowolfx d9236b7
fix: clippy all the things
alvarowolfx 4c228fe
Merge branch 'main' into impl-gax-universe-domain-transport
alvarowolfx 7f87714
fix: unwanted changes
alvarowolfx 65b6630
Merge branch 'main' into impl-gax-universe-domain-transport
alvarowolfx 70e57b0
impl: custom universes should also take vpc, regional and locational …
alvarowolfx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ pub mod reqwest; | |
| use crate::as_inner::as_inner; | ||
| use crate::attempt_info::AttemptInfo; | ||
| use crate::observability::{HttpResultExt, RequestRecorder, create_http_attempt_span}; | ||
| use crate::universe_domain::DEFAULT_UNIVERSE_DOMAIN; | ||
| use google_cloud_auth::credentials::{ | ||
| Builder as CredentialsBuilder, CacheableResource, Credentials, | ||
| }; | ||
|
|
@@ -67,6 +68,7 @@ pub struct ReqwestClient { | |
| polling_backoff_policy: Arc<dyn PollingBackoffPolicy>, | ||
| instrumentation: Option<&'static crate::options::InstrumentationClientInfo>, | ||
| _tracing_enabled: bool, | ||
| universe_domain: String, | ||
| transport_metric: Option<crate::observability::TransportMetric>, | ||
| } | ||
|
|
||
|
|
@@ -87,12 +89,13 @@ impl ReqwestClient { | |
| builder = builder.redirect(::reqwest::redirect::Policy::none()); | ||
| } | ||
| let inner = builder.build().map_err(BuilderError::transport)?; | ||
| let host = crate::host::header(config.endpoint.as_deref(), default_endpoint) | ||
| let universe_domain = | ||
| crate::universe_domain::resolve(config.universe_domain.as_deref(), &cred).await?; | ||
| let service_endpoint = default_endpoint.replace(DEFAULT_UNIVERSE_DOMAIN, &universe_domain); | ||
| let host = crate::host::header(config.endpoint.as_deref(), &service_endpoint) | ||
| .map_err(|e| e.client_builder())?; | ||
| let tracing_enabled = crate::options::tracing_enabled(&config); | ||
| let endpoint = config | ||
| .endpoint | ||
| .unwrap_or_else(|| default_endpoint.to_string()); | ||
| let endpoint = config.endpoint.unwrap_or(service_endpoint); | ||
| Ok(Self { | ||
| inner, | ||
| cred, | ||
|
|
@@ -117,6 +120,7 @@ impl ReqwestClient { | |
| .unwrap_or_else(|| Arc::new(ExponentialBackoff::default())), | ||
| instrumentation: None, | ||
| _tracing_enabled: tracing_enabled, | ||
| universe_domain, | ||
| transport_metric: None, | ||
| }) | ||
| } | ||
|
|
@@ -220,7 +224,9 @@ impl ReqwestClient { | |
| url: &str, | ||
| default_endpoint: &str, | ||
| ) -> Result<HttpRequestBuilder> { | ||
| let host = crate::host::header(Some(url), default_endpoint).map_err(|e| e.gax())?; | ||
| let service_endpoint = | ||
| default_endpoint.replace(DEFAULT_UNIVERSE_DOMAIN, &self.universe_domain); | ||
| let host = crate::host::header(Some(url), &service_endpoint).map_err(|e| e.gax())?; | ||
| let builder = self | ||
| .inner | ||
| .request(method, url) | ||
|
|
@@ -581,9 +587,26 @@ mod tests { | |
| use crate::options::ClientConfig; | ||
| use crate::options::InstrumentationClientInfo; | ||
| use google_cloud_auth::credentials::anonymous::Builder as Anonymous; | ||
| use google_cloud_auth::credentials::{CacheableResource, CredentialsProvider}; | ||
| use google_cloud_auth::errors::CredentialsError; | ||
| use http::{HeaderMap, HeaderValue, Method}; | ||
| use scoped_env::ScopedEnv; | ||
| use serial_test::serial; | ||
| use test_case::test_case; | ||
|
|
||
| type AuthResult<T> = std::result::Result<T, CredentialsError>; | ||
| type TestResult = anyhow::Result<()>; | ||
|
|
||
| mockall::mock! { | ||
| #[derive(Debug)] | ||
| Credentials {} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aside, non-blocking: We don't need to define this more than once per crate. And we could even put it in |
||
|
|
||
| impl CredentialsProvider for Credentials { | ||
| async fn headers(&self, extensions: Extensions) -> AuthResult<CacheableResource<HeaderMap>>; | ||
| async fn universe_domain(&self) -> Option<String>; | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn client_http_error_bytes() -> anyhow::Result<()> { | ||
| let http_resp = http::Response::builder() | ||
|
|
@@ -767,6 +790,53 @@ mod tests { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| #[test_case(None, "my-universe-domain.com", "language.my-universe-domain.com", "https://language.my-universe-domain.com"; "default endpoint")] | ||
| #[test_case(Some("https://yet-another-universe-domain.com/"), "yet-another-universe-domain.com", "yet-another-universe-domain.com", "https://yet-another-universe-domain.com/"; "custom endpoint override")] | ||
| #[test_case(Some("https://rep.language.googleapis.com/"), "my-universe-domain.com", "rep.language.googleapis.com", "https://rep.language.googleapis.com/"; "regional endpoint with universe domain")] | ||
| #[test_case(Some("https://us-central1-language.googleapis.com/"), "my-universe-domain.com", "us-central1-language.googleapis.com", "https://us-central1-language.googleapis.com/"; "locational endpoint with universe domain")] | ||
| #[serial] | ||
| async fn host_from_endpoint_with_universe_domain_success( | ||
| endpoint_override: Option<&str>, | ||
| universe_domain: &str, | ||
| expected_host: &str, | ||
| expected_endpoint: &str, | ||
| ) -> TestResult { | ||
| let _env = ScopedEnv::remove("GOOGLE_CLOUD_UNIVERSE_DOMAIN"); | ||
| let universe_domain = universe_domain.to_string(); | ||
| let mut config = ClientConfig::default(); | ||
| config.universe_domain = Some(universe_domain.clone()); | ||
| config.endpoint = endpoint_override.map(String::from); | ||
|
|
||
| let universe_domain_clone = universe_domain.clone(); | ||
| let mut cred = MockCredentials::new(); | ||
| cred.expect_universe_domain() | ||
| .returning(move || Some(universe_domain_clone.clone())); | ||
| config.cred = Some(cred.into()); | ||
|
|
||
| let client = ReqwestClient::new(config, "https://language.googleapis.com").await?; | ||
| assert_eq!(client.universe_domain, universe_domain); | ||
| assert_eq!(client.host, expected_host); | ||
| assert_eq!(client.endpoint, expected_endpoint); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn host_from_endpoint_with_universe_domain_mismatch_fails() -> TestResult { | ||
| let mut config = ClientConfig::default(); | ||
| config.universe_domain = Some("custom.com".to_string()); | ||
| config.cred = Some(Anonymous::new().build()); | ||
|
|
||
| let err = ReqwestClient::new(config, "https://language.googleapis.com") | ||
| .await | ||
| .unwrap_err(); | ||
|
|
||
| assert!(err.is_universe_domain_mismatch(), "{err:?}"); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[test_case(None; "default")] | ||
| #[test_case(Some("localhost:5678"); "custom")] | ||
| #[tokio::test] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is
private.my-custom-ud.coma thing? Orrestricted.my-custom-ud.com?In which case we would want to use like
<service>.my-custom-ud.comas the host, but this would useprivate.my-custom-ud.com.Duckie found b/361611906 for me. Seems like yes?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't be afraid to scrap this whole
origin_and_headerfunction. I wrote it and it was not my finest work.(My memory is that I was trying to make it as efficient as possible, but (1) that is not so important for client-construction vs. like per request, (2) it made the code inflexible.).