From d0511a35af2b9c11636ac35f1892d0e26e16eb43 Mon Sep 17 00:00:00 2001 From: Spencer Taylor-Brown Date: Tue, 26 Mar 2024 06:30:38 +0000 Subject: [PATCH 1/2] simulators/eth/engine: Only trim rpc logs at low log levels. --- simulators/ethereum/engine/helper/helper.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/simulators/ethereum/engine/helper/helper.go b/simulators/ethereum/engine/helper/helper.go index 349a732b4c..5ca8e23195 100644 --- a/simulators/ethereum/engine/helper/helper.go +++ b/simulators/ethereum/engine/helper/helper.go @@ -2,6 +2,7 @@ package helper import ( "context" + "strconv" "sync" "time" @@ -53,7 +54,10 @@ func (rt *LoggingRoundTrip) RoundTrip(req *http.Request) (*http.Response, error) return nil, err } reqLogBytes := bytes.TrimSpace(reqBytes[:]) - if len(reqLogBytes) > MAX_LOG_BYTES { + + hiveLogLevel, _ := strconv.Atoi(os.Getenv("HIVE_LOGLEVEL")) + reqTrimLogs := len(reqLogBytes) > MAX_LOG_BYTES && hiveLogLevel <= 3 + if reqTrimLogs { rt.Logger.Logf(">> (%s) %s... (Log trimmed)", rt.ID, reqLogBytes[:MAX_LOG_BYTES]) } else { rt.Logger.Logf(">> (%s) %s", rt.ID, reqLogBytes) @@ -76,7 +80,9 @@ func (rt *LoggingRoundTrip) RoundTrip(req *http.Request) (*http.Response, error) respCopy := *resp respCopy.Body = io.NopCloser(bytes.NewReader(respBytes)) respLogBytes := bytes.TrimSpace(respBytes[:]) - if len(respLogBytes) > MAX_LOG_BYTES { + + respTrimLogs := len(respLogBytes) > MAX_LOG_BYTES && hiveLogLevel <= 3 + if respTrimLogs { rt.Logger.Logf("<< (%s) %s... (Log trimmed)", rt.ID, respLogBytes[:MAX_LOG_BYTES]) } else { rt.Logger.Logf("<< (%s) %s", rt.ID, respLogBytes) From c08b4bbf39e7df8ae73e4e5135e8541f9c6493bb Mon Sep 17 00:00:00 2001 From: Spencer Taylor-Brown Date: Wed, 27 Mar 2024 05:05:17 +0000 Subject: [PATCH 2/2] simulators/eth/engine: Optimize log level instantiation. --- .../ethereum/engine/client/hive_rpc/hive_rpc.go | 10 +++++++--- simulators/ethereum/engine/helper/helper.go | 14 ++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/simulators/ethereum/engine/client/hive_rpc/hive_rpc.go b/simulators/ethereum/engine/client/hive_rpc/hive_rpc.go index d055d1d346..2f2d8c77ab 100644 --- a/simulators/ethereum/engine/client/hive_rpc/hive_rpc.go +++ b/simulators/ethereum/engine/client/hive_rpc/hive_rpc.go @@ -7,6 +7,8 @@ import ( "math/big" "net" "net/http" + "os" + "strconv" "strings" "sync" "time" @@ -108,10 +110,12 @@ func (s HiveRPCEngineStarter) StartClient(T *hivesim.T, testContext context.Cont if err := CheckEthEngineLive(c); err != nil { return nil, fmt.Errorf("Engine/Eth ports were never open for client: %v", err) } + hiveLogLevel, _ := strconv.Atoi(os.Getenv("HIVE_LOGLEVEL")) ec := NewHiveRPCEngineClient(c, enginePort, ethPort, jwtSecret, ttd, &helper.LoggingRoundTrip{ - Logger: T, - ID: c.Container, - Inner: http.DefaultTransport, + Logger: T, + ID: c.Container, + Inner: http.DefaultTransport, + LogLevel: hiveLogLevel, }) return ec, nil } diff --git a/simulators/ethereum/engine/helper/helper.go b/simulators/ethereum/engine/helper/helper.go index 5ca8e23195..aaf040669c 100644 --- a/simulators/ethereum/engine/helper/helper.go +++ b/simulators/ethereum/engine/helper/helper.go @@ -2,7 +2,6 @@ package helper import ( "context" - "strconv" "sync" "time" @@ -39,9 +38,10 @@ type LogF interface { } type LoggingRoundTrip struct { - Logger LogF - ID string - Inner http.RoundTripper + Logger LogF + ID string + Inner http.RoundTripper + LogLevel int } const MAX_LOG_BYTES = 1024 * 4 @@ -54,9 +54,7 @@ func (rt *LoggingRoundTrip) RoundTrip(req *http.Request) (*http.Response, error) return nil, err } reqLogBytes := bytes.TrimSpace(reqBytes[:]) - - hiveLogLevel, _ := strconv.Atoi(os.Getenv("HIVE_LOGLEVEL")) - reqTrimLogs := len(reqLogBytes) > MAX_LOG_BYTES && hiveLogLevel <= 3 + reqTrimLogs := len(reqLogBytes) > MAX_LOG_BYTES && rt.LogLevel <= 3 if reqTrimLogs { rt.Logger.Logf(">> (%s) %s... (Log trimmed)", rt.ID, reqLogBytes[:MAX_LOG_BYTES]) } else { @@ -81,7 +79,7 @@ func (rt *LoggingRoundTrip) RoundTrip(req *http.Request) (*http.Response, error) respCopy.Body = io.NopCloser(bytes.NewReader(respBytes)) respLogBytes := bytes.TrimSpace(respBytes[:]) - respTrimLogs := len(respLogBytes) > MAX_LOG_BYTES && hiveLogLevel <= 3 + respTrimLogs := len(respLogBytes) > MAX_LOG_BYTES && rt.LogLevel <= 3 if respTrimLogs { rt.Logger.Logf("<< (%s) %s... (Log trimmed)", rt.ID, respLogBytes[:MAX_LOG_BYTES]) } else {