TestWRRMetrics tests the metrics emitted from the WRR LB Policy. It configures WRR as an endpoint picking policy through xDS on a ClientConn alongside an OpenTelemetry stats handler. It makes a few RPC's, and then sleeps for a bit to allow weight to expire. It then asserts OpenTelemetry metrics atom
(t *testing.T)
| 573 | // metrics atoms are eventually present for all four WRR Metrics, alongside the |
| 574 | // correct target and locality label for each metric. |
| 575 | func (s) TestWRRMetrics(t *testing.T) { |
| 576 | cmr := orca.NewServerMetricsRecorder().(orca.CallMetricsRecorder) |
| 577 | backend1 := stubserver.StartTestService(t, &stubserver.StubServer{ |
| 578 | EmptyCallF: func(ctx context.Context, _ *testpb.Empty) (*testpb.Empty, error) { |
| 579 | if r := orca.CallMetricsRecorderFromContext(ctx); r != nil { |
| 580 | // Copy metrics from what the test set in cmr into r. |
| 581 | sm := cmr.(orca.ServerMetricsProvider).ServerMetrics() |
| 582 | r.SetApplicationUtilization(sm.AppUtilization) |
| 583 | r.SetQPS(sm.QPS) |
| 584 | r.SetEPS(sm.EPS) |
| 585 | } |
| 586 | return &testpb.Empty{}, nil |
| 587 | }, |
| 588 | }, orca.CallMetricsServerOption(nil)) |
| 589 | port1 := itestutils.ParsePort(t, backend1.Address) |
| 590 | defer backend1.Stop() |
| 591 | |
| 592 | cmr.SetQPS(10.0) |
| 593 | cmr.SetApplicationUtilization(1.0) |
| 594 | |
| 595 | backend2 := stubserver.StartTestService(t, &stubserver.StubServer{ |
| 596 | EmptyCallF: func(ctx context.Context, _ *testpb.Empty) (*testpb.Empty, error) { |
| 597 | if r := orca.CallMetricsRecorderFromContext(ctx); r != nil { |
| 598 | // Copy metrics from what the test set in cmr into r. |
| 599 | sm := cmr.(orca.ServerMetricsProvider).ServerMetrics() |
| 600 | r.SetApplicationUtilization(sm.AppUtilization) |
| 601 | r.SetQPS(sm.QPS) |
| 602 | r.SetEPS(sm.EPS) |
| 603 | } |
| 604 | return &testpb.Empty{}, nil |
| 605 | }, |
| 606 | }, orca.CallMetricsServerOption(nil)) |
| 607 | port2 := itestutils.ParsePort(t, backend2.Address) |
| 608 | defer backend2.Stop() |
| 609 | |
| 610 | const serviceName = "my-service-client-side-xds" |
| 611 | |
| 612 | // Start an xDS management server. |
| 613 | managementServer, nodeID, _, xdsResolver := setup.ManagementServerAndResolver(t) |
| 614 | |
| 615 | wrrConfig := &v3wrrlocalitypb.WrrLocality{ |
| 616 | EndpointPickingPolicy: &v3clusterpb.LoadBalancingPolicy{ |
| 617 | Policies: []*v3clusterpb.LoadBalancingPolicy_Policy{ |
| 618 | { |
| 619 | TypedExtensionConfig: &v3corepb.TypedExtensionConfig{ |
| 620 | TypedConfig: itestutils.MarshalAny(t, &v3clientsideweightedroundrobinpb.ClientSideWeightedRoundRobin{ |
| 621 | EnableOobLoadReport: &wrapperspb.BoolValue{ |
| 622 | Value: false, |
| 623 | }, |
| 624 | // BlackoutPeriod long enough to cause load report |
| 625 | // weight to trigger in the scope of test case. |
| 626 | // WeightExpirationPeriod will cause the load report |
| 627 | // weight for backend 1 to expire. |
| 628 | BlackoutPeriod: durationpb.New(5 * time.Millisecond), |
| 629 | WeightExpirationPeriod: durationpb.New(500 * time.Millisecond), |
| 630 | WeightUpdatePeriod: durationpb.New(time.Second), |
| 631 | ErrorUtilizationPenalty: &wrapperspb.FloatValue{Value: 1}, |
| 632 | }), |
nothing calls this directly
no test coverage detected