-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
alts: Read max number of concurrent ALTS handshakes from environment variable. #6267
alts: Read max number of concurrent ALTS handshakes from environment variable. #6267
Conversation
@easwars Would you be able to take a look at this PR when you have a chance? :) |
// handshakes. | ||
maxPendingHandshakes = 100 | ||
defaultMaxPendingHandshakes = 100 | ||
maxConcurrentHandshakesEnvVariable = "GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES" |
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.
Please take a look at the following files to get an idea of how we handle env vars in grpc-go:
https://github.com/grpc/grpc-go/blob/master/internal/envconfig/envconfig.go
https://github.com/grpc/grpc-go/blob/master/internal/envconfig/xds.go
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.
Thanks for the pointers! I've cleaned up the PR accordingly. :)
internal/envconfig/alts.go
Outdated
// maximum number of concurrent ALTS handshakes that can be performed. | ||
// Its value is read and kept in the variable | ||
// ALTSMaxConcurrentHandshakes. | ||
ALTSMaxConcurrentHandshakesEnv = "GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES" |
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 there a reason to export this const? If not, it can be inline into the var definition on line 33.
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.
Done.
internal/envconfig/alts.go
Outdated
// Its value is read and kept in the variable | ||
// ALTSMaxConcurrentHandshakes. | ||
ALTSMaxConcurrentHandshakesEnv = "GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES" | ||
altsDefaultMaxConcurrentHandshakes = uint64(100) |
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.
Same with this one. This can be inlined as well.
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.
Done.
internal/envconfig/alts.go
Outdated
var ( | ||
// ALTSMaxConcurrentHandshakes is the maximum number of concurrent ALTS | ||
// handshakes that can be performed. | ||
ALTSMaxConcurrentHandshakes = uint64FromEnv(ALTSMaxConcurrentHandshakesEnv, altsDefaultMaxConcurrentHandshakes, uint64(1), altsDefaultMaxConcurrentHandshakes) |
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.
Are these type conversions to uint64
required? uint64FromEnv
is defined as:
func uint64FromEnv(envVar string, def, min, max uint64) uint64 { ... }
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.
Good call, fixed.
if concurrentHandshakes < 0 { | ||
mu.Unlock() | ||
panic("bad release") | ||
} | ||
mu.Unlock() | ||
} |
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 it possible to use a weighted semaphore type provided by the sync
package, which does exactly what you want in here. See: https://pkg.go.dev/golang.org/x/sync/semaphore.
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.
Great suggestion! Done.
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
Waiting on #6300 before coming back to this. |
…into alts-read-envvar
…into alts-read-envvar
Thanks for the great suggestions @easwars and apologies for the delay: your suggestion to use a weight semaphore was a great one, but I wanted to add another e2e test to ensure correctness and it took a little while to get it working as expected. :) |
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.
Why are all these go.mod
changes needed? That seems unexpected, given that all the code changes are in the main module.
credentials/alts/alts_test.go
Outdated
// handshake begins. If vmOnGCP is not reset and this test is run | ||
// anywhere except for a GCP VM, then the ALTS handshake will | ||
// immediately fail. | ||
once.Do(func() {}) |
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.
Should this just go into an init()
? Then it doesn't need to be repeated.
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.
Good call, done.
internal/envconfig/alts.go
Outdated
@@ -0,0 +1,25 @@ | |||
/* |
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.
Please don't create a new file for this one new variable.. Just put it in envconfig.go
.
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.
Sure thing, done.
…into alts-read-envvar
…into alts-read-envvar
Sorry about that, not sure what happened there. This should all be cleaned up now. |
Thanks for the review! |
This mimics the existing functionality for Java (grpc/grpc-java#10016) and for C++ (grpc/grpc#32672). When the environment variable is not set, the functionality is unchanged.
Along the way, we remove 2 obsolete TODOs in
handshaker.go
.RELEASE NOTES:
GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES
env var