MCPcopy
hub / github.com/grpc/grpc-go / TestWRRMetricsBasic

Method TestWRRMetricsBasic

balancer/weightedroundrobin/balancer_test.go:220–251  ·  view source on GitHub ↗

TestWRRMetricsBasic tests metrics emitted from the WRR balancer. It configures a weighted round robin balancer as the top level balancer of a ClientConn, and configures a fake stats handler on the ClientConn to receive metrics. It verifies stats emitted from the Weighted Round Robin Balancer on bala

(t *testing.T)

Source from the content-addressed store, hash-verified

218// from the most recently synced state of the system (picker/scheduler) from the
219// test body.
220func (s) TestWRRMetricsBasic(t *testing.T) {
221 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
222 defer cancel()
223
224 srv := startServer(t, reportCall)
225 sc := svcConfig(t, testMetricsConfig)
226
227 tmr := stats.NewTestMetricsRecorder()
228 if err := srv.StartClient(grpc.WithDefaultServiceConfig(sc), grpc.WithStatsHandler(tmr)); err != nil {
229 t.Fatalf("Error starting client: %v", err)
230 }
231 srv.callMetrics.SetQPS(float64(1))
232
233 if _, err := srv.Client.EmptyCall(ctx, &testpb.Empty{}); err != nil {
234 t.Fatalf("Error from EmptyCall: %v", err)
235 }
236
237 if got, _ := tmr.Metric("grpc.lb.wrr.rr_fallback"); got != 1 {
238 t.Fatalf("Unexpected data for metric %v, got: %v, want: %v", "grpc.lb.wrr.rr_fallback", got, 1)
239 }
240 if got, _ := tmr.Metric("grpc.lb.wrr.endpoint_weight_stale"); got != 0 {
241 t.Fatalf("Unexpected data for metric %v, got: %v, want: %v", "grpc.lb.wrr.endpoint_weight_stale", got, 0)
242 }
243 if got, _ := tmr.Metric("grpc.lb.wrr.endpoint_weight_not_yet_usable"); got != 1 {
244 t.Fatalf("Unexpected data for metric %v, got: %v, want: %v", "grpc.lb.wrr.endpoint_weight_not_yet_usable", got, 1)
245 }
246 // Unusable, so no endpoint weight. Due to only one SubConn, this will never
247 // update the weight. Thus, this will stay 0.
248 if got, _ := tmr.Metric("grpc.lb.wrr.endpoint_weight_stale"); got != 0 {
249 t.Fatalf("Unexpected data for metric %v, got: %v, want: %v", "grpc.lb.wrr.endpoint_weight_stale", got, 0)
250 }
251}
252
253// Tests two addresses with ORCA reporting disabled (should fall back to pure
254// RR).

Callers

nothing calls this directly

Calls 10

MetricMethod · 0.95
NewTestMetricsRecorderFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
WithStatsHandlerFunction · 0.92
svcConfigFunction · 0.85
StartClientMethod · 0.80
startServerFunction · 0.70
FatalfMethod · 0.65
SetQPSMethod · 0.65
EmptyCallMethod · 0.65

Tested by

no test coverage detected