-
Notifications
You must be signed in to change notification settings - Fork 15
Refactor Logger to SafeLogger, part 1 #5619
Changes from all commits
a992a37
ecef0db
690aeb8
3a5b08b
ab3b45a
b2918ff
2fd8b72
f354950
e436b8d
0b7b339
6ca3e3c
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 |
---|---|---|
|
@@ -42,7 +42,10 @@ | |
import com.palantir.common.base.Throwables; | ||
import com.palantir.common.streams.KeyedStream; | ||
import com.palantir.logsafe.SafeArg; | ||
import com.palantir.logsafe.UnsafeArg; | ||
import com.palantir.logsafe.exceptions.SafeIllegalStateException; | ||
import com.palantir.logsafe.logger.SafeLogger; | ||
import com.palantir.logsafe.logger.SafeLoggerFactory; | ||
import java.net.InetAddress; | ||
import java.net.InetSocketAddress; | ||
import java.net.UnknownHostException; | ||
|
@@ -63,12 +66,10 @@ | |
import java.util.stream.Collectors; | ||
import org.apache.cassandra.thrift.EndpointDetails; | ||
import org.apache.cassandra.thrift.TokenRange; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class CassandraService implements AutoCloseable { | ||
// TODO(tboam): keep logging on old class? | ||
private static final Logger log = LoggerFactory.getLogger(CassandraService.class); | ||
private static final SafeLogger log = SafeLoggerFactory.get(CassandraService.class); | ||
private static final Interner<RangeMap<LightweightOppToken, List<InetSocketAddress>>> tokensInterner = | ||
Interners.newWeakInterner(); | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Why unsafe? |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
import com.palantir.atlasdb.keyvalue.api.RangeRequest; | ||
import com.palantir.atlasdb.keyvalue.api.TableReference; | ||
import com.palantir.atlasdb.keyvalue.api.Value; | ||
import com.palantir.atlasdb.logging.LoggingArgs; | ||
import com.palantir.atlasdb.schema.SweepSchema; | ||
import com.palantir.atlasdb.schema.generated.SweepPriorityTable; | ||
import com.palantir.atlasdb.schema.generated.SweepPriorityTable.SweepPriorityNamedColumn; | ||
|
@@ -43,6 +44,8 @@ | |
import com.palantir.logsafe.Preconditions; | ||
import com.palantir.logsafe.SafeArg; | ||
import com.palantir.logsafe.UnsafeArg; | ||
import com.palantir.logsafe.logger.SafeLogger; | ||
import com.palantir.logsafe.logger.SafeLoggerFactory; | ||
import com.palantir.timestamp.TimestampService; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
|
@@ -55,8 +58,6 @@ | |
import java.util.concurrent.locks.Lock; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
import java.util.function.Supplier; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This kvs wrapper tracks the approximate number of writes to every table | ||
|
@@ -65,7 +66,7 @@ | |
*/ | ||
public final class SweepStatsKeyValueService extends ForwardingKeyValueService { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(SweepStatsKeyValueService.class); | ||
private static final SafeLogger log = SafeLoggerFactory.get(SweepStatsKeyValueService.class); | ||
private static final int CLEAR_WEIGHT = 1 << 14; // 16384 | ||
private static final long FLUSH_DELAY_SECONDS = 42; | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Is there a benefit to attaching the throwable also as an arg? |
||
} | ||
} | ||
} | ||
|
@@ -311,7 +312,11 @@ private void flushWrites(Multiset<TableReference> writes, Set<TableReference> cl | |
.hydrateFromBytes(oldValue.getContents()) | ||
.getValue(); | ||
long newValue = clears.contains(tableRef) ? writes.count(tableRef) : oldCount + writes.count(tableRef); | ||
log.debug("Sweep priority for {} has {} writes (was {})", tableRef, newValue, oldCount); | ||
log.debug( | ||
"Sweep priority for {} has {} writes (was {})", | ||
LoggingArgs.tableRef(tableRef), | ||
SafeArg.of("newValue", newValue), | ||
SafeArg.of("oldCount", oldCount)); | ||
newWriteCounts.put( | ||
cell, SweepPriorityTable.WriteCount.of(newValue).persistValue()); | ||
} | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. We could add a method to convert these in LoggingArgs? |
||
"Unable to flush sweep stats for writes {} and clears {}: ", | ||
UnsafeArg.of("writes", writes), | ||
UnsafeArg.of("clears", clears), | ||
e); | ||
throw e; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import com.palantir.atlasdb.keyvalue.api.RowResult; | ||
import com.palantir.atlasdb.keyvalue.api.TableReference; | ||
import com.palantir.atlasdb.keyvalue.impl.Cells; | ||
import com.palantir.atlasdb.logging.LoggingArgs; | ||
import com.palantir.atlasdb.transaction.api.Transaction; | ||
import com.palantir.atlasdb.transaction.api.TransactionManager; | ||
import com.palantir.atlasdb.transaction.impl.TransactionConstants; | ||
|
@@ -36,16 +37,18 @@ | |
import com.palantir.common.base.AbortingVisitors; | ||
import com.palantir.common.base.BatchingVisitable; | ||
import com.palantir.common.collect.Maps2; | ||
import com.palantir.logsafe.SafeArg; | ||
import com.palantir.logsafe.UnsafeArg; | ||
import com.palantir.logsafe.logger.SafeLogger; | ||
import com.palantir.logsafe.logger.SafeLoggerFactory; | ||
import com.palantir.util.Mutable; | ||
import com.palantir.util.Mutables; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.commons.lang3.mutable.MutableLong; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class KvsRangeMigrator implements RangeMigrator { | ||
private static final Logger log = LoggerFactory.getLogger(KvsRangeMigrator.class); | ||
private static final SafeLogger log = SafeLoggerFactory.get(KvsRangeMigrator.class); | ||
|
||
private final TableReference srcTable; | ||
private final TableReference destTable; | ||
|
@@ -92,15 +95,18 @@ private void logStatus(Transaction tx, int numRangeBoundaries) { | |
if (checkpoint != null) { | ||
log.info( | ||
"({}/{}) Migration from table {} to table {} will start/resume at {}", | ||
rangeId, | ||
numRangeBoundaries, | ||
srcTable, | ||
destTable, | ||
PtBytes.encodeHexString(checkpoint)); | ||
SafeArg.of("rangeId", rangeId), | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. (this is how you encode the hex string) |
||
return; | ||
} | ||
} | ||
log.info("Migration from table {} to {} has already been completed", srcTable, destTable); | ||
log.info( | ||
"Migration from table {} to {} has already been completed", | ||
LoggingArgs.tableRef("srcTable", srcTable), | ||
LoggingArgs.tableRef("destTable", destTable)); | ||
} | ||
|
||
@Override | ||
|
@@ -144,18 +150,26 @@ private byte[] copyOneTransactionInternal(RangeRequest range, long rangeId, Tran | |
if (log.isTraceEnabled()) { | ||
log.trace( | ||
"Copying table {} range {} from {} to {}", | ||
srcTable, | ||
rangeId, | ||
BaseEncoding.base16().lowerCase().encode(rangeToUse.getStartInclusive()), | ||
BaseEncoding.base16().lowerCase().encode(rangeToUse.getEndExclusive())); | ||
LoggingArgs.tableRef("srcTable", srcTable), | ||
SafeArg.of("rangeId", rangeId), | ||
UnsafeArg.of( | ||
"rangeStartInclusive", | ||
BaseEncoding.base16().lowerCase().encode(rangeToUse.getStartInclusive())), | ||
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. nit: use the |
||
UnsafeArg.of( | ||
"rangeStartExclusive", | ||
BaseEncoding.base16().lowerCase().encode(rangeToUse.getEndExclusive()))); | ||
} | ||
|
||
BatchingVisitable<RowResult<byte[]>> bv = readT.getRange(srcTable, rangeToUse); | ||
|
||
Map<Cell, byte[]> writeMap = new HashMap<>(); | ||
byte[] lastRow = internalCopyRange(bv, maxBytes, writeMap); | ||
if (log.isTraceEnabled() && (lastRow != null)) { | ||
log.trace("Copying {} bytes for range {} on table {}", lastRow.length, rangeId, srcTable); | ||
log.trace( | ||
"Copying {} bytes for range {} on table {}", | ||
SafeArg.of("lengths", lastRow.length), | ||
SafeArg.of("rangeId", rangeId), | ||
LoggingArgs.tableRef("srcTable", srcTable)); | ||
} | ||
writeToKvs(writeMap); | ||
|
||
|
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