Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simulators/ethereum/engine: Trim rpc logs only at low log levels #1066

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions simulators/ethereum/engine/client/hive_rpc/hive_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"math/big"
"net"
"net/http"
"os"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 9 additions & 5 deletions simulators/ethereum/engine/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,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
Expand All @@ -53,7 +54,8 @@ func (rt *LoggingRoundTrip) RoundTrip(req *http.Request) (*http.Response, error)
return nil, err
}
reqLogBytes := bytes.TrimSpace(reqBytes[:])
if len(reqLogBytes) > MAX_LOG_BYTES {
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 {
rt.Logger.Logf(">> (%s) %s", rt.ID, reqLogBytes)
Expand All @@ -76,7 +78,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 && rt.LogLevel <= 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)
Expand Down