-
Notifications
You must be signed in to change notification settings - Fork 15
Refactor Logger to SafeLogger, part 1 #5619
Conversation
Generate changelog in
|
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 must have been enjoyable to write!
@@ -151,7 +151,7 @@ private void scheduleSweepRowTask( | |||
// RejectedExecutionException are expected. | |||
// The executor is shutdown when we already fetched all the values we were interested | |||
// for the current iteration. | |||
log.trace("Rejecting row {} because executor is closed", rows.get(rowIndex), e); | |||
log.trace("Rejecting row {} because executor is closed", UnsafeArg.of("row", rows.get(rowIndex)), e); |
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.
These kind of args are crap anyway because we are logging a reference only. I guess therefore it could be also logged as safe, even though the intention was almost certainly to log the hex representation of the byte array (and therefore unsafe). So this is not wrong, but I would drive by fix it and log the actual array
@@ -341,7 +342,7 @@ public void debugLogStateOfPool() { | |||
activeCheckouts > 0 ? Integer.toString(activeCheckouts) : "(unknown)", | |||
totalAllowed > 0 ? Integer.toString(totalAllowed) : "(not bounded)")); | |||
} | |||
log.debug("Current pool state: {}", currentState.toString()); | |||
log.debug("Current pool state: {}", UnsafeArg.of("currentState", currentState.toString())); |
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.
Why unsafe?
@@ -262,7 +263,7 @@ private void flushTask() { | |||
} | |||
} catch (Throwable t) { | |||
if (!Thread.interrupted()) { | |||
log.warn("Error occurred while flushing sweep stats: {}", t, t); | |||
log.warn("Error occurred while flushing sweep stats: {}", UnsafeArg.of("throwable", t), t); |
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.
Is there a benefit to attaching the throwable also as an arg?
@@ -331,7 +336,11 @@ private void flushWrites(Multiset<TableReference> writes, Set<TableReference> cl | |||
// ignore problems when sweep or transaction tables don't exist | |||
log.warn("Ignoring failed sweep stats flush due to ", e); | |||
} | |||
log.warn("Unable to flush sweep stats for writes {} and clears {}: ", writes, clears, e); | |||
log.warn( |
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.
We could add a method to convert these in LoggingArgs?
SafeArg.of("numRangeBoundaries", numRangeBoundaries), | ||
LoggingArgs.tableRef("srcTable", srcTable), | ||
LoggingArgs.tableRef("destTable", destTable), | ||
UnsafeArg.of("checkpoint", PtBytes.encodeHexString(checkpoint))); |
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 is how you encode the hex string)
@@ -190,7 +195,7 @@ private void writeStreamToFile(Transaction transaction, T id, StreamMetadata met | |||
try { | |||
tryWriteStreamToFile(transaction, id, metadata, fos); | |||
} catch (IOException e) { | |||
log.error("Could not finish streaming blocks to file for stream {}", id, e); | |||
log.error("Could not finish streaming blocks to file for stream {}", UnsafeArg.of("stream", id), e); |
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.
Stream ids are probably safe, but no need to change
@@ -248,7 +249,7 @@ public void validate() { | |||
try { | |||
entry.getValue().validate(); | |||
} catch (Exception e) { | |||
log.error("Failed to validate table {}.", entry.getKey(), e); | |||
log.error("Failed to validate table {}.", UnsafeArg.of("tableName", entry.getKey()), e); |
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.
These are table names from schemas, probably should be safe to log? Again, fine to leave as is
@@ -128,7 +135,7 @@ public void truncate() { | |||
public void checkDatabaseVersion() { | |||
AgnosticResultSet result = conns.get().selectResultSetUnregisteredQuery("SHOW server_version"); | |||
String version = result.get(0).getString("server_version"); | |||
PostgresVersionCheck.checkDatabaseVersion(version, log); |
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.
Why not modify the method to take a SafeLogger
instead? If you're worried about public API, you can always keep the old version of the method
SafeArg.of("tableCount", scrubTimestampToTableNameToCell.size()), | ||
SafeArg.of("minTimestamp", minTimestamp), | ||
SafeArg.of("maxTimestamp", maxTimestamp), | ||
UnsafeArg.of("tables", tables)); |
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.
Also maybe use LoggingArgs
} | ||
} | ||
|
||
private Object[] constructSlowLockLogParams(String lockId, LockClient currentHolder, long durationMillis) { |
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.
🎉
Goals (and why): Replace most Logger usage in favor of SafeLogger, to unblock #5597.
Implementation Description (bullets): Each SafeArg vs UnsafeArg decision was made manually, quite conservatively in favor of UnsafeArg due to the large number of changes. For now, only log instances with simple logger declarations were processed.
Testing (What was existing testing like? What have you done to improve it?): Very few places in code test log messages. Nothing was done to improve this.
Concerns (what feedback would you like?): Thoroughly check that all SafeArg instances are actually safe.
Where should we start reviewing?: Wherever.
Priority (whenever / two weeks / yesterday): Not urgent, but blocks baseline upgrade.