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

Method Test_RLSDefaultTargetPicksMetric

balancer/rls/picker_test.go:256–290  ·  view source on GitHub ↗

Test_RLSDefaultTargetPicksMetric tests the default target picks metric. It configures an RLS Balancer which specifies to route to the default target in the RLS Configuration, and makes an RPC on a Channel containing this RLS Balancer. This test then asserts a default target picks metric is emitted,

(t *testing.T)

Source from the content-addressed store, hash-verified

254// Balancer. This test then asserts a default target picks metric is emitted,
255// and target pick or failed pick metric is not emitted.
256func (s) Test_RLSDefaultTargetPicksMetric(t *testing.T) {
257 // Start an RLS server and set the throttler to always throttle requests.
258 rlsServer, _ := rlstest.SetupFakeRLSServer(t, nil)
259 overrideAdaptiveThrottler(t, alwaysThrottlingThrottler())
260
261 // Build RLS service config with a default target.
262 rlsConfig := buildBasicRLSConfigWithChildPolicy(t, t.Name(), rlsServer.Address)
263 defBackendCh, defBackendAddress := startBackend(t)
264 rlsConfig.RouteLookupConfig.DefaultTarget = defBackendAddress
265
266 // Register a manual resolver and push the RLS service config through it.
267 r := startManualResolverWithConfig(t, rlsConfig)
268
269 tmr := stats.NewTestMetricsRecorder()
270 cc, err := grpc.NewClient(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(tmr))
271 if err != nil {
272 t.Fatalf("grpc.NewClient() failed: %v", err)
273 }
274 defer cc.Close()
275
276 // Make an RPC and ensure it gets routed to the default target.
277 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
278 defer cancel()
279 makeTestRPCAndExpectItToReachBackend(ctx, t, cc, defBackendCh)
280
281 if got, _ := tmr.Metric("grpc.lb.rls.default_target_picks"); got != 1 {
282 t.Fatalf("Unexpected data for metric %v, got: %v, want: %v", "grpc.lb.rls.default_target_picks", got, 1)
283 }
284 if _, ok := tmr.Metric("grpc.lb.rls.target_picks"); ok {
285 t.Fatalf("Data is present for metric %v", "grpc.lb.rls.target_picks")
286 }
287 if _, ok := tmr.Metric("grpc.lb.rls.failed_picks"); ok {
288 t.Fatalf("Data is present for metric %v", "grpc.lb.rls.failed_picks")
289 }
290}
291
292// Test_RLSTargetPicksMetric tests the target picks metric. It configures an RLS
293// Balancer which specifies to route to a target through a RouteLookupResponse,

Callers

nothing calls this directly

Calls 15

MetricMethod · 0.95
NewTestMetricsRecorderFunction · 0.92
NewClientFunction · 0.92
WithResolversFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithStatsHandlerFunction · 0.92
startBackendFunction · 0.85

Tested by

no test coverage detected