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

alts: Read max number of concurrent ALTS handshakes from environment variable. #6267

Merged
merged 30 commits into from Jun 8, 2023

Conversation

matthewstevenson88
Copy link
Contributor

@matthewstevenson88 matthewstevenson88 commented May 10, 2023

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:

  • alts: add support for GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES env var

@matthewstevenson88 matthewstevenson88 marked this pull request as ready for review May 10, 2023 16:49
@matthewstevenson88
Copy link
Contributor Author

@easwars Would you be able to take a look at this PR when you have a chance? :)

@easwars easwars added this to the 1.56 Release milestone May 10, 2023
// handshakes.
maxPendingHandshakes = 100
defaultMaxPendingHandshakes = 100
maxConcurrentHandshakesEnvVariable = "GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES"
Copy link
Contributor

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

Copy link
Contributor Author

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. :)

// 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"
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// Its value is read and kept in the variable
// ALTSMaxConcurrentHandshakes.
ALTSMaxConcurrentHandshakesEnv = "GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES"
altsDefaultMaxConcurrentHandshakes = uint64(100)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

var (
// ALTSMaxConcurrentHandshakes is the maximum number of concurrent ALTS
// handshakes that can be performed.
ALTSMaxConcurrentHandshakes = uint64FromEnv(ALTSMaxConcurrentHandshakesEnv, altsDefaultMaxConcurrentHandshakes, uint64(1), altsDefaultMaxConcurrentHandshakes)
Copy link
Contributor

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 { ... }

Copy link
Contributor Author

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()
}
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion! Done.

@github-actions
Copy link

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.

@github-actions github-actions bot added the stale label May 16, 2023
@matthewstevenson88
Copy link
Contributor Author

Waiting on #6300 before coming back to this.

@matthewstevenson88
Copy link
Contributor Author

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. :)

@matthewstevenson88
Copy link
Contributor Author

@dfawley It seems @easwars is OOO, would you mind if I re-assign to you to finish the review?

Copy link
Member

@dfawley dfawley left a 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.

// 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() {})
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, done.

@@ -0,0 +1,25 @@
/*
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, done.

@dfawley dfawley assigned matthewstevenson88 and unassigned easwars and dfawley Jun 6, 2023
@matthewstevenson88
Copy link
Contributor Author

Why are all these go.mod changes needed? That seems unexpected, given that all the code changes are in the main module.

Sorry about that, not sure what happened there. This should all be cleaned up now.

@matthewstevenson88
Copy link
Contributor Author

Thanks for the review!

@matthewstevenson88 matthewstevenson88 merged commit 907bdaa into grpc:master Jun 8, 2023
11 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants