test(spanner): support filtering of PickRandomInstance() candidates#5885
test(spanner): support filtering of PickRandomInstance() candidates#5885devbww merged 2 commits intogoogleapis:masterfrom
PickRandomInstance() candidates#5885Conversation
Support filtering of `PickRandomInstance()` candidates (1) on the server side, by exposing the `ListInstances` filter, and (2) on the client side, via a predicate over `Instance` and `InstanceConfig`. This will be needed to support the upcoming CMEK integration tests (at least in their current configuration), where the selected instance must be in the single location we use to store the encryption keys. Also use server-side filtering to implement the restriction of instance IDs to "test-instance-*". Fixes googleapis#5588.
Codecov Report
@@ Coverage Diff @@
## master #5885 +/- ##
==========================================
- Coverage 95.46% 95.46% -0.01%
==========================================
Files 1120 1120
Lines 102858 102869 +11
==========================================
+ Hits 98191 98201 +10
- Misses 4667 4668 +1
Continue to review full report at Codecov.
|
coryan
left a comment
There was a problem hiding this comment.
Reviewed 2 of 2 files at r1.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @devbww)
google/cloud/spanner/testing/pick_random_instance.h, line 39 at r1 (raw file):
google::cloud::internal::DefaultPRNG& generator, std::string const& project_id, std::string const& filter = "", std::function<bool(
Consider a type alias, it was hard for me to find the predicate in this case.
google/cloud/spanner/testing/pick_random_instance.cc, line 36 at r1 (raw file):
std::vector<google::spanner::admin::instance::v1::InstanceConfig> configs; if (predicate) {
I think if you take predicate by value you can do something like:
if (!predicate) {
predicate = [](auto, auto) { return true; }
}And the code below gets simpler. Well, you can't use auto in the lambda, because C++11, but you get the idea.
devbww
left a comment
There was a problem hiding this comment.
Reviewable status: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @coryan)
google/cloud/spanner/testing/pick_random_instance.h, line 39 at r1 (raw file):
Previously, coryan (Carlos O'Ryan) wrote…
Consider a type alias, it was hard for me to find the
predicatein this case.
Done.
google/cloud/spanner/testing/pick_random_instance.cc, line 36 at r1 (raw file):
Previously, coryan (Carlos O'Ryan) wrote…
I think if you take
predicateby value you can do something like:if (!predicate) { predicate = [](auto, auto) { return true; } }And the code below gets simpler. Well, you can't use
autoin the lambda, because C++11, but you get the idea.
I was trying to avoid (1) copying the std::function, and (2) fetching the instance configs every time, but this is test code, so done.
coryan
left a comment
There was a problem hiding this comment.
Reviewed 2 of 2 files at r2.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @devbww)
google/cloud/spanner/testing/pick_random_instance.cc, line 36 at r1 (raw file):
Previously, devbww (Bradley White) wrote…
I was trying to avoid (1) copying the
std::function, and (2) fetching the instance configs every time, but this is test code, so done.
Ack. Thanks for making the change.
google/cloud/spanner/testing/pick_random_instance.cc, line 58 at r2 (raw file):
if (!instance) return std::move(instance).status(); for (auto const& config : configs) { if (instance->config() == config.name()) {
nit: if you wanted to, you can organize the configs into some kind of map or hash as they are loaded and avoid the double loop. But as you said elsewhere, this is test code.
devbww
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! all files reviewed, all discussions resolved (waiting on @devbww)
google/cloud/spanner/testing/pick_random_instance.cc, line 58 at r2 (raw file):
Previously, coryan (Carlos O'Ryan) wrote…
nit: if you wanted to, you can organize the configs into some kind of map or hash as they are loaded and avoid the double loop. But as you said elsewhere, this is test code.
Thanks. But yes ... test code. And I think we might also find that linear search outperforms associative lookup when the number of configs is small (as expected), and particularly so when it is within another loop and cache effects kick in when data is more contiguous.
Undo the addition of a predicate to `PickRandomInstance()` (from #5885) to, say, one in a specific location where test resources were configured. A better tactic is to configure test resources in all possible test-instance locations. So, introduce `InstanceLocation()`, which can be used to select location-specific test resources for the randomly selected instance. This will be needed to support the upcoming CMEK integration tests and samples, where the location of the encryption keys must match the location of the instance.
Support filtering of
PickRandomInstance()candidates (1) on the serverside, by exposing the
ListInstancesfilter, and (2) on the client side,via a predicate over
InstanceandInstanceConfig.This will be needed to support the upcoming CMEK integration tests (at
least in their current configuration), where the selected instance must
be in the single location we use to store the encryption keys.
Also use server-side filtering to implement the restriction of instance
IDs to "test-instance-*".
Fixes #5588.
This change is