TestCSMPluginOptionUnary tests the CSM Plugin Option and labels. It configures the environment for the CSM Plugin Option to read from. It then configures a system with a gRPC Client and gRPC server with the OpenTelemetry Dial and Server Option configured with a CSM Plugin Option with a certain unary
(t *testing.T)
| 98 | // provided OpenTelemetry SDK's Meter Provider. The CSM Labels emitted from the |
| 99 | // plugin option should be attached to the relevant metrics. |
| 100 | func (s) TestCSMPluginOptionUnary(t *testing.T) { |
| 101 | resourceDetectorEmissions := map[string]string{ |
| 102 | "cloud.platform": "gcp_kubernetes_engine", |
| 103 | "cloud.region": "cloud_region_val", // availability_zone isn't present, so this should become location |
| 104 | "cloud.account.id": "cloud_account_id_val", |
| 105 | "k8s.namespace.name": "k8s_namespace_name_val", |
| 106 | "k8s.cluster.name": "k8s_cluster_name_val", |
| 107 | } |
| 108 | const meshID = "mesh_id" |
| 109 | const csmCanonicalServiceName = "csm_canonical_service_name" |
| 110 | const csmWorkloadName = "csm_workload_name" |
| 111 | setupEnv(t, resourceDetectorEmissions, meshID, csmCanonicalServiceName, csmWorkloadName) |
| 112 | |
| 113 | attributesWant := map[string]string{ |
| 114 | "csm.workload_canonical_service": csmCanonicalServiceName, // from env |
| 115 | "csm.mesh_id": "mesh_id", // from bootstrap env var |
| 116 | |
| 117 | // No xDS Labels - this happens in a test below. |
| 118 | |
| 119 | "csm.remote_workload_type": "gcp_kubernetes_engine", |
| 120 | "csm.remote_workload_canonical_service": csmCanonicalServiceName, |
| 121 | "csm.remote_workload_project_id": "cloud_account_id_val", |
| 122 | "csm.remote_workload_cluster_name": "k8s_cluster_name_val", |
| 123 | "csm.remote_workload_namespace_name": "k8s_namespace_name_val", |
| 124 | "csm.remote_workload_location": "cloud_region_val", |
| 125 | "csm.remote_workload_name": csmWorkloadName, |
| 126 | } |
| 127 | |
| 128 | var csmLabels []attribute.KeyValue |
| 129 | for k, v := range attributesWant { |
| 130 | csmLabels = append(csmLabels, attribute.String(k, v)) |
| 131 | } |
| 132 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 133 | defer cancel() |
| 134 | tests := []struct { |
| 135 | name string |
| 136 | // To test the different operations for Unary RPC's from the interceptor |
| 137 | // level that can plumb metadata exchange header in. |
| 138 | unaryCallFunc func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) |
| 139 | opts itestutils.MetricDataOptions |
| 140 | }{ |
| 141 | { |
| 142 | name: "normal-flow", |
| 143 | unaryCallFunc: func(_ context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { |
| 144 | return &testpb.SimpleResponse{Payload: &testpb.Payload{ |
| 145 | Body: make([]byte, len(in.GetPayload().GetBody())), |
| 146 | }}, nil |
| 147 | }, |
| 148 | opts: itestutils.MetricDataOptions{ |
| 149 | CSMLabels: csmLabels, |
| 150 | UnaryCompressedMessageSize: float64(57), |
| 151 | }, |
| 152 | }, |
| 153 | { |
| 154 | name: "trailers-only", |
| 155 | unaryCallFunc: func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { |
| 156 | return nil, errors.New("some error") // return an error and no message - this triggers trailers only - no messages or headers sent |
| 157 | }, |
nothing calls this directly
no test coverage detected