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
ringhash: allow overriding max ringhash size via environment variable #5884
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* | ||
* Copyright 2022 gRPC authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package envconfig | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"google.golang.org/grpc/internal/grpctest" | ||
) | ||
|
||
type s struct { | ||
grpctest.Tester | ||
} | ||
|
||
func Test(t *testing.T) { | ||
grpctest.RunSubTests(t, s{}) | ||
} | ||
|
||
func (s) TestUint64FromEnv(t *testing.T) { | ||
|
||
var testCases = []struct { | ||
name string | ||
val string | ||
def, min, max uint64 | ||
want uint64 | ||
}{ | ||
{ | ||
name: "error parsing; want default", | ||
val: "asdf", def: 5, want: 5, | ||
}, { | ||
name: "unset; want default", | ||
val: "", def: 5, want: 5, | ||
}, { | ||
name: "too low; want min", | ||
val: "5", min: 10, want: 10, | ||
}, { | ||
name: "too high; want max", | ||
val: "5", max: 2, want: 2, | ||
}, { | ||
name: "in range; good", | ||
val: "17391", def: 13000, min: 12000, max: 18000, want: 17391, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
const testVar = "testvar" | ||
if tc.val == "" { | ||
os.Unsetenv(testVar) | ||
Comment on lines
+64
to
+65
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. Do we really need this special case for empty string? Since the code which reads the env var uses 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. From a blackbox testing perspective, it's an interesting, specific test. But from a whitebox perspective, it's no different. So I could go either way, but I'm inclined to keep it with the former in mind. |
||
} else { | ||
os.Setenv(testVar, tc.val) | ||
} | ||
if got := uint64FromEnv(testVar, tc.def, tc.min, tc.max); got != tc.want { | ||
t.Errorf("uint64FromEnv(%q(=%q), %v, %v, %v) = %v; want %v", testVar, tc.val, tc.def, tc.min, tc.max, got, tc.want) | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,3 +99,9 @@ var ( | |
// C2PResolverTestOnlyTrafficDirectorURI is the TD URI for testing. | ||
C2PResolverTestOnlyTrafficDirectorURI = os.Getenv(c2pResolverTestOnlyTrafficDirectorURIEnv) | ||
) | ||
|
||
// XDSRingHashLimit indicates the maximum ring size which defaults to 4096 but | ||
// may be overridden by setting the environment variable | ||
// "GRPC_XDS_RING_HASH_LIMIT". A hard maximum limit of 8MB and minimum limit | ||
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. RING_HASH_LIMIT is somewhat ambiguous, since this limit really controls the max number of ring hash entries, and only indirectly controls memory (e.g. per-entry memory consumption could be reduced with a revised layout). Note too the 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.
Can you suggest something better? I wanted to avoid something too verbose.
Well, it's apparently not 8 million either, it's 8,388,608. Why did we choose that number (for Java) btw? 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. Oh wait.. we actually NACK for configs > 8M. So probably this is irrelevant to even mention here? 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. In C++, their's a channel option called In Java, the global is So maybe use
Yeah I think it's not really relevant. Though I suppose we could mention that 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.
This is fine since it matches the other languages re: cap/limit, though I find "cap" to be less formal/precise than "limit". Changed. 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. Actually, should we remove "xds" from the name, too, since the LB policy name doesn't have "xds" in it? 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. (I went ahead and did that in another commit; LMK.) |
||
// of 1 is also enforced. | ||
var XDSRingHashLimit = uint64FromEnv("GRPC_XDS_RING_HASH_LIMIT", 4096, 1, 8*1024*1024) |
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 we change the test names to be in snake_case instead, as the
go test
command would do that anyways, and will;
s in there, the test name might look weird.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.
I think this is fine IMO. AFAICT there's no real guidance given on this by the Go team, and the name is essentially just a convenience & informational. No matter what we name things, they will be copy-pasteable to re-run. That said, the "want"s are pretty obvious, especially given the "want" declaration, so I just removed them.