Skip to content

Commit a6abe4b

Browse files
author
Kate Osborn
committed
Don't fail on nginx errors
1 parent f00abfb commit a6abe4b

File tree

2 files changed

+69
-32
lines changed

2 files changed

+69
-32
lines changed

tests/suite/graceful_recovery_test.go

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"net/http"
88
"os/exec"
9+
"slices"
910
"strings"
1011
"time"
1112

@@ -28,7 +29,7 @@ const (
2829
ngfContainerName = "nginx-gateway"
2930
)
3031

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
3233
// documentation), this test is recommended to be run separate from other tests.
3334
var _ = Describe("Graceful Recovery test", Ordered, Label("graceful-recovery"), func() {
3435
files := []string{
@@ -189,6 +190,9 @@ func runRestartNodeTest(teaURL, coffeeURL string, files []string, ns *core.Names
189190
}
190191

191192
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+
}
192196
}
193197

194198
func runRecoveryTest(teaURL, coffeeURL, ngfPodName, containerName string, files []string, ns *core.Namespace) {
@@ -219,6 +223,9 @@ func runRecoveryTest(teaURL, coffeeURL, ngfPodName, containerName string, files
219223
}
220224

221225
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+
}
222229
}
223230

224231
func restartContainer(ngfPodName, containerName string) {
@@ -347,52 +354,76 @@ func checkNGFFunctionality(teaURL, coffeeURL, ngfPodName, containerName string,
347354
WithPolling(500 * time.Millisecond).
348355
Should(Succeed())
349356

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+
}
351363
}
352364

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 {
357366
nginxLogs, err := resourceManager.GetPodLogs(
358367
ngfNamespace,
359368
ngfPodName,
360369
&core.PodLogOptions{Container: nginxContainerName},
361370
)
362371
Expect(err).ToNot(HaveOccurred())
363372

373+
errPrefixes := []string{"[crit]", "[error]", "[warn]", "[alert]", "[emerg]"}
374+
errorLogs := ""
375+
364376
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+
}
381382
}
382383
}
383384

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)
391401

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
394408
}
395409
}
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+
396427
}
397428

398429
func checkLeaderLeaseChange(originalLeaseName string) error {

tests/suite/reconfig_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ var _ = Describe("Reconfiguration Performance Testing", Ordered, Label("nfr", "r
405405
).WithTimeout(metricExistTimeout).WithPolling(metricExistPolling).Should(Succeed())
406406
}
407407

408-
checkContainerLogsForErrors(ngfPodName, false)
408+
checkNGFContainerLogsForErrors(ngfPodName)
409+
nginxErrorLogs := getNginxErrorLogs(ngfPodName)
409410

410411
reloadCount, err := framework.GetReloadCount(promInstance, ngfPodName)
411412
Expect(err).ToNot(HaveOccurred())
@@ -447,6 +448,7 @@ var _ = Describe("Reconfiguration Performance Testing", Ordered, Label("nfr", "r
447448
TimeToReadyAvgSingle: timeToReadyAvgSingle,
448449
NGINXReloads: int(reloadCount),
449450
NGINXReloadAvgTime: int(reloadAvgTime),
451+
NGINXErrorLogs: nginxErrorLogs,
450452
EventsCount: int(eventsCount),
451453
EventsAvgTime: int(eventsAvgTime),
452454
}
@@ -601,6 +603,7 @@ type reconfigTestResults struct {
601603
NumResources int
602604
NGINXReloads int
603605
NGINXReloadAvgTime int
606+
NGINXErrorLogs string
604607
EventsCount int
605608
EventsAvgTime int
606609
}
@@ -627,6 +630,9 @@ const reconfigResultTemplate = `
627630
{{- range .EventsBuckets }}
628631
- {{ .Le }}ms: {{ .Val }}
629632
{{- end }}
633+
634+
### NGINX Error Logs
635+
{{ .NGINXErrorLogs }}
630636
`
631637

632638
func writeReconfigResults(dest io.Writer, results reconfigTestResults) error {

0 commit comments

Comments
 (0)