[tools][perfmon] Limit length of CL report
Attempting to post a very long message will be rejected by the server.
Change-Id: I5073415fe04b5dcae23c4fcce88db62e822b5b72
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/172543
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
diff --git a/tools/src/cmd/perfmon/main.go b/tools/src/cmd/perfmon/main.go
index 4350bf0..75ade35 100644
--- a/tools/src/cmd/perfmon/main.go
+++ b/tools/src/cmd/perfmon/main.go
@@ -973,13 +973,21 @@
}
postMsg := func(notify, msg string) error {
- _, _, err = e.gerrit.Changes.SetReview(change.ChangeID, currentHash.String(), &gerrit.ReviewInput{
+ _, resp, err := e.gerrit.Changes.SetReview(change.ChangeID, currentHash.String(), &gerrit.ReviewInput{
Message: msg,
Tag: "autogenerated:perfmon",
Notify: notify,
})
+
if err != nil {
- return fmt.Errorf("failed to post message to gerrit change:\n %v", err)
+ body, _ := io.ReadAll(resp.Body)
+ info := &strings.Builder{}
+ fmt.Fprintln(info, "response: ", string(body))
+ fmt.Fprintln(info, "change-id: ", change.ChangeID)
+ fmt.Fprintln(info, "revision-id: ", currentHash.String())
+ fmt.Fprintln(info, "notify: ", notify)
+ fmt.Fprintf(info, "msg:\n<<%v>>\n", msg)
+ return fmt.Errorf("failed to post message to gerrit change:\n %v\n%v", err, info.String())
}
return nil
}
@@ -1025,7 +1033,16 @@
fmt.Fprintln(msg, "```")
fmt.Fprintf(msg, "A: parent change (%v) -> B: patchset %v\n", parent.Commit[:7], current.Number)
fmt.Fprintln(msg)
- for _, line := range strings.Split(diff.Format(diffFmt), "\n") {
+ lines := strings.Split(diff.Format(diffFmt), "\n")
+ const kMaxLines = 50
+ if n := len(lines); n > kMaxLines {
+ trimmed := make([]string, 0, kMaxLines+1)
+ trimmed = append(trimmed, lines[:(kMaxLines/2)]...)
+ trimmed = append(trimmed, fmt.Sprintf("... omitting %v rows ...", n-kMaxLines))
+ trimmed = append(trimmed, lines[n-(kMaxLines/2):]...)
+ lines = trimmed
+ }
+ for _, line := range lines {
fmt.Fprintf(msg, " %v\n", line)
}
fmt.Fprintln(msg, "```")