Skip to content

Commit

Permalink
Excavator: Migrate to the logsafe SafeLogger API (#1168)
Browse files Browse the repository at this point in the history
  • Loading branch information
svc-excavator-bot authored Jul 27, 2021
1 parent b79b219 commit df57547
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 41 deletions.
2 changes: 1 addition & 1 deletion tritium-caffeine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ dependencies {
api 'io.dropwizard.metrics:metrics-core'

implementation 'com.google.guava:guava'
implementation 'com.palantir.safe-logging:logger'
implementation 'com.palantir.safe-logging:preconditions'
implementation 'com.palantir.safe-logging:safe-logging'
implementation 'io.dropwizard.metrics:metrics-core'
implementation 'org.slf4j:slf4j-api'

testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
import com.google.common.collect.ImmutableMap;
import com.palantir.logsafe.Safe;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.logger.SafeLogger;
import com.palantir.logsafe.logger.SafeLoggerFactory;
import com.palantir.tritium.metrics.InternalCacheMetrics;
import com.palantir.tritium.metrics.MetricRegistries;
import com.palantir.tritium.metrics.registry.TaggedMetricRegistry;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class CaffeineCacheStats {

private static final Logger log = LoggerFactory.getLogger(CaffeineCacheStats.class);
private static final SafeLogger log = SafeLoggerFactory.get(CaffeineCacheStats.class);
private static final String STATS_DISABLED = "cache.stats.disabled";

private CaffeineCacheStats() {}
Expand Down
2 changes: 1 addition & 1 deletion tritium-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ dependencies {

implementation 'com.google.code.findbugs:jsr305'
implementation 'com.google.guava:guava'
implementation 'com.palantir.safe-logging:logger'
implementation 'com.palantir.safe-logging:preconditions'
implementation 'com.palantir.safe-logging:safe-logging'
implementation 'org.slf4j:slf4j-api'

testImplementation project(':tritium-test')
testImplementation 'org.assertj:assertj-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import static com.palantir.logsafe.Preconditions.checkNotNull;

import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.logger.SafeLogger;
import com.palantir.logsafe.logger.SafeLoggerFactory;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Abstract invocation event handler implementation.
Expand All @@ -30,7 +30,7 @@
*/
public abstract class AbstractInvocationEventHandler<C extends InvocationContext> implements InvocationEventHandler<C> {

private static final Logger log = LoggerFactory.getLogger(AbstractInvocationEventHandler.class);
private static final SafeLogger log = SafeLoggerFactory.get(AbstractInvocationEventHandler.class);

private static final Object[] NO_ARGS = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@

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.tritium.api.event.InstrumentationFilter;
import java.lang.reflect.Method;
import java.util.Objects;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class Handlers {

private static final Logger log = LoggerFactory.getLogger(Handlers.class);
private static final SafeLogger log = SafeLoggerFactory.get(Handlers.class);

/**
* The caller is expected to check {@link InvocationEventHandler#isEnabled()} prior to calling this method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
import com.google.common.collect.ImmutableMap;
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.tritium.api.functions.BooleanSupplier;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class InstrumentationProperties {
private static final Logger log = LoggerFactory.getLogger(InstrumentationProperties.class);
private static final SafeLogger log = SafeLoggerFactory.get(InstrumentationProperties.class);

private InstrumentationProperties() {}

Expand Down
1 change: 1 addition & 0 deletions tritium-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
implementation 'net.bytebuddy:byte-buddy'
implementation 'com.google.code.findbugs:jsr305'
implementation 'com.google.guava:guava'
implementation 'com.palantir.safe-logging:logger'
implementation 'com.palantir.safe-logging:preconditions'
implementation 'com.palantir.safe-logging:safe-logging'
implementation 'io.dropwizard.metrics:metrics-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
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 com.palantir.tritium.api.event.InstrumentationFilter;
import com.palantir.tritium.event.CompositeInvocationEventHandler;
import com.palantir.tritium.event.InvocationContext;
Expand All @@ -48,12 +50,10 @@
import net.bytebuddy.implementation.bytecode.assign.Assigner;
import net.bytebuddy.jar.asm.Opcodes;
import net.bytebuddy.matcher.ElementMatchers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final class ByteBuddyInstrumentation {

private static final Logger log = LoggerFactory.getLogger(ByteBuddyInstrumentation.class);
private static final SafeLogger log = SafeLoggerFactory.get(ByteBuddyInstrumentation.class);
// Offset to avoid duplicate fqcns
private static final AtomicInteger offset = new AtomicInteger();
// Reuse generated classes when possible
Expand Down
2 changes: 1 addition & 1 deletion tritium-metrics-jvm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ dependencies {
implementation 'io.dropwizard.metrics:metrics-core'
implementation 'io.dropwizard.metrics:metrics-jvm'
implementation 'com.google.guava:guava'
implementation 'com.palantir.safe-logging:logger'
implementation 'com.palantir.safe-logging:preconditions'
implementation 'com.palantir.safe-logging:safe-logging'
implementation 'org.slf4j:slf4j-api'

testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import com.codahale.metrics.RatioGauge;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.logger.SafeLogger;
import com.palantir.logsafe.logger.SafeLoggerFactory;
import com.sun.management.UnixOperatingSystemMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A gauge to report the ratio of open file descriptors.
Expand All @@ -31,7 +31,7 @@
*/
final class Jdk9CompatibleFileDescriptorRatioGauge {

private static final Logger log = LoggerFactory.getLogger(Jdk9CompatibleFileDescriptorRatioGauge.class);
private static final SafeLogger log = SafeLoggerFactory.get(Jdk9CompatibleFileDescriptorRatioGauge.class);

static void register(InternalJvmMetrics metrics) {
OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

import com.palantir.jvm.diagnostics.JvmDiagnostics;
import com.palantir.jvm.diagnostics.SafepointTimeAccessor;
import com.palantir.logsafe.logger.SafeLogger;
import com.palantir.logsafe.logger.SafeLoggerFactory;
import com.palantir.tritium.metrics.registry.TaggedMetricRegistry;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Report duration spent waiting at safepoints. This could indicate badness in terms of STW GCing, or biased locking
* going badly. See https://stackoverflow.com/questions/29666057/analyzing-gc-logs/29673564#29673564 for details. This
* essentially provides the information of '+PrintGCApplicationStoppedTime' programmatically.
*/
final class SafepointMetrics {
private static final Logger log = LoggerFactory.getLogger(SafepointMetrics.class);
private static final SafeLogger log = SafeLoggerFactory.get(SafepointMetrics.class);

static void register(TaggedMetricRegistry registry) {
Optional<SafepointTimeAccessor> safepointTimeAccessor = JvmDiagnostics.totalSafepointTime();
Expand Down
2 changes: 1 addition & 1 deletion tritium-metrics/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ dependencies {

implementation 'com.google.code.findbugs:jsr305'
implementation 'com.google.guava:guava'
implementation 'com.palantir.safe-logging:logger'
implementation 'com.palantir.safe-logging:preconditions'
implementation 'com.palantir.safe-logging:safe-logging'
implementation ('org.mpierce.metrics.reservoir:hdrhistogram-metrics-reservoir') {
exclude group: 'io.dropwizard.metrics', module: 'metrics-core'
exclude group: 'org.hdrhistogram', module: 'HdrHistogram'
}
implementation 'org.hdrhistogram:HdrHistogram'
implementation 'org.slf4j:slf4j-api'

testImplementation project(':tritium-test')
testImplementation 'com.squareup.okhttp3:okhttp'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
package com.palantir.tritium.metrics;

import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.logger.SafeLogger;
import com.palantir.logsafe.logger.SafeLoggerFactory;
import com.palantir.tritium.event.InstrumentationProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Utility class to record handshake metrics. This class exists to allow a single logger to configure handshake logging
* for both socket factories and ssl engines.
*/
final class HandshakeInstrumentation {

private static final Logger log = LoggerFactory.getLogger(HandshakeInstrumentation.class);
private static final SafeLogger log = SafeLoggerFactory.get(HandshakeInstrumentation.class);

static void record(TlsMetrics metrics, String contextName, String cipherSuite, String protocol) {
metrics.handshake()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.palantir.tritium.metrics;

import com.palantir.logsafe.logger.SafeLogger;
import com.palantir.logsafe.logger.SafeLoggerFactory;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Objects;
Expand All @@ -27,12 +29,10 @@
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final class InstrumentedSslEngine extends SSLEngine {

private static final Logger log = LoggerFactory.getLogger(InstrumentedSslEngine.class);
private static final SafeLogger log = SafeLoggerFactory.get(InstrumentedSslEngine.class);

// n.b. This value is set using 'beginHandshake' for renegotiation. We instrument both because ciphers may change.
private final AtomicBoolean handshaking = new AtomicBoolean(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import com.palantir.logsafe.Safe;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import com.palantir.logsafe.logger.SafeLogger;
import com.palantir.logsafe.logger.SafeLoggerFactory;
import com.palantir.tritium.metrics.registry.LockFreeExponentiallyDecayingReservoir;
import com.palantir.tritium.metrics.registry.MetricName;
import com.palantir.tritium.metrics.registry.TaggedMetricRegistry;
Expand All @@ -59,13 +61,11 @@
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSocketFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Utilities for working with {@link MetricRegistry} instances. */
public final class MetricRegistries {

private static final Logger log = LoggerFactory.getLogger(MetricRegistries.class);
private static final SafeLogger log = SafeLoggerFactory.get(MetricRegistries.class);

static final String RESERVOIR_TYPE_METRIC_NAME = MetricRegistry.name(MetricRegistries.class, "reservoir.type");

Expand Down
3 changes: 2 additions & 1 deletion tritium-tracing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ dependencies {

implementation 'com.google.code.findbugs:jsr305'
implementation 'com.google.guava:guava'
implementation 'com.palantir.safe-logging:logger'
implementation 'com.palantir.safe-logging:preconditions'
implementation 'com.palantir.safe-logging:safe-logging'
implementation 'com.palantir.tracing:tracing'
implementation 'org.slf4j:slf4j-api'

testImplementation project(':tritium-test')
testImplementation 'com.palantir.tracing:tracing-api'
Expand All @@ -20,4 +20,5 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'org.slf4j:slf4j-api'
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.google.common.base.Suppliers;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalStateException;
import com.palantir.logsafe.logger.SafeLogger;
import com.palantir.logsafe.logger.SafeLoggerFactory;
import com.palantir.tritium.event.AbstractInvocationEventHandler;
import com.palantir.tritium.event.DefaultInvocationContext;
import com.palantir.tritium.event.InstrumentationProperties;
Expand All @@ -35,14 +37,12 @@
import java.util.function.Supplier;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("TryFailRefactoring") // work-around https://github.com/google/error-prone/issues/1447
public final class RemotingCompatibleTracingInvocationEventHandler
extends AbstractInvocationEventHandler<InvocationContext> {

private static final Logger log = LoggerFactory.getLogger(RemotingCompatibleTracingInvocationEventHandler.class);
private static final SafeLogger log = SafeLoggerFactory.get(RemotingCompatibleTracingInvocationEventHandler.class);

private static final AtomicBoolean shouldLogFallbackError = new AtomicBoolean();

Expand Down
9 changes: 6 additions & 3 deletions versions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.3 (1 constraints: cf0c
com.github.ben-manes.caffeine:caffeine:3.0.3 (1 constraints: 0805fd35)
com.google.auto.service:auto-service-annotations:1.0 (1 constraints: a5041a2c)
com.google.code.findbugs:jsr305:3.0.2 (4 constraints: 5c3586ed)
com.google.errorprone:error_prone_annotations:2.8.0 (6 constraints: 2447e889)
com.google.errorprone:error_prone_annotations:2.8.0 (9 constraints: b374a185)
com.google.guava:failureaccess:1.0.1 (1 constraints: 140ae1b4)
com.google.guava:guava:30.1.1-jre (5 constraints: cb427e81)
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918)
com.google.j2objc:j2objc-annotations:1.3 (1 constraints: b809eda0)
com.palantir.goethe:goethe:0.2.0 (1 constraints: 0405f135)
com.palantir.jvm.diagnostics:jvm-diagnostics:0.0.2 (1 constraints: 0405ed35)
com.palantir.safe-logging:logger:1.18.0 (1 constraints: 3c05413b)
com.palantir.safe-logging:logger-slf4j:1.18.0 (1 constraints: 350e9350)
com.palantir.safe-logging:logger-spi:1.18.0 (2 constraints: 791e0cb1)
com.palantir.safe-logging:preconditions:1.18.0 (2 constraints: de111b06)
com.palantir.safe-logging:safe-logging:1.18.0 (3 constraints: 1323ae54)
com.palantir.safe-logging:safe-logging:1.18.0 (5 constraints: f4408b9d)
com.palantir.tracing:tracing:4.23.0 (1 constraints: 3b05483b)
com.palantir.tracing:tracing-api:4.23.0 (2 constraints: 0b120b18)
com.squareup:javapoet:1.13.0 (2 constraints: 2b113eee)
Expand All @@ -25,7 +28,7 @@ org.checkerframework:checker-qual:3.15.0 (4 constraints: b42950a2)
org.hdrhistogram:HdrHistogram:2.1.12 (1 constraints: 3805313b)
org.immutables:value:2.8.8 (1 constraints: 14051536)
org.mpierce.metrics.reservoir:hdrhistogram-metrics-reservoir:1.1.3 (1 constraints: 0705f635)
org.slf4j:slf4j-api:1.7.32 (6 constraints: 734deb8b)
org.slf4j:slf4j-api:1.7.32 (7 constraints: b95d3bd1)

[Test dependencies]
com.google.auto:auto-common:1.1.2 (1 constraints: e711f5e8)
Expand Down

0 comments on commit df57547

Please sign in to comment.