From 7e31a724910aefa749b1f288c0b48b64bd0a360f Mon Sep 17 00:00:00 2001 From: Sean Rankine Date: Wed, 11 Dec 2024 15:36:35 +0000 Subject: [PATCH] Remove testing logging --- integration_tests/integration_test.go | 10 +--- integration_tests/proxy_function_test.go | 31 ----------- integration_tests/router_logging.go | 69 ------------------------ integration_tests/router_support.go | 1 - 4 files changed, 1 insertion(+), 110 deletions(-) delete mode 100644 integration_tests/router_logging.go diff --git a/integration_tests/integration_test.go b/integration_tests/integration_test.go index 7f44e476..21e0d253 100644 --- a/integration_tests/integration_test.go +++ b/integration_tests/integration_test.go @@ -18,10 +18,7 @@ func TestEverything(t *testing.T) { var _ = BeforeSuite(func() { runtime.GOMAXPROCS(runtime.NumCPU()) - err := setupTempLogfile() - if err != nil { - Fail(err.Error()) - } + var err error ctx := context.Background() @@ -45,12 +42,7 @@ var _ = BeforeSuite(func() { } }) -var _ = BeforeEach(func() { - resetTempLogfile() -}) - var _ = AfterSuite(func() { stopRouter(routerPort) cleanupPostgresContainer() - cleanupTempLogfile() }) diff --git a/integration_tests/proxy_function_test.go b/integration_tests/proxy_function_test.go index 127d0321..a7741ece 100644 --- a/integration_tests/proxy_function_test.go +++ b/integration_tests/proxy_function_test.go @@ -27,16 +27,6 @@ var _ = Describe("Functioning as a reverse proxy", func() { resp := doRequest(req) Expect(resp.StatusCode).To(Equal(502)) - - logDetails := lastRouterErrorLogEntry() - Expect(logDetails.Fields).To(Equal(map[string]interface{}{ - "error": "dial tcp 127.0.0.1:6803: connect: connection refused", - "request": "GET /not-running HTTP/1.1", - "request_method": "GET", - "status": float64(502), // All numbers in JSON are floating point - "upstream_addr": "127.0.0.1:6803", - })) - Expect(logDetails.Timestamp).To(BeTemporally("~", time.Now(), time.Second)) }) It("should log and return a 504 if the connection times out in the configured time", func() { @@ -56,16 +46,6 @@ var _ = Describe("Functioning as a reverse proxy", func() { Expect(resp.StatusCode).To(Equal(504)) Expect(duration).To(BeNumerically("~", 320*time.Millisecond, 20*time.Millisecond)) // 300 - 340 ms - - logDetails := lastRouterErrorLogEntry() - Expect(logDetails.Fields).To(Equal(map[string]interface{}{ - "error": "dial tcp 240.0.0.0:1234: i/o timeout", - "request": "GET /should-time-out HTTP/1.1", - "request_method": "GET", - "status": float64(504), // All numbers in JSON are floating point - "upstream_addr": "240.0.0.0:1234", - })) - Expect(logDetails.Timestamp).To(BeTemporally("~", time.Now(), time.Second)) }) Describe("response header timeout", func() { @@ -91,17 +71,6 @@ var _ = Describe("Functioning as a reverse proxy", func() { req := newRequest(http.MethodGet, routerURL(3167, "/tarpit1")) resp := doRequest(req) Expect(resp.StatusCode).To(Equal(504)) - - logDetails := lastRouterErrorLogEntry() - tarpitURL, _ := url.Parse(tarpit1.URL) - Expect(logDetails.Fields).To(Equal(map[string]interface{}{ - "error": "net/http: timeout awaiting response headers", - "request": "GET /tarpit1 HTTP/1.1", - "request_method": "GET", - "status": float64(504), // All numbers in JSON are floating point - "upstream_addr": tarpitURL.Host, - })) - Expect(logDetails.Timestamp).To(BeTemporally("~", time.Now(), time.Second)) }) It("should still return the response if the body takes longer than the header timeout", func() { diff --git a/integration_tests/router_logging.go b/integration_tests/router_logging.go deleted file mode 100644 index 461ff3ab..00000000 --- a/integration_tests/router_logging.go +++ /dev/null @@ -1,69 +0,0 @@ -package integration - -import ( - "bufio" - "encoding/json" - "os" - "time" - - // revive:disable:dot-imports - . "github.com/onsi/gomega" - // revive:enable:dot-imports -) - -var ( - tempLogfile *os.File -) - -func setupTempLogfile() error { - file, err := os.CreateTemp("", "router_error_log") - if err != nil { - return err - } - tempLogfile = file - return nil -} - -func resetTempLogfile() { - _, err := tempLogfile.Seek(0, 0) - Expect(err).NotTo(HaveOccurred()) - err = tempLogfile.Truncate(0) - Expect(err).NotTo(HaveOccurred()) -} - -func cleanupTempLogfile() { - if tempLogfile != nil { - tempLogfile.Close() - os.Remove(tempLogfile.Name()) - } -} - -type routerLogEntry struct { - Timestamp time.Time `json:"@timestamp"` - Fields map[string]interface{} `json:"@fields"` -} - -func lastRouterErrorLogLine() []byte { - var line []byte - - Eventually(func() ([]byte, error) { - scanner := bufio.NewScanner(tempLogfile) - for scanner.Scan() { - line = scanner.Bytes() - } - if err := scanner.Err(); err != nil { - return nil, err - } - return line, nil - }).ShouldNot(BeNil(), "No log line found after 1 second") - - return line -} - -func lastRouterErrorLogEntry() *routerLogEntry { - line := lastRouterErrorLogLine() - var entry *routerLogEntry - err := json.Unmarshal(line, &entry) - Expect(err).NotTo(HaveOccurred()) - return entry -} diff --git a/integration_tests/router_support.go b/integration_tests/router_support.go index b19f9adb..64e550bb 100644 --- a/integration_tests/router_support.go +++ b/integration_tests/router_support.go @@ -92,7 +92,6 @@ func startRouter(port, apiPort int, extraEnv []string) error { cmd.Env = append(cmd.Env, fmt.Sprintf("ROUTER_PUBADDR=%s", pubAddr)) cmd.Env = append(cmd.Env, fmt.Sprintf("ROUTER_APIADDR=%s", apiAddr)) - cmd.Env = append(cmd.Env, fmt.Sprintf("ROUTER_ERROR_LOG=%s", tempLogfile.Name())) cmd.Env = append(cmd.Env, "CONTENT_STORE_DATABASE_URL="+postgresContainer.MustConnectionString(context.Background())) cmd.Env = append(cmd.Env, extraEnv...)