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

Method TestWRRMetrics

stats/opentelemetry/e2e_test.go:575–772  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

573// metrics atoms are eventually present for all four WRR Metrics, alongside the
574// correct target and locality label for each metric.
575func (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 }),

Callers

nothing calls this directly

Calls 15

HasFiredMethod · 0.95
EmptyCallMethod · 0.95
FireMethod · 0.95
NewServerMetricsRecorderFunction · 0.92
StartTestServiceFunction · 0.92
CallMetricsServerOptionFunction · 0.92
DefaultClientListenerFunction · 0.92
DefaultRouteConfigFunction · 0.92
DefaultMetricsFunction · 0.92

Tested by

no test coverage detected