Skip to content

Commit

Permalink
simulators/eth/engine: Optimize log level instantiation.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-tb committed Mar 27, 2024
1 parent d0511a3 commit 1a8e721
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
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: 6 additions & 8 deletions simulators/ethereum/engine/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package helper

import (
"context"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 1a8e721

Please sign in to comment.