You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
balancer: introduce env flag for case-sensitive registry (#8837)
Part of #5288
Follow up of PR: #6647
This PR introduces the
`GRPC_GO_EXPERIMENTAL_CASE_SENSITIVE_BALANCER_REGISTRIES` environment
variable to transition balancer registries to be case-sensitive.
**Default Behavior**:
* The env var is disabled by default.
* The registry remains case-insensitive (legacy behavior) and a warning
is logged if a balancer name contains uppercase letters, notifying users
of the upcoming change.
RELEASE NOTES:
* balancer: grpc will log a warning if balancer registries are used with
uppercase letter(s).
Copy file name to clipboardExpand all lines: balancer/balancer.go
+17-15Lines changed: 17 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,7 @@ import (
33
33
estats "google.golang.org/grpc/experimental/stats"
34
34
"google.golang.org/grpc/grpclog"
35
35
"google.golang.org/grpc/internal"
36
+
"google.golang.org/grpc/internal/envconfig"
36
37
"google.golang.org/grpc/metadata"
37
38
"google.golang.org/grpc/resolver"
38
39
"google.golang.org/grpc/serviceconfig"
@@ -46,21 +47,21 @@ var (
46
47
)
47
48
48
49
// Register registers the balancer builder to the balancer map. b.Name
49
-
// (lowercased) will be used as the name registered with this builder. If the
50
-
// Builder implements ConfigParser, ParseConfig will be called when new service
50
+
// will be used as the name registered with this builder. If the Builder
51
+
// implements ConfigParser, ParseConfig will be called when new service
51
52
// configs are received by the resolver, and the result will be provided to the
52
53
// Balancer in UpdateClientConnState.
53
54
//
54
55
// NOTE: this function must only be called during initialization time (i.e. in
55
56
// an init() function), and is not thread-safe. If multiple Balancers are
56
57
// registered with the same name, the one registered last will take effect.
57
58
funcRegister(bBuilder) {
58
-
name:=strings.ToLower(b.Name())
59
-
ifname!=b.Name() {
60
-
// TODO: Skip the use of strings.ToLower() to index the map after v1.59
61
-
// is released to switch to case sensitive balancer registry. Also,
62
-
// remove this warning and update the docstrings for Register and Get.
63
-
logger.Warningf("Balancer registered with name %q. grpc-go will be switching to case sensitive balancer registries soon", b.Name())
59
+
name:=b.Name()
60
+
if!envconfig.CaseSensitiveBalancerRegistries {
61
+
name=strings.ToLower(name)
62
+
ifname!=b.Name() {
63
+
logger.Warningf("Balancer registered with name %q. grpc-go will be switching to case sensitive balancer registries soon. After 2 releases, we will enable the env var by default.", b.Name())
64
+
}
64
65
}
65
66
m[name] =b
66
67
}
@@ -78,16 +79,17 @@ func init() {
78
79
}
79
80
80
81
// Get returns the resolver builder registered with the given name.
81
-
// Note that the compare is done in a case-insensitive fashion.
82
+
// Note that the compare is done in a case-sensitive fashion.
82
83
// If no builder is register with the name, nil will be returned.
83
84
funcGet(namestring) Builder {
84
-
ifstrings.ToLower(name) !=name {
85
-
// TODO: Skip the use of strings.ToLower() to index the map after v1.59
86
-
// is released to switch to case sensitive balancer registry. Also,
87
-
// remove this warning and update the docstrings for Register and Get.
88
-
logger.Warningf("Balancer retrieved for name %q. grpc-go will be switching to case sensitive balancer registries soon", name)
85
+
if!envconfig.CaseSensitiveBalancerRegistries {
86
+
lowerName:=strings.ToLower(name)
87
+
iflowerName!=name {
88
+
logger.Warningf("Balancer retrieved for name %q. grpc-go will be switching to case sensitive balancer registries soon. After 2 releases, we will enable the env var by default.", name)
0 commit comments