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

Method TestCSMPluginOptionUnary

stats/opentelemetry/csm/observability_test.go:100–257  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

98// provided OpenTelemetry SDK's Meter Provider. The CSM Labels emitted from the
99// plugin option should be attached to the relevant metrics.
100func (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 },

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
StopMethod · 0.95
SetHeaderFunction · 0.92
NewFunction · 0.92
SendHeaderFunction · 0.92
DefaultMetricsFunction · 0.92
UseCompressorFunction · 0.92
setupEnvFunction · 0.85
newPluginOptionFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected