TestRLSFailedRPCMetric tests RLS Metrics in the case an RLS Balancer fails an RPC due to an RLS failure. This should emit a "grpc.lb.rls.default_target_picks" with certain labels and cache metrics with certain labels.
(t *testing.T)
| 279 | // "grpc.lb.rls.default_target_picks" with certain labels and cache metrics with |
| 280 | // certain labels. |
| 281 | func (s) TestRLSFailedRPCMetric(t *testing.T) { |
| 282 | // Overwrite the uuid random number generator to be deterministic. |
| 283 | uuid.SetRand(rand.New(rand.NewSource(1))) |
| 284 | defer uuid.SetRand(nil) |
| 285 | |
| 286 | rlsServer, _ := rlstest.SetupFakeRLSServer(t, nil) |
| 287 | // Build an RLS config without a default target. |
| 288 | rlsConfig := buildBasicRLSConfigWithChildPolicy(t, t.Name(), rlsServer.Address) |
| 289 | // Register a manual resolver and push the RLS service config through it. |
| 290 | r := startManualResolverWithConfig(t, rlsConfig) |
| 291 | reader := metric.NewManualReader() |
| 292 | provider := metric.NewMeterProvider(metric.WithReader(reader)) |
| 293 | mo := opentelemetry.MetricsOptions{ |
| 294 | MeterProvider: provider, |
| 295 | Metrics: opentelemetry.DefaultMetrics().Add("grpc.lb.rls.cache_entries", "grpc.lb.rls.cache_size", "grpc.lb.rls.default_target_picks", "grpc.lb.rls.target_picks", "grpc.lb.rls.failed_picks"), |
| 296 | OptionalLabels: []string{"grpc.client.call.custom"}, |
| 297 | } |
| 298 | grpcTarget := r.Scheme() + ":///" |
| 299 | cc, err := grpc.NewClient(grpcTarget, grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()), opentelemetry.DialOption(opentelemetry.Options{MetricsOptions: mo})) |
| 300 | if err != nil { |
| 301 | t.Fatalf("Failed to dial local test server: %v", err) |
| 302 | } |
| 303 | defer cc.Close() |
| 304 | |
| 305 | wantMetrics := []metricdata.Metrics{ |
| 306 | { |
| 307 | Name: "grpc.lb.rls.failed_picks", |
| 308 | Description: "EXPERIMENTAL. Number of LB picks failed due to either a failed RLS request or the RLS channel being throttled.", |
| 309 | Unit: "{pick}", |
| 310 | Data: metricdata.Sum[int64]{ |
| 311 | DataPoints: []metricdata.DataPoint[int64]{ |
| 312 | { |
| 313 | Attributes: attribute.NewSet(attribute.String("grpc.target", grpcTarget), attribute.String("grpc.lb.rls.server_target", rlsServer.Address), attribute.String("grpc.client.call.custom", "failed-pick-custom")), |
| 314 | Value: 1, |
| 315 | }, |
| 316 | }, |
| 317 | Temporality: metricdata.CumulativeTemporality, |
| 318 | IsMonotonic: true, |
| 319 | }, |
| 320 | }, |
| 321 | // Receives an empty RLS Response, so a single cache entry with no size. |
| 322 | { |
| 323 | Name: "grpc.lb.rls.cache_entries", |
| 324 | Description: "EXPERIMENTAL. Number of entries in the RLS cache.", |
| 325 | Unit: "{entry}", |
| 326 | Data: metricdata.Gauge[int64]{ |
| 327 | DataPoints: []metricdata.DataPoint[int64]{ |
| 328 | { |
| 329 | Attributes: attribute.NewSet(attribute.String("grpc.target", grpcTarget), attribute.String("grpc.lb.rls.server_target", rlsServer.Address), attribute.String("grpc.lb.rls.instance_uuid", "52fdfc07-2182-454f-963f-5f0f9a621d72")), |
| 330 | Value: 1, |
| 331 | }, |
| 332 | }, |
| 333 | }, |
| 334 | }, |
| 335 | { |
| 336 | Name: "grpc.lb.rls.cache_size", |
| 337 | Description: "EXPERIMENTAL. The current size of the RLS cache.", |
| 338 | Unit: "By", |
nothing calls this directly
no test coverage detected