-
Notifications
You must be signed in to change notification settings - Fork 66
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
Summarize compact snapshot logs to reduce noise #467
Changes from 5 commits
7b95308
6637bfd
61dc1e2
5f63009
707c0f7
70be798
651c191
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"io" | ||
"net/http" | ||
"net/url" | ||
"sort" | ||
"strings" | ||
"time" | ||
|
||
|
@@ -137,7 +138,29 @@ func submitCompactSnapshot(ctx context.Context, server *state.Server, collection | |
if len(msg) > 0 && collectionOpts.TestRun { | ||
logger.PrintInfo(" %s", msg) | ||
} else if !quiet { | ||
logger.PrintInfo("Submitted compact %s snapshot successfully", kind) | ||
logger.PrintVerbose("Submitted compact %s snapshot successfully", kind) | ||
if server.CompactLogTime.IsZero() { | ||
server.CompactLogTime = time.Now() | ||
server.CompactLogStats = make(map[string]uint8) | ||
} else if time.Now().Sub(server.CompactLogTime) > time.Minute { | ||
server.CompactLogTime = time.Now() | ||
var keys []string | ||
for k := range server.CompactLogStats { | ||
keys = append(keys, k) | ||
} | ||
sort.Strings(keys) | ||
details := "" | ||
for i, kind := range keys { | ||
details += fmt.Sprintf("%d %s", server.CompactLogStats[kind], kind) | ||
if i < len(keys)-1 { | ||
details += ", " | ||
} | ||
} | ||
logger.PrintInfo("Compact snapshots submitted: " + details) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we ever get here with an empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK that would only happen if all snapshots failed, which would be logged as errors separately. I'll go ahead and add a presence check here. |
||
server.CompactLogStats = make(map[string]uint8) | ||
} else { | ||
server.CompactLogStats[kind] = server.CompactLogStats[kind] + 1 | ||
} | ||
} | ||
|
||
return nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal, but since this is part of resetting the log stats state, it feels like it belongs together with resetting the map below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally didn't do that, to avoid clock skew from the time it takes to build the log message. But it should never take a long time and this code path is non-critical so I'll move it down to improve readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 a way to avoid the timestamp changing over time would be to truncate it to the nearest even minute, instead of simply using
time.Now()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would ensure we always print the log at an even minute. Though it does mean that when initially starting up the collector you may have to wait was long as 1m59s before anything is logged.
Or is it 1m30s? I'm not 100% sure what
Truncate
doesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example output:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and added this change; it's nice that the logs show up reliably at the same time every minute.