@ -56,10 +56,12 @@ namespace grpc_core {
namespace testing {
namespace {
BackendMetricData MakeBackendMetricData ( double cpu_utilization , double qps ,
double eps ) {
BackendMetricData MakeBackendMetricData ( double app_utilization , double qps ,
double eps ,
double cpu_utilization = 0 ) {
BackendMetricData b ;
b . cpu_utilization = cpu_utilization ;
b . application_utilization = app_utilization ;
b . qps = qps ;
b . eps = eps ;
return b ;
@ -193,6 +195,8 @@ class WeightedRoundRobinTest : public TimeAwareLoadBalancingPolicyTest {
backend_metric_data - > qps = it - > second . qps ;
backend_metric_data - > eps = it - > second . eps ;
backend_metric_data - > cpu_utilization = it - > second . cpu_utilization ;
backend_metric_data - > application_utilization =
it - > second . application_utilization ;
}
FakeMetadata metadata ( { } ) ;
FakeBackendMetricAccessor backend_metric_accessor (
@ -213,6 +217,8 @@ class WeightedRoundRobinTest : public TimeAwareLoadBalancingPolicyTest {
backend_metric_data . qps = p . second . qps ;
backend_metric_data . eps = p . second . eps ;
backend_metric_data . cpu_utilization = p . second . cpu_utilization ;
backend_metric_data . application_utilization =
p . second . application_utilization ;
subchannel - > SendOobBackendMetricReport ( backend_metric_data ) ;
}
}
@ -334,24 +340,92 @@ TEST_F(WeightedRoundRobinTest, Basic) {
// No utilization report from backend 2, so it gets the average weight 2.
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 2 } } ) ;
// Now have backend 2 report utilization the same as backend 1, so its
// weight will be the same.
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
}
TEST_F ( WeightedRoundRobinTest , CpuUtilWithNoAppUtil ) {
// Send address list to LB policy.
const std : : array < absl : : string_view , 3 > kAddresses = {
" ipv4:127.0.0.1:441 " , " ipv4:127.0.0.1:442 " , " ipv4:127.0.0.1:443 " } ;
auto picker = SendInitialUpdateAndWaitForConnected ( kAddresses ) ;
ASSERT_NE ( picker , nullptr ) ;
// Address 0 gets weight 1, address 1 gets weight 3.
// No utilization report from backend 2, so it gets the average weight 2.
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app_utilization=*/ 0 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.9 ) } ,
{ kAddresses [ 1 ] ,
MakeBackendMetricData ( /*app_utilization=*/ 0 ,
/*qps=*/ 100.0 ,
/*eps=*/ 0.0 , /*cpu_utilization=*/ 0.3 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 2 } } ) ;
// Now have backend 2 report utilization the same as backend 1, so its
// weight will be the same.
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app_utilization=*/ 0 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.9 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app_utilization=*/ 0 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.3 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app_utilization=*/ 0 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.3 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
}
TEST_F ( WeightedRoundRobinTest , AppUtilOverCpuUtil ) {
// Send address list to LB policy.
const std : : array < absl : : string_view , 3 > kAddresses = {
" ipv4:127.0.0.1:441 " , " ipv4:127.0.0.1:442 " , " ipv4:127.0.0.1:443 " } ;
auto picker = SendInitialUpdateAndWaitForConnected ( kAddresses ) ;
ASSERT_NE ( picker , nullptr ) ;
// Address 0 gets weight 1, address 1 gets weight 3.
// No utilization report from backend 2, so it gets the average weight 2.
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app_utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.3 ) } ,
{ kAddresses [ 1 ] ,
MakeBackendMetricData ( /*app_utilization=*/ 0.3 ,
/*qps=*/ 100.0 ,
/*eps=*/ 0.0 , /*cpu_utilization=*/ 0.4 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 2 } } ) ;
// Now have backend 2 report utilization the same as backend 1, so its
// weight will be the same.
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app_utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.2 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app_utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.6 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app_utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.5 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
}
TEST_F ( WeightedRoundRobinTest , Eps ) {
// Send address list to LB policy.
const std : : array < absl : : string_view , 3 > kAddresses = {
@ -362,11 +436,11 @@ TEST_F(WeightedRoundRobinTest, Eps) {
// Expected weights: 1/(0.1+0.5) : 1/(0.1+0.2) : 1/(0.1+0.1) = 1:2:3
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.1 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.1 ,
/*qps=*/ 100.0 , /*eps=*/ 50.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.1 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.1 ,
/*qps=*/ 100.0 , /*eps=*/ 20.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.1 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.1 ,
/*qps=*/ 100.0 , /*eps=*/ 10.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 2 } , { kAddresses [ 2 ] , 3 } } ) ;
}
@ -385,20 +459,20 @@ TEST_F(WeightedRoundRobinTest, IgnoresDuplicateAddresses) {
// No utilization report from backend 2, so it gets the average weight 2.
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 2 } } ) ;
// Now have backend 2 report utilization the same as backend 1, so its
// weight will be the same.
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
}
@ -425,9 +499,9 @@ TEST_F(WeightedRoundRobinTest, OobReporting) {
// Address 0 gets weight 1, address 1 gets weight 3.
// No utilization report from backend 2, so it gets the average weight 2.
ReportOobBackendMetrics (
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ) ;
WaitForWeightedRoundRobinPicks (
& picker , { } ,
@ -435,11 +509,11 @@ TEST_F(WeightedRoundRobinTest, OobReporting) {
// Now have backend 2 report utilization the same as backend 1, so its
// weight will be the same.
ReportOobBackendMetrics (
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ) ;
WaitForWeightedRoundRobinPicks (
& picker , { } ,
@ -452,6 +526,94 @@ TEST_F(WeightedRoundRobinTest, OobReporting) {
}
}
TEST_F ( WeightedRoundRobinTest , OobReportingCpuUtilWithNoAppUtil ) {
// Send address list to LB policy.
const std : : array < absl : : string_view , 3 > kAddresses = {
" ipv4:127.0.0.1:441 " , " ipv4:127.0.0.1:442 " , " ipv4:127.0.0.1:443 " } ;
auto picker = SendInitialUpdateAndWaitForConnected (
kAddresses , ConfigBuilder ( ) . SetEnableOobLoadReport ( true ) ) ;
ASSERT_NE ( picker , nullptr ) ;
// Address 0 gets weight 1, address 1 gets weight 3.
// No utilization report from backend 2, so it gets the average weight 2.
ReportOobBackendMetrics (
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app_utilization=*/ 0 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.9 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app_utilization=*/ 0 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.3 ) } } ) ;
WaitForWeightedRoundRobinPicks (
& picker , { } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 2 } } ) ;
// Now have backend 2 report utilization the same as backend 1, so its
// weight will be the same.
ReportOobBackendMetrics (
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app_utilization=*/ 0 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.9 ) } ,
{ kAddresses [ 1 ] ,
MakeBackendMetricData ( /*app_utilization=*/ 0 ,
/*qps=*/ 100.0 ,
/*eps=*/ 0.0 , /*cpu_utilization=*/ 0.3 ) } ,
{ kAddresses [ 2 ] ,
MakeBackendMetricData ( /*app_utilization=*/ 0 ,
/*qps=*/ 100.0 ,
/*eps=*/ 0.0 , /*cpu_utilization=*/ 0.3 ) } } ) ;
WaitForWeightedRoundRobinPicks (
& picker , { } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
// Verify that OOB reporting interval is the default.
for ( const auto & address : kAddresses ) {
auto * subchannel = FindSubchannel ( address ) ;
ASSERT_NE ( subchannel , nullptr ) ;
subchannel - > CheckOobReportingPeriod ( Duration : : Seconds ( 10 ) ) ;
}
}
TEST_F ( WeightedRoundRobinTest , OobReportingAppUtilOverCpuUtil ) {
// Send address list to LB policy.
const std : : array < absl : : string_view , 3 > kAddresses = {
" ipv4:127.0.0.1:441 " , " ipv4:127.0.0.1:442 " , " ipv4:127.0.0.1:443 " } ;
auto picker = SendInitialUpdateAndWaitForConnected (
kAddresses , ConfigBuilder ( ) . SetEnableOobLoadReport ( true ) ) ;
ASSERT_NE ( picker , nullptr ) ;
// Address 0 gets weight 1, address 1 gets weight 3.
// No utilization report from backend 2, so it gets the average weight 2.
ReportOobBackendMetrics (
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app_utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.3 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app_utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.4 ) } } ) ;
WaitForWeightedRoundRobinPicks (
& picker , { } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 2 } } ) ;
// Now have backend 2 report utilization the same as backend 1, so its
// weight will be the same.
ReportOobBackendMetrics (
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app_utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ,
/*cpu_utilization=*/ 0.2 ) } ,
{ kAddresses [ 1 ] ,
MakeBackendMetricData ( /*app_utilization=*/ 0.3 ,
/*qps=*/ 100.0 ,
/*eps=*/ 0.0 , /*cpu_utilization=*/ 0.6 ) } ,
{ kAddresses [ 2 ] ,
MakeBackendMetricData ( /*app_utilization=*/ 0.3 ,
/*qps=*/ 100.0 ,
/*eps=*/ 0.0 , /*cpu_utilization=*/ 0.5 ) } } ) ;
WaitForWeightedRoundRobinPicks (
& picker , { } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
// Verify that OOB reporting interval is the default.
for ( const auto & address : kAddresses ) {
auto * subchannel = FindSubchannel ( address ) ;
ASSERT_NE ( subchannel , nullptr ) ;
subchannel - > CheckOobReportingPeriod ( Duration : : Seconds ( 10 ) ) ;
}
}
TEST_F ( WeightedRoundRobinTest , HonorsOobReportingPeriod ) {
const std : : array < absl : : string_view , 3 > kAddresses = {
" ipv4:127.0.0.1:441 " , " ipv4:127.0.0.1:442 " , " ipv4:127.0.0.1:443 " } ;
@ -461,11 +623,11 @@ TEST_F(WeightedRoundRobinTest, HonorsOobReportingPeriod) {
Duration : : Seconds ( 5 ) ) ) ;
ASSERT_NE ( picker , nullptr ) ;
ReportOobBackendMetrics (
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ) ;
WaitForWeightedRoundRobinPicks (
& picker , { } ,
@ -486,11 +648,11 @@ TEST_F(WeightedRoundRobinTest, HonorsWeightUpdatePeriod) {
ASSERT_NE ( picker , nullptr ) ;
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
}
@ -505,11 +667,11 @@ TEST_F(WeightedRoundRobinTest, WeightUpdatePeriodLowerBound) {
ASSERT_NE ( picker , nullptr ) ;
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
}
@ -525,11 +687,11 @@ TEST_F(WeightedRoundRobinTest, WeightExpirationPeriod) {
// All backends report weights.
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
// Advance time to make weights stale and trigger the timer callback
@ -553,11 +715,11 @@ TEST_F(WeightedRoundRobinTest, BlackoutPeriodAfterWeightExpiration) {
// All backends report weights.
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
// Advance time to make weights stale and trigger the timer callback
@ -572,11 +734,11 @@ TEST_F(WeightedRoundRobinTest, BlackoutPeriodAfterWeightExpiration) {
// because we're still in the blackout period.
ExpectWeightedRoundRobinPicks (
picker . get ( ) ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ,
{ { kAddresses [ 0 ] , 3 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
// Advance time past the blackout period. This should cause the
@ -599,11 +761,11 @@ TEST_F(WeightedRoundRobinTest, BlackoutPeriodAfterDisconnect) {
// All backends report weights.
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
// Trigger disconnection and reconnection on address 2.
@ -619,11 +781,11 @@ TEST_F(WeightedRoundRobinTest, BlackoutPeriodAfterDisconnect) {
picker = ExpectState ( GRPC_CHANNEL_READY , absl : : OkStatus ( ) ) ;
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 2 } } ) ;
// Advance time to exceed the blackout period and trigger the timer
@ -632,11 +794,11 @@ TEST_F(WeightedRoundRobinTest, BlackoutPeriodAfterDisconnect) {
RunTimerCallback ( ) ;
ExpectWeightedRoundRobinPicks (
picker . get ( ) ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.3 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.3 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.9 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.9 ,
/*qps=*/ 100.0 , /*eps=*/ 0.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 3 } , { kAddresses [ 2 ] , 3 } } ) ;
}
@ -651,11 +813,11 @@ TEST_F(WeightedRoundRobinTest, ZeroErrorUtilPenalty) {
// Expected weights: 1:1:1
WaitForWeightedRoundRobinPicks (
& picker ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.1 ,
{ { kAddresses [ 0 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.1 ,
/*qps=*/ 100.0 , /*eps=*/ 50.0 ) } ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.1 ,
{ kAddresses [ 1 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.1 ,
/*qps=*/ 100.0 , /*eps=*/ 20.0 ) } ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*cpu _utilization=*/ 0.1 ,
{ kAddresses [ 2 ] , MakeBackendMetricData ( /*app _utilization=*/ 0.1 ,
/*qps=*/ 100.0 , /*eps=*/ 10.0 ) } } ,
{ { kAddresses [ 0 ] , 1 } , { kAddresses [ 1 ] , 1 } , { kAddresses [ 2 ] , 1 } } ) ;
}