Skip to content

Commit

Permalink
avoid showing repeated messages (#16118)
Browse files Browse the repository at this point in the history
Sometimes we show hundreds of repeated messages in the logs, e.g.
"waiting for quiescence; 3 outputs outstanding". This just makes the
logs harder to read. Since we need to wait for the test to finish before
any of this is shown anyway, only log each message once and show a
little blurb about how often the message has been repeated.

(Note that for simplicity if the last message is repeated we don't show
the same blurb, but that should be okay since the last messages we're
logging are always different.)

Based on #16117 where I noticed
this, and I didn't want to rebase it to avoid conflicts.
  • Loading branch information
tgummerer committed May 6, 2024
1 parent e8b62fa commit b072edb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sdk/nodejs/cmd/pulumi-language-nodejs/language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ import (
type hostEngine struct {
pulumirpc.UnimplementedEngineServer
t *testing.T

logRepeat int
previousMessage string
}

func (e *hostEngine) Log(_ context.Context, req *pulumirpc.LogRequest) (*pbempty.Empty, error) {
Expand All @@ -66,6 +69,17 @@ func (e *hostEngine) Log(_ context.Context, req *pulumirpc.LogRequest) (*pbempty
}
}

if e.previousMessage == message {
e.logRepeat++
return &pbempty.Empty{}, nil
}

if e.logRepeat > 1 {
e.t.Logf("Last message repeated %d times", e.logRepeat)
}
e.logRepeat = 1
e.previousMessage = message

if req.StreamId != 0 {
e.t.Logf("(%d) %s[%s]: %s", req.StreamId, sev, req.Urn, message)
} else {
Expand Down
14 changes: 14 additions & 0 deletions sdk/python/cmd/pulumi-language-python/language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import (
type hostEngine struct {
pulumirpc.UnimplementedEngineServer
t *testing.T

logRepeat int
previousMessage string
}

func (e *hostEngine) Log(_ context.Context, req *pulumirpc.LogRequest) (*pbempty.Empty, error) {
Expand All @@ -68,6 +71,17 @@ func (e *hostEngine) Log(_ context.Context, req *pulumirpc.LogRequest) (*pbempty
}
}

if e.previousMessage == message {
e.logRepeat++
return &pbempty.Empty{}, nil
}

if e.logRepeat > 1 {
e.t.Logf("Last message repeated %d times", e.logRepeat)
}
e.logRepeat = 1
e.previousMessage = message

if req.StreamId != 0 {
e.t.Logf("(%d) %s[%s]: %s", req.StreamId, sev, req.Urn, message)
} else {
Expand Down

0 comments on commit b072edb

Please sign in to comment.