TestResourceUpdateMetrics configures an xDS client, and a management server to send valid and invalid LDS updates, and verifies that the expected metrics for both good and bad updates are emitted.
(t *testing.T)
| 56 | // to send valid and invalid LDS updates, and verifies that the expected metrics |
| 57 | // for both good and bad updates are emitted. |
| 58 | func (s) TestResourceUpdateMetrics(t *testing.T) { |
| 59 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 60 | defer cancel() |
| 61 | |
| 62 | tmr := stats.NewTestMetricsRecorder() |
| 63 | l, err := testutils.LocalTCPListener() |
| 64 | if err != nil { |
| 65 | t.Fatalf("net.Listen() failed: %v", err) |
| 66 | } |
| 67 | mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{Listener: l}) |
| 68 | const listenerResourceName = "test-listener-resource" |
| 69 | const routeConfigurationName = "test-route-configuration-resource" |
| 70 | nodeID := uuid.New().String() |
| 71 | resources := e2e.UpdateOptions{ |
| 72 | NodeID: nodeID, |
| 73 | Listeners: []*v3listenerpb.Listener{e2e.DefaultClientListener(listenerResourceName, routeConfigurationName)}, |
| 74 | SkipValidation: true, |
| 75 | } |
| 76 | if err := mgmtServer.Update(ctx, resources); err != nil { |
| 77 | t.Fatalf("Failed to update management server with resources: %v, err: %v", resources, err) |
| 78 | } |
| 79 | |
| 80 | bootstrapContents, err := bootstrap.NewContentsForTesting(bootstrap.ConfigOptionsForTesting{ |
| 81 | Servers: []byte(fmt.Sprintf(`[{ |
| 82 | "server_uri": %q, |
| 83 | "channel_creds": [{"type": "insecure"}] |
| 84 | }]`, mgmtServer.Address)), |
| 85 | Node: []byte(fmt.Sprintf(`{"id": "%s"}`, nodeID)), |
| 86 | Authorities: map[string]json.RawMessage{ |
| 87 | "authority": []byte("{}"), |
| 88 | }, |
| 89 | }) |
| 90 | if err != nil { |
| 91 | t.Fatalf("Failed to create bootstrap configuration: %v", err) |
| 92 | } |
| 93 | |
| 94 | config, err := bootstrap.NewConfigFromContents(bootstrapContents) |
| 95 | if err != nil { |
| 96 | t.Fatalf("Failed to parse bootstrap contents: %s, %v", string(bootstrapContents), err) |
| 97 | } |
| 98 | pool := NewPool(config) |
| 99 | client, close, err := pool.NewClientForTesting(OptionsForTesting{ |
| 100 | Name: t.Name(), |
| 101 | WatchExpiryTimeout: defaultTestWatchExpiryTimeout, |
| 102 | MetricsRecorder: tmr, |
| 103 | }) |
| 104 | if err != nil { |
| 105 | t.Fatalf("Failed to create an xDS client: %v", err) |
| 106 | } |
| 107 | defer close() |
| 108 | |
| 109 | // Watch the valid listener configured on the management server. This should |
| 110 | // cause a resource updates valid count to emit eventually. |
| 111 | xdsresource.WatchListener(client, listenerResourceName, noopListenerWatcher{}) |
| 112 | mdWant := stats.MetricsData{ |
| 113 | Handle: xdsClientResourceUpdatesValidMetric.Descriptor(), |
| 114 | IntIncr: 1, |
| 115 | LabelKeys: []string{"grpc.target", "grpc.xds.server", "grpc.xds.resource_type"}, |
nothing calls this directly
no test coverage detected