Skip to content
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

feat(transport): Log DirectPath misconfiguration #2225

Merged
merged 9 commits into from
Nov 6, 2023

Conversation

mohanli-ml
Copy link
Contributor

We met issues where customers wanted to use DirectPath, but DirectPath was misconfigured and it took 2 weeks for debugging. So we want to add WARNING logs if DirectPath flag/option is set but DirectPath is not used. Issue: googleapis/sdk-platform-java#2164.

Java PR: googleapis/sdk-platform-java#2105.

Note that the log is added when a channel is created because we need to check the OAuth token, which means it will be logged every channel. This is a bad behavior if customer has a large channel pool size. Ideally I want to use something like LOG_EVERY_N_SEC, and I found rate.Sometimes can do this. Cody, do you have suggestions here?

@codyoss @frankyn

@mohanli-ml mohanli-ml requested a review from a team as a code owner October 17, 2023 18:43
} else {
// Case 2: credential is not correctly set
if !isTokenSourceDirectPathCompatible(ts, o) {
log.Print("WARNING: DirectPath is misconfigured. Please make sure the token source is fetched from GCE metadata server and the default service account is used")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does a user do this correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCS client should set the AllowNonDefaultServiceAccount option to true, https://github.com/googleapis/google-api-go-client/blob/main/transport/grpc/dial.go#L269, and customers do not need to worry about this.

transport/grpc/dial.go Outdated Show resolved Hide resolved
transport/grpc/dial.go Outdated Show resolved Hide resolved
@codyoss
Copy link
Member

codyoss commented Oct 19, 2023

If we are going to start logging about this I think we need a nice section in the package docs on how to configure this all correctly. Also logging is not super ideal today because the way this is being done a user could shut off all logging that uses the standard library or keep it all on. Let me think about this. Are we sure we don't want to return an error for misconfiguration? What state will there app be in if this is not working correctly?

@mohanli-ml
Copy link
Contributor Author

If we are going to start logging about this I think we need a nice section in the package docs on how to configure this all correctly.

I am not sure about what are the "package docs" you pointed to. My understanding is that each DirectPath service (GCS, CBT, CS) will publish its own doc to its customers.

Are we sure we don't want to return an error for misconfiguration? What state will there app be in if this is not working correctly?

The app will use CloudPath if DirectPath misconfiguration happens. The purpose here is to give a hint to the customers who want to use DirectPath but traffic is actually CloudPath.

transport/grpc/dial.go Outdated Show resolved Hide resolved
transport/grpc/dial.go Outdated Show resolved Hide resolved
transport/grpc/dial.go Show resolved Hide resolved
Copy link
Member

@frankyn frankyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @mohanli-ml

@frankyn
Copy link
Member

frankyn commented Nov 1, 2023

We are pending approval from @quartzmo

@mohanli-ml
Copy link
Contributor Author

We are pending approval from @quartzmo

Can I get some help about how to limit the log? Is rate.Sometimes the right thing to use?

Note that the log is added when a channel is created because we need to check the OAuth token, which means it will be logged every channel. This is a bad behavior if customer has a large channel pool size. Ideally I want to use something like LOG_EVERY_N_SEC, and I found rate.Sometimes can do this.

@quartzmo
Copy link
Member

quartzmo commented Nov 2, 2023

Can I get some help about how to limit the log? Is rate.Sometimes the right thing to use?

Yes, I believe that is a good solution. I have not yet personally used it in production however.

@mohanli-ml
Copy link
Contributor Author

I added the rate.Sometimes to limit the log. PTAL. Thanks!

@frankyn frankyn requested a review from quartzmo November 2, 2023 21:05
@frankyn
Copy link
Member

frankyn commented Nov 2, 2023

@mohanli-ml IIUC you have to do this because Go doesn't have a similar option to what you did with Java in the constructor? I would think you could check this once without having to do it for every channel instantiation.

@mohanli-ml
Copy link
Contributor Author

@mohanli-ml IIUC you have to do this because Go doesn't have a similar option to what you did with Java in the constructor? I would think you could check this once without having to do it for every channel instantiation.

The credential code for Java and Go is a bit different. In Java, the credential is passed to the builder, so the builder can do the check. In Go the credential is created during channel construction, so builder does not have this information.

Anyways the code will not do the check for every channel instantiation, it is limited to every second.

@@ -296,6 +304,24 @@ func checkDirectPathEndPoint(endpoint string) bool {
return true
}

func logDirectPathMisconfig(endpoint string, ts oauth2.TokenSource, o *internal.DialSettings) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for this function in case changes are made to this code there's expectation on what's expected for this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. PTAL.

Copy link
Member

@frankyn frankyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mohanli-ml one more approval from @quartzmo and let's ship it.

@mohanli-ml
Copy link
Contributor Author

I do not have the access to merge. @quartzmo Chris, can you help? Thanks!

@noahdietz noahdietz added the automerge Merge the pull request once unit tests and other checks pass. label Nov 6, 2023
@noahdietz
Copy link
Contributor

I do not have the access to merge. @quartzmo Chris, can you help? Thanks!

I've added the automerge label.

@gcf-merge-on-green gcf-merge-on-green bot merged commit 85e85ad into googleapis:main Nov 6, 2023
5 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Nov 6, 2023
@noahdietz
Copy link
Contributor

FYI @mohanli-ml this will be in v0.150.0 #2244

gcf-merge-on-green bot pushed a commit that referenced this pull request Nov 6, 2023
🤖 I have created a release *beep* *boop*
---


## [0.150.0](https://github.com/googleapis/google-api-go-client/compare/v0.149.0...v0.150.0) (2023-11-06)


### Features

* **all:** Auto-regenerate discovery clients ([#2243](https://github.com/googleapis/google-api-go-client/issues/2243)) ([2ce2d2d](https://github.com/googleapis/google-api-go-client/commit/2ce2d2d63343cae224e0f44f37d0426e9c7acbaa))
* **all:** Auto-regenerate discovery clients ([#2245](https://github.com/googleapis/google-api-go-client/issues/2245)) ([5693997](https://github.com/googleapis/google-api-go-client/commit/56939974844fd102839077f56ca84454458749f2))
* **all:** Auto-regenerate discovery clients ([#2246](https://github.com/googleapis/google-api-go-client/issues/2246)) ([8bfbeac](https://github.com/googleapis/google-api-go-client/commit/8bfbeaca4cb80ffe972d56762c832ed31785e8ca))
* **all:** Auto-regenerate discovery clients ([#2249](https://github.com/googleapis/google-api-go-client/issues/2249)) ([b56da3d](https://github.com/googleapis/google-api-go-client/commit/b56da3d6d7c0ad083d8835dead8f681de263fa39))
* **all:** Auto-regenerate discovery clients ([#2250](https://github.com/googleapis/google-api-go-client/issues/2250)) ([c08d405](https://github.com/googleapis/google-api-go-client/commit/c08d405c38ecd133175b932232211e046c4aa07c))
* **all:** Auto-regenerate discovery clients ([#2252](https://github.com/googleapis/google-api-go-client/issues/2252)) ([7529003](https://github.com/googleapis/google-api-go-client/commit/752900316914347301220b5f5dc2eb5eea2a8325))
* **transport:** Log DirectPath misconfiguration ([#2225](https://github.com/googleapis/google-api-go-client/issues/2225)) ([85e85ad](https://github.com/googleapis/google-api-go-client/commit/85e85ad04e28b434dd731c3b537d0fc35ff3639a))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants