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

xds: implement WeightedTargetLoadBalancer #6731

Merged
merged 11 commits into from Mar 11, 2020

Conversation

dapengzhang0
Copy link
Member

  • Implement weighted_target lb part of go/grpc-xds-traffic-splitting-and-path-matching
  • Refactor InterLocalityPicker to reuse the RandomWeightedPicker.

}

@Nullable
private ConnectivityState aggregateState(
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to make a utility method for this, as it is used in a couple of places (for any load balancers that contain a bunch of child balancers).

Copy link
Member Author

Choose a reason for hiding this comment

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

This is related to #6650. Might do it after the design in general is clear.

xds/src/main/java/io/grpc/xds/RandomWeightedPicker.java Outdated Show resolved Hide resolved
xds/src/main/java/io/grpc/xds/RandomWeightedPicker.java Outdated Show resolved Hide resolved
@voidzcy voidzcy self-requested a review March 4, 2020 23:23
@@ -62,12 +62,12 @@ public String toString() {
}
}

InterLocalityPicker(List<WeightedChildPicker> weightedChildPickers) {
WeightedRandomPicker(List<WeightedChildPicker> weightedChildPickers) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This class structure does not help with testing at all, as in order to provide your own random number generator in test, you have to implement a fake WeightedPickerFactory instance whose picker(...) method creates a fake SubchannelPicker. So everything about picking is fake. This tests nothing.

Instead, a better strategy is to not have this constructor at all. You implementation code should always call the constructor with injectable random number generator. In that way, your test code is still executing the real WeightedRandomPicker but only with the random number generator being faked out.

Copy link
Member Author

Choose a reason for hiding this comment

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

WeightedPickerFactory does not claim to test anything that WeightedRandomPicker does. What WeightedRandomPicker does is well-tested in its own test with a fake random. Using WeightedPickerFactory in LocalityStoreTest/WeightedTargetLoadBalancerTest is to avoid re-testing WeightedRandomPicker. Passing a fake random instead of the factory toLocalityStore/WeightedTargetLoadBalancer in test, you need recalculate the relation between the weights and the fake random number, that's basically following the implementation details of WeightedRandomPicker.

We have argued about this a lot of times. When class A uses class B where B is well-tested with its own BTest. Then ATest will just use BFactory. BFactory does not claim to test anything of B. ATest does not claim to test any implementation detail encapsulated in B Using B's constructor arg instead of BFactory in ATest, you are retesting B again.

Now I revised the class not to use a factory, but I'm still not going to retest the well-encapsulated and well-tested class before EdsLoadBalancer is refactored to use WeightedTargetLoadBalancer.

Copy link
Contributor

Choose a reason for hiding this comment

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

This test strategy is poor. It should be used only when the subcomponent B is heavy (i.e., small interface with large implementation). WeightedRandomPicker is completely an internal implementation of WeightedTargetLoadBalancer/LocalityStore, even though you write it as a modularized subcomponent. It's better even if WeightedRandomPicker is inlined in WeightedTargetLoadBalancer/LocalityStore. But in terms of code reuse, put it into a modularized class. Its implementation is not complex (even somewhat trivial), it's just using a random number generator to choose something in an input list. It is more like a utility. We are not keenly interested in testing the isolated behaviors of this sub-component. Instead, we are more interested in the real output of WeigtedTargetLoadBalancer/LocalityStore, which is the content of picker that eventually propagated to Channel (i.e., helper.updateBalancingState(State, Picker)).

The above is just my opinion. I am not going to block you on tests, as long as the class structure is obviously inappropriate. But really, existing tests test barely little real things...

WeightedTargetLoadBalancer(Helper helper) {
this(
checkNotNull(helper, "helper"),
WeightedRandomPicker.RANDOM_PICKER_FACTORY);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks bad... You should rather call constructor to create a factory or call the factory class to get the instance. At least, not something that is not the factory itself.

@dapengzhang0 dapengzhang0 force-pushed the weighted-target-2 branch 2 times, most recently from 5a7e732 to ca310f1 Compare March 9, 2020 19:46
@dapengzhang0 dapengzhang0 merged commit 5e7b8c6 into grpc:master Mar 11, 2020
@dapengzhang0 dapengzhang0 deleted the weighted-target-2 branch March 11, 2020 22:35
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants