@@ -53,6 +53,7 @@ tests by ensuring the console output is clean for each test.
53
53
4. parse stdout from otelcol to see if the trace contains the data that we want
54
54
*/
55
55
56
+ // SetupSuite installs the echo-server and curl pods
56
57
func (s * testingSuite ) SetupSuite () {
57
58
var err error
58
59
@@ -91,6 +92,7 @@ func (s *testingSuite) SetupSuite() {
91
92
s .NoError (err , "can apply service/gateway-proxy-tracing" )
92
93
}
93
94
95
+ // TearDownSuite cleans up the resources created in SetupSuite
94
96
func (s * testingSuite ) TearDownSuite () {
95
97
var err error
96
98
@@ -105,6 +107,7 @@ func (s *testingSuite) TearDownSuite() {
105
107
s .NoError (err , "can delete service/gateway-proxy-tracing" )
106
108
}
107
109
110
+ // BeforeTest sets up the common resources (otel, upstreams, virtual services)
108
111
func (s * testingSuite ) BeforeTest (string , string ) {
109
112
var err error
110
113
@@ -138,10 +141,24 @@ func (s *testingSuite) BeforeTest(string, string) {
138
141
core .Status_Accepted ,
139
142
gloo_defaults .GlooReporter ,
140
143
)
144
+ }
145
+
146
+ // AfterTest cleans up the common resources (otel, upstreams, virtual services)
147
+ func (s * testingSuite ) AfterTest (string , string ) {
148
+ var err error
149
+ err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , setupOtelcolManifest )
150
+ s .Assertions .NoError (err , "can delete otel collector" )
141
151
142
- err = s .testInstallation .Actions .Kubectl ().ApplyFile (s .ctx , gatewayConfigManifest ,
152
+ err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , tracingConfigManifest )
153
+ s .Assertions .NoError (err , "can delete gloo tracing config" )
154
+ }
155
+
156
+ // BeforeGlooGatewayTest sets up the Gloo Gateway resources
157
+ func (s * testingSuite ) BeforeGlooGatewayTest () {
158
+ err := s .testInstallation .Actions .Kubectl ().ApplyFile (s .ctx , gatewayConfigManifest ,
143
159
"-n" , s .testInstallation .Metadata .InstallNamespace )
144
160
s .NoError (err , "can create gateway and service" )
161
+
145
162
s .testInstallation .Assertions .EventuallyResourceStatusMatchesState (
146
163
func () (resources.InputResource , error ) {
147
164
return s .testInstallation .ResourceClients .GatewayClient ().Read (
@@ -152,20 +169,39 @@ func (s *testingSuite) BeforeTest(string, string) {
152
169
)
153
170
}
154
171
155
- func (s * testingSuite ) AfterTest (string , string ) {
156
- var err error
157
- err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , setupOtelcolManifest )
158
- s .Assertions .NoError (err , "can delete otel collector" )
159
-
160
- err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , tracingConfigManifest )
161
- s .Assertions .NoError (err , "can delete gloo tracing config" )
162
-
163
- err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , gatewayConfigManifest ,
172
+ // AfterGlooGatewayTest cleans up the Gloo Gateway resources
173
+ func (s * testingSuite ) AfterGlooGatewayTest () {
174
+ err := s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , gatewayConfigManifest ,
164
175
"-n" , s .testInstallation .Metadata .InstallNamespace )
165
176
s .Assertions .NoError (err , "can delete gateway config" )
166
177
}
167
178
168
- func (s * testingSuite ) TestSpanNameTransformationsWithoutRouteDecorator () {
179
+ // BeforeK8sGatewayTest sets up the K8s Gateway resources
180
+ func (s * testingSuite ) BeforeK8sGatewayTest (hloManifest string ) {
181
+ if ! s .testInstallation .Metadata .K8sGatewayEnabled {
182
+ s .T ().Skip ("Installation of Gloo Gateway does not have K8s Gateway enabled, skipping test as there is nothing to test" )
183
+ }
184
+
185
+ s .T ().Cleanup (func () {
186
+ err := s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , k8sGatewayManifest )
187
+ s .Assertions .NoError (err , "cannot delete k8s gateway resources" )
188
+
189
+ err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , hloManifest )
190
+ s .Assertions .NoError (err , "cannot delete k8s gateway hlo" )
191
+ })
192
+
193
+ err := s .testInstallation .Actions .Kubectl ().ApplyFile (s .ctx , hloManifest )
194
+ s .Assertions .NoError (err , "can apply k8s gateway hlo" )
195
+
196
+ err = s .testInstallation .Actions .Kubectl ().ApplyFile (s .ctx , k8sGatewayManifest )
197
+ s .Assertions .NoError (err , "can apply k8s gateway resources" )
198
+
199
+ s .testInstallation .Assertions .EventuallyObjectsExist (s .ctx , proxyService , proxyDeployment )
200
+ }
201
+
202
+ func (s * testingSuite ) TestGlooGatewaySpanNameTransformationsWithoutRouteDecorator () {
203
+ s .BeforeGlooGatewayTest ()
204
+
169
205
testHostname := "test-really-cool-hostname.com"
170
206
s .testInstallation .Assertions .AssertEventuallyConsistentCurlResponse (s .ctx , testdefaults .CurlPodExecOpt ,
171
207
[]curl.Option {
@@ -191,9 +227,13 @@ func (s *testingSuite) TestSpanNameTransformationsWithoutRouteDecorator() {
191
227
// Name : <value of host header>
192
228
assert .Regexp (c , "Name *: " + testHostname , logs )
193
229
}, time .Second * 30 , time .Second * 3 , "otelcol logs contain span with name == hostname" )
230
+
231
+ s .AfterGlooGatewayTest ()
194
232
}
195
233
196
- func (s * testingSuite ) TestSpanNameTransformationsWithRouteDecorator () {
234
+ func (s * testingSuite ) TestGlooGatewaySpanNameTransformationsWithRouteDecorator () {
235
+ s .BeforeGlooGatewayTest ()
236
+
197
237
s .testInstallation .Assertions .AssertEventuallyConsistentCurlResponse (s .ctx , testdefaults .CurlPodExecOpt ,
198
238
[]curl.Option {
199
239
curl .WithHost (kubeutils .ServiceFQDN (metav1.ObjectMeta {
@@ -218,9 +258,13 @@ func (s *testingSuite) TestSpanNameTransformationsWithRouteDecorator() {
218
258
// Name : <value of routeDescriptorSpanName>
219
259
assert .Regexp (c , "Name *: " + routeDescriptorSpanName , logs )
220
260
}, time .Second * 30 , time .Second * 3 , "otelcol logs contain span with name == routeDescriptor" )
261
+
262
+ s .AfterGlooGatewayTest ()
221
263
}
222
264
223
- func (s * testingSuite ) TestGatewayWithoutOtelTracingGrpcAuthority () {
265
+ func (s * testingSuite ) TestGlooGatewayWithoutOtelTracingGrpcAuthority () {
266
+ s .BeforeGlooGatewayTest ()
267
+
224
268
s .testInstallation .Assertions .AssertEventuallyConsistentCurlResponse (s .ctx , testdefaults .CurlPodExecOpt ,
225
269
[]curl.Option {
226
270
curl .WithHost (kubeutils .ServiceFQDN (metav1.ObjectMeta {
@@ -244,9 +288,20 @@ func (s *testingSuite) TestGatewayWithoutOtelTracingGrpcAuthority() {
244
288
assert .Regexp (c , `-> authority: Str\(opentelemetry-collector_default\)` , logs )
245
289
//s.Fail("this test is not implemented yet")
246
290
}, time .Second * 30 , time .Second * 3 , "otelcol logs contain cluster name as authority" )
291
+
292
+ s .AfterGlooGatewayTest ()
247
293
}
248
294
249
- func (s * testingSuite ) TestGatewayWithOtelTracingGrpcAuthority () {
295
+ func (s * testingSuite ) TestGlooGatewayWithOtelTracingGrpcAuthority () {
296
+ s .BeforeGlooGatewayTest ()
297
+
298
+ s .T ().Cleanup (func () {
299
+ // cleanup the gateway
300
+ err := s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , gatewayAuthorityConfigManifest ,
301
+ "-n" , s .testInstallation .Metadata .InstallNamespace )
302
+ s .Assertions .NoError (err , "can delete gateway config" )
303
+ })
304
+
250
305
// create new gateway with grpc authority set
251
306
err := s .testInstallation .Actions .Kubectl ().ApplyFile (s .ctx , gatewayAuthorityConfigManifest ,
252
307
"-n" , s .testInstallation .Metadata .InstallNamespace )
@@ -260,13 +315,6 @@ func (s *testingSuite) TestGatewayWithOtelTracingGrpcAuthority() {
260
315
gloo_defaults .GlooReporter ,
261
316
)
262
317
263
- s .T ().Cleanup (func () {
264
- // cleanup the gateway
265
- err = s .testInstallation .Actions .Kubectl ().DeleteFile (s .ctx , gatewayAuthorityConfigManifest ,
266
- "-n" , s .testInstallation .Metadata .InstallNamespace )
267
- s .Assertions .NoError (err , "can delete gateway config" )
268
- })
269
-
270
318
s .testInstallation .Assertions .AssertEventuallyConsistentCurlResponse (s .ctx , testdefaults .CurlPodExecOpt ,
271
319
[]curl.Option {
272
320
curl .WithHost (kubeutils .ServiceFQDN (metav1.ObjectMeta {
@@ -292,3 +340,55 @@ func (s *testingSuite) TestGatewayWithOtelTracingGrpcAuthority() {
292
340
//s.Fail("this test is not implemented yet")
293
341
}, time .Second * 30 , time .Second * 3 , "otelcol logs contain authority set in gateway" )
294
342
}
343
+
344
+ func (s * testingSuite ) TestK8sGatewayWithOtelTracing () {
345
+ s .BeforeK8sGatewayTest (k8sGatewayHloTracingManifest )
346
+
347
+ s .testInstallation .Assertions .AssertEventuallyConsistentCurlResponse (
348
+ s .ctx ,
349
+ testdefaults .CurlPodExecOpt ,
350
+ []curl.Option {
351
+ curl .WithHost (kubeutils .ServiceFQDN (proxyService .ObjectMeta )),
352
+ curl .WithHostHeader ("example.com" ),
353
+ curl .Silent (),
354
+ },
355
+ & matchers.HttpResponse {
356
+ StatusCode : http .StatusOK ,
357
+ },
358
+ 5 * time .Second , 30 * time .Second ,
359
+ )
360
+
361
+ s .EventuallyWithT (func (c * assert.CollectT ) {
362
+ logs , err := s .testInstallation .Actions .Kubectl ().GetContainerLogs (s .ctx ,
363
+ otelcolPod .ObjectMeta .GetNamespace (), otelcolPod .ObjectMeta .GetName ())
364
+ assert .NoError (c , err , "can get otelcol logs" )
365
+
366
+ assert .Regexp (c , `-> authority: Str\(opentelemetry-collector_default\)` , logs )
367
+ }, time .Second * 30 , time .Second * 3 , "otelcol logs contain cluster name as authority" )
368
+ }
369
+
370
+ func (s * testingSuite ) TestK8sGatewayWithOtelTracingGrpcAuthority () {
371
+ s .BeforeK8sGatewayTest (k8sGatewayHloAuthorityManifest )
372
+
373
+ s .testInstallation .Assertions .AssertEventuallyConsistentCurlResponse (
374
+ s .ctx ,
375
+ testdefaults .CurlPodExecOpt ,
376
+ []curl.Option {
377
+ curl .WithHost (kubeutils .ServiceFQDN (proxyService .ObjectMeta )),
378
+ curl .WithHostHeader ("example.com" ),
379
+ curl .Silent (),
380
+ },
381
+ & matchers.HttpResponse {
382
+ StatusCode : http .StatusOK ,
383
+ },
384
+ 5 * time .Second , 30 * time .Second ,
385
+ )
386
+
387
+ s .EventuallyWithT (func (c * assert.CollectT ) {
388
+ logs , err := s .testInstallation .Actions .Kubectl ().GetContainerLogs (s .ctx ,
389
+ otelcolPod .ObjectMeta .GetNamespace (), otelcolPod .ObjectMeta .GetName ())
390
+ assert .NoError (c , err , "can get otelcol logs" )
391
+
392
+ assert .Regexp (c , `-> authority: Str\(test-authority\)` , logs )
393
+ }, time .Second * 30 , time .Second * 3 , "otelcol logs contain authority set in gateway" )
394
+ }
0 commit comments