TestPickFirstMetricsFailure tests the connection attempts failed metric. It configures a channel and scenario that causes a pick first connection attempt to fail, and then expects that metric to emit.
(t *testing.T)
| 138 | // configures a channel and scenario that causes a pick first connection attempt |
| 139 | // to fail, and then expects that metric to emit. |
| 140 | func (s) TestPickFirstMetricsFailure(t *testing.T) { |
| 141 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 142 | defer cancel() |
| 143 | |
| 144 | sc := internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult)(pfConfig) |
| 145 | |
| 146 | r := manual.NewBuilderWithScheme("whatever") |
| 147 | r.InitialState(resolver.State{ |
| 148 | ServiceConfig: sc, |
| 149 | Addresses: []resolver.Address{{Addr: "bad address"}}}, |
| 150 | ) |
| 151 | grpcTarget := r.Scheme() + ":///" |
| 152 | tmr := stats.NewTestMetricsRecorder() |
| 153 | cc, err := grpc.NewClient(grpcTarget, grpc.WithStatsHandler(tmr), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r)) |
| 154 | if err != nil { |
| 155 | t.Fatalf("NewClient() failed with error: %v", err) |
| 156 | } |
| 157 | defer cc.Close() |
| 158 | |
| 159 | tsc := testgrpc.NewTestServiceClient(cc) |
| 160 | if _, err := tsc.EmptyCall(ctx, &testpb.Empty{}); err == nil { |
| 161 | t.Fatalf("EmptyCall() passed when expected to fail") |
| 162 | } |
| 163 | |
| 164 | if got, _ := tmr.Metric("grpc.lb.pick_first.connection_attempts_succeeded"); got != 0 { |
| 165 | t.Errorf("Unexpected data for metric %v, got: %v, want: %v", "grpc.lb.pick_first.connection_attempts_succeeded", got, 0) |
| 166 | } |
| 167 | if got, _ := tmr.Metric("grpc.lb.pick_first.connection_attempts_failed"); got != 1 { |
| 168 | t.Errorf("Unexpected data for metric %v, got: %v, want: %v", "grpc.lb.pick_first.connection_attempts_failed", got, 1) |
| 169 | } |
| 170 | if got, _ := tmr.Metric("grpc.lb.pick_first.disconnections"); got != 0 { |
| 171 | t.Errorf("Unexpected data for metric %v, got: %v, want: %v", "grpc.lb.pick_first.disconnections", got, 0) |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | // TestPickFirstMetricsE2E tests the pick first metrics end to end. It |
| 176 | // configures a channel with an OpenTelemetry plugin, induces all 3 pick first |
nothing calls this directly
no test coverage detected