-
Notifications
You must be signed in to change notification settings - Fork 4.5k
balancer/weightedroundrobin: Add recording point for endpoint weight not yet usable and add metrics tests #7466
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f8aed9e
Add recording point for endpoint weight not yet usable and add metric…
zasweq 9a1fb9b
Responded to some comments
zasweq 6ff2e00
Add unit tests for WRR Metrics
zasweq 761b729
Responded to Doug's comments
zasweq 2ceb6e6
Responded to Doug's comments
zasweq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/* | ||
* | ||
* Copyright 2024 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 weightedroundrobin | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"google.golang.org/grpc/internal/grpctest" | ||
iserviceconfig "google.golang.org/grpc/internal/serviceconfig" | ||
"google.golang.org/grpc/internal/testutils/stats" | ||
) | ||
|
||
type s struct { | ||
grpctest.Tester | ||
} | ||
|
||
func Test(t *testing.T) { | ||
grpctest.RunSubTests(t, s{}) | ||
} | ||
|
||
// TestWRR_Metrics_SubConnWeight tests different scenarios for the weight call | ||
// on a weighted SubConn, and expects certain metrics for each of these | ||
// scenarios. | ||
func (s) TestWRR_Metrics_SubConnWeight(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
weightExpirationPeriod time.Duration | ||
blackoutPeriod time.Duration | ||
lastUpdated time.Time | ||
nonEmpty time.Time | ||
nowTime time.Time | ||
endpointWeightStaleWant float64 | ||
endpointWeightNotYetUsableWant float64 | ||
endpointWeightWant float64 | ||
}{ | ||
// The weighted SubConn's lastUpdated field hasn't been set, so this | ||
// SubConn's weight is not yet usable. Thus, should emit that endpoint | ||
// weight is not yet usable, and 0 for weight. | ||
{ | ||
name: "no weight set", | ||
weightExpirationPeriod: time.Second, | ||
blackoutPeriod: time.Second, | ||
nowTime: time.Now(), | ||
endpointWeightStaleWant: 0, | ||
endpointWeightNotYetUsableWant: 1, | ||
endpointWeightWant: 0, | ||
}, | ||
{ | ||
name: "weight expiration", | ||
lastUpdated: time.Now(), | ||
weightExpirationPeriod: 2 * time.Second, | ||
blackoutPeriod: time.Second, | ||
nowTime: time.Now().Add(100 * time.Second), | ||
endpointWeightStaleWant: 1, | ||
endpointWeightNotYetUsableWant: 0, | ||
endpointWeightWant: 0, | ||
}, | ||
{ | ||
name: "in blackout period", | ||
lastUpdated: time.Now(), | ||
weightExpirationPeriod: time.Minute, | ||
blackoutPeriod: 10 * time.Second, | ||
nowTime: time.Now(), | ||
endpointWeightStaleWant: 0, | ||
endpointWeightNotYetUsableWant: 1, | ||
endpointWeightWant: 0, | ||
}, | ||
{ | ||
name: "normal weight", | ||
lastUpdated: time.Now(), | ||
nonEmpty: time.Now(), | ||
weightExpirationPeriod: time.Minute, | ||
blackoutPeriod: time.Second, | ||
nowTime: time.Now().Add(10 * time.Second), | ||
endpointWeightStaleWant: 0, | ||
endpointWeightNotYetUsableWant: 0, | ||
endpointWeightWant: 3, | ||
}, | ||
{ | ||
name: "weight expiration takes precdedence over blackout", | ||
lastUpdated: time.Now(), | ||
nonEmpty: time.Now(), | ||
weightExpirationPeriod: time.Second, | ||
blackoutPeriod: time.Minute, | ||
nowTime: time.Now().Add(10 * time.Second), | ||
endpointWeightStaleWant: 1, | ||
endpointWeightNotYetUsableWant: 0, | ||
endpointWeightWant: 0, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
tmr := stats.NewTestMetricsRecorder(t) | ||
wsc := &weightedSubConn{ | ||
metricsRecorder: tmr, | ||
weightVal: 3, | ||
lastUpdated: test.lastUpdated, | ||
nonEmptySince: test.nonEmpty, | ||
} | ||
wsc.weight(test.nowTime, test.weightExpirationPeriod, test.blackoutPeriod, true) | ||
|
||
tmr.AssertDataForMetric("grpc.lb.wrr.endpoint_weight_stale", test.endpointWeightStaleWant) | ||
tmr.AssertDataForMetric("grpc.lb.wrr.endpoint_weight_not_yet_usable", test.endpointWeightNotYetUsableWant) | ||
tmr.AssertDataForMetric("grpc.lb.wrr.endpoint_weights", test.endpointWeightWant) | ||
}) | ||
} | ||
|
||
} | ||
|
||
// TestWRR_Metrics_Scheduler_RR_Fallback tests the round robin fallback metric | ||
// for scheduler updates. It tests the case with one SubConn, and two SubConns | ||
// with no weights. Both of these should emit a count metric for round robin | ||
// fallback. | ||
func (s) TestWRR_Metrics_Scheduler_RR_Fallback(t *testing.T) { | ||
tmr := stats.NewTestMetricsRecorder(t) | ||
wsc := &weightedSubConn{ | ||
metricsRecorder: tmr, | ||
weightVal: 0, | ||
} | ||
|
||
p := &picker{ | ||
cfg: &lbConfig{ | ||
BlackoutPeriod: iserviceconfig.Duration(10 * time.Second), | ||
WeightExpirationPeriod: iserviceconfig.Duration(3 * time.Minute), | ||
}, | ||
subConns: []*weightedSubConn{wsc}, | ||
metricsRecorder: tmr, | ||
} | ||
// There is only one SubConn, so no matter if the SubConn has a weight or | ||
// not will fallback to round robin. | ||
p.regenerateScheduler() | ||
tmr.AssertDataForMetric("grpc.lb.wrr.rr_fallback", 1) | ||
tmr.ClearMetrics() | ||
|
||
// With two SubConns, if neither of them have weights, it will also fallback | ||
// to round robin. | ||
dfawley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
wsc2 := &weightedSubConn{ | ||
target: "target", | ||
metricsRecorder: tmr, | ||
weightVal: 0, | ||
} | ||
p.subConns = append(p.subConns, wsc2) | ||
p.regenerateScheduler() | ||
tmr.AssertDataForMetric("grpc.lb.wrr.rr_fallback", 1) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.