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
Changes from 1 commit
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: 8 additions & 2 deletions simulators/ethereum/engine/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helper

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

Expand Down Expand Up @@ -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"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could do this when instantiating the LoggingRoundTrip to not have to parse this from the env variable on every single HTTP call we do. Seems expensive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh ofc! Sheesh - will change it :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this in: c08b4bb

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