6
6
"fmt"
7
7
"net/http"
8
8
"os/exec"
9
+ "slices"
9
10
"strings"
10
11
"time"
11
12
@@ -28,7 +29,7 @@ const (
28
29
ngfContainerName = "nginx-gateway"
29
30
)
30
31
31
- // Since checkContainerLogsForErrors may experience interference from previous tests (as explained in the function
32
+ // Since checkNGFContainerLogsForErrors may experience interference from previous tests (as explained in the function
32
33
// documentation), this test is recommended to be run separate from other tests.
33
34
var _ = Describe ("Graceful Recovery test" , Ordered , Label ("graceful-recovery" ), func () {
34
35
files := []string {
@@ -189,6 +190,9 @@ func runRestartNodeTest(teaURL, coffeeURL string, files []string, ns *core.Names
189
190
}
190
191
191
192
checkNGFFunctionality (teaURL , coffeeURL , ngfPodName , "" , files , ns )
193
+ if errorLogs := getUnexpectedNginxErrorLogs (ngfPodName ); errorLogs != "" {
194
+ Skip (fmt .Sprintf ("NGINX has unexpected error logs: \n %s" , errorLogs ))
195
+ }
192
196
}
193
197
194
198
func runRecoveryTest (teaURL , coffeeURL , ngfPodName , containerName string , files []string , ns * core.Namespace ) {
@@ -219,6 +223,9 @@ func runRecoveryTest(teaURL, coffeeURL, ngfPodName, containerName string, files
219
223
}
220
224
221
225
checkNGFFunctionality (teaURL , coffeeURL , ngfPodName , containerName , files , ns )
226
+ if errorLogs := getUnexpectedNginxErrorLogs (ngfPodName ); errorLogs != "" {
227
+ Skip (fmt .Sprintf ("NGINX has unexpected error logs: \n %s" , errorLogs ))
228
+ }
222
229
}
223
230
224
231
func restartContainer (ngfPodName , containerName string ) {
@@ -347,52 +354,76 @@ func checkNGFFunctionality(teaURL, coffeeURL, ngfPodName, containerName string,
347
354
WithPolling (500 * time .Millisecond ).
348
355
Should (Succeed ())
349
356
350
- checkContainerLogsForErrors (ngfPodName , containerName == nginxContainerName )
357
+ // When the NGINX process is killed, some errors are expected in the NGF logs while we wait for the
358
+ // NGINX container to be restarted. Therefore, we don't want to check the NGF logs for errors when the container
359
+ // we restarted was NGINX.
360
+ if containerName != nginxContainerName {
361
+ checkNGFContainerLogsForErrors (ngfPodName )
362
+ }
351
363
}
352
364
353
- // checkContainerLogsForErrors checks both nginx and NGF container's logs for any possible errors.
354
- // When the NGINX process is killed, some errors are expected in the NGF logs while we wait for the
355
- // NGINX container to be restarted.
356
- func checkContainerLogsForErrors (ngfPodName string , checkNginxLogsOnly bool ) {
365
+ func getNginxErrorLogs (ngfPodName string ) string {
357
366
nginxLogs , err := resourceManager .GetPodLogs (
358
367
ngfNamespace ,
359
368
ngfPodName ,
360
369
& core.PodLogOptions {Container : nginxContainerName },
361
370
)
362
371
Expect (err ).ToNot (HaveOccurred ())
363
372
373
+ errPrefixes := []string {"[crit]" , "[error]" , "[warn]" , "[alert]" , "[emerg]" }
374
+ errorLogs := ""
375
+
364
376
for _ , line := range strings .Split (nginxLogs , "\n " ) {
365
- Expect (line ).ToNot (ContainSubstring ("[crit]" ), line )
366
- Expect (line ).ToNot (ContainSubstring ("[alert]" ), line )
367
- Expect (line ).ToNot (ContainSubstring ("[emerg]" ), line )
368
- if strings .Contains (line , "[error]" ) {
369
- expectedError1 := "connect() failed (111: Connection refused)"
370
- expectedError2 := "could not be resolved (host not found) during usage report"
371
- expectedError3 := "server returned 429"
372
- // FIXME(salonichf5) remove this error message check
373
- // when https://github.com/nginxinc/nginx-gateway-fabric/issues/2090 is completed.
374
- expectedError4 := "no live upstreams while connecting to upstream"
375
- Expect (line ).To (Or (
376
- ContainSubstring (expectedError1 ),
377
- ContainSubstring (expectedError2 ),
378
- ContainSubstring (expectedError3 ),
379
- ContainSubstring (expectedError4 ),
380
- ))
377
+ for _ , prefix := range errPrefixes {
378
+ if strings .Contains (line , prefix ) {
379
+ errorLogs += line + "\n "
380
+ break
381
+ }
381
382
}
382
383
}
383
384
384
- if ! checkNginxLogsOnly {
385
- ngfLogs , err := resourceManager .GetPodLogs (
386
- ngfNamespace ,
387
- ngfPodName ,
388
- & core.PodLogOptions {Container : ngfContainerName },
389
- )
390
- Expect (err ).ToNot (HaveOccurred ())
385
+ return errorLogs
386
+ }
387
+
388
+ func getUnexpectedNginxErrorLogs (ngfPodName string ) string {
389
+ expectedErrStrings := []string {
390
+ "connect() failed (111: Connection refused)" ,
391
+ "could not be resolved (host not found) during usage report" ,
392
+ "server returned 429" ,
393
+ // FIXME(salonichf5) remove this error message check
394
+ // when https://github.com/nginxinc/nginx-gateway-fabric/issues/2090 is completed.
395
+ "no live upstreams while connecting to upstream" ,
396
+ }
397
+
398
+ unexpectedErrors := ""
399
+
400
+ errorLogs := getNginxErrorLogs (ngfPodName )
391
401
392
- for _ , line := range strings .Split (ngfLogs , "\n " ) {
393
- Expect (line ).ToNot (ContainSubstring ("\" level\" :\" error\" " ), line )
402
+ for _ , line := range strings .Split (errorLogs , "\n " ) {
403
+
404
+ if ! slices .ContainsFunc (expectedErrStrings , func (s string ) bool {
405
+ return strings .Contains (line , s )
406
+ }) {
407
+ unexpectedErrors += line
394
408
}
395
409
}
410
+
411
+ return unexpectedErrors
412
+ }
413
+
414
+ // checkNGFContainerLogsForErrors checks NGF container's logs for any possible errors.
415
+ func checkNGFContainerLogsForErrors (ngfPodName string ) {
416
+ ngfLogs , err := resourceManager .GetPodLogs (
417
+ ngfNamespace ,
418
+ ngfPodName ,
419
+ & core.PodLogOptions {Container : ngfContainerName },
420
+ )
421
+ Expect (err ).ToNot (HaveOccurred ())
422
+
423
+ for _ , line := range strings .Split (ngfLogs , "\n " ) {
424
+ Expect (line ).ToNot (ContainSubstring ("\" level\" :\" error\" " ), line )
425
+ }
426
+
396
427
}
397
428
398
429
func checkLeaderLeaseChange (originalLeaseName string ) error {
0 commit comments