Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@
import io.netty.util.ResourceLeakDetector;
import io.netty.util.ResourceLeakDetector.Level;
import java.util.function.Consumer;
import lombok.CustomLog;
import org.apache.bookkeeper.common.allocator.ByteBufAllocatorWithOomHandler;
import org.apache.bookkeeper.common.allocator.LeakDetectionPolicy;
import org.apache.bookkeeper.common.allocator.OutOfMemoryPolicy;
import org.apache.bookkeeper.common.allocator.PoolingPolicy;
import org.apache.bookkeeper.common.util.ShutdownUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Implementation of {@link ByteBufAllocator}.
*/
@CustomLog
public class ByteBufAllocatorImpl extends AbstractByteBufAllocator implements ByteBufAllocatorWithOomHandler {

private static final Logger log = LoggerFactory.getLogger(ByteBufAllocatorImpl.class);

// Same as AbstractByteBufAllocator, but copied here since it's not visible
private static final int DEFAULT_INITIAL_CAPACITY = 256;
private static final int DEFAULT_MAX_CAPACITY = Integer.MAX_VALUE;
Expand Down Expand Up @@ -69,7 +67,7 @@ public class ByteBufAllocatorImpl extends AbstractByteBufAllocator implements By
this.exitOnOutOfMemory = exitOnOutOfMemory;
if (outOfMemoryListener == null) {
this.outOfMemoryListener = (v) -> {
log.error("Unable to allocate memory", v);
log.error().exception(v).log("Unable to allocate memory");
};
} else {
this.outOfMemoryListener = outOfMemoryListener;
Expand Down Expand Up @@ -105,9 +103,7 @@ public class ByteBufAllocatorImpl extends AbstractByteBufAllocator implements By
// allocators
switch (leakDetectionPolicy) {
case Disabled:
if (log.isDebugEnabled()) {
log.debug("Disable Netty allocator leak detector");
}
log.debug("Disable Netty allocator leak detector");
ResourceLeakDetector.setLevel(Level.DISABLED);
break;

Expand Down Expand Up @@ -201,10 +197,10 @@ private void consumeOOMError(OutOfMemoryError outOfMemoryError) {
try {
outOfMemoryListener.accept(outOfMemoryError);
} catch (Throwable e) {
log.warn("Consume outOfMemory error failed.", e);
log.warn().exception(e).log("Consume outOfMemory error failed");
}
if (exitOnOutOfMemory) {
log.info("Exiting JVM process for OOM error: {}", outOfMemoryError.getMessage(), outOfMemoryError);
log.info().exception(outOfMemoryError).log("Exiting JVM process for OOM error");
ShutdownUtil.triggerImmediateForcefulShutdown();
}
}
Expand Down
2 changes: 2 additions & 0 deletions bookkeeper-dist/src/main/resources/LICENSE-all.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Apache Software License, Version 2.
- lib/commons-codec-commons-codec-1.18.0.jar [6]
- lib/commons-io-commons-io-2.19.0.jar [8]
- lib/commons-logging-commons-logging-1.3.5.jar [10]
- lib/io.github.merlimat.slog-slog-0.9.8.jar [64]
- lib/io.netty-netty-buffer-4.2.12.Final.jar [11]
- lib/io.netty-netty-codec-base-4.2.12.Final.jar [11]
- lib/io.netty-netty-codec-compression-4.2.12.Final.jar [11]
Expand Down Expand Up @@ -422,6 +423,7 @@ Apache Software License, Version 2.
[61] Source available at https://github.com/apache/commons-text/tree/rel/commons-text-1.13.1
[62] Source available at https://github.com/apache/commons-beanutils/tree/rel/commons-beanutils-1.11.0
[63] Source available at https://github.com/googleapis/sdk-platform-java/tree/v2.53.0/api-common-java
[64] Source available at https://github.com/merlimat/slog/tree/v0.9.8
------------------------------------------------------------------------------------
lib/io.netty-netty-codec-base-4.2.12.Final.jar bundles some 3rd party dependencies

Expand Down
2 changes: 2 additions & 0 deletions bookkeeper-dist/src/main/resources/LICENSE-bkctl.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Apache Software License, Version 2.
- lib/commons-codec-commons-codec-1.18.0.jar [6]
- lib/commons-io-commons-io-2.19.0.jar [8]
- lib/commons-logging-commons-logging-1.3.5.jar [10]
- lib/io.github.merlimat.slog-slog-0.9.8.jar [59]
- lib/io.netty-netty-buffer-4.2.12.Final.jar [11]
- lib/io.netty-netty-codec-base-4.2.12.Final.jar [11]
- lib/io.netty-netty-common-4.2.12.Final.jar [11]
Expand Down Expand Up @@ -355,6 +356,7 @@ Apache Software License, Version 2.
[56] Source available at https://github.com/apache/commons-text/tree/rel/commons-text-1.13.1
[57] Source available at https://github.com/apache/commons-beanutils/tree/rel/commons-beanutils-1.11.0
[58] Source available at https://github.com/googleapis/sdk-platform-java/tree/v2.53.0/api-common-java
[59] Source available at https://github.com/merlimat/slog/tree/v0.9.8
------------------------------------------------------------------------------------
lib/io.netty-netty-codec-base-4.2.12.Final.jar bundles some 3rd party dependencies

Expand Down
2 changes: 2 additions & 0 deletions bookkeeper-dist/src/main/resources/LICENSE-server.bin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Apache Software License, Version 2.
- lib/commons-codec-commons-codec-1.18.0.jar [6]
- lib/commons-io-commons-io-2.19.0.jar [8]
- lib/commons-logging-commons-logging-1.3.5.jar [10]
- lib/io.github.merlimat.slog-slog-0.9.8.jar [63]
- lib/io.netty-netty-buffer-4.2.12.Final.jar [11]
- lib/io.netty-netty-codec-base-4.2.12.Final.jar [11]
- lib/io.netty-netty-codec-compression-4.2.12.Final.jar [11]
Expand Down Expand Up @@ -417,6 +418,7 @@ Apache Software License, Version 2.
[60] Source available at https://github.com/apache/commons-text/tree/rel/commons-text-1.13.1
[61] Source available at https://github.com/apache/commons-beanutils/tree/rel/commons-beanutils-1.11.0
[62] Source available at https://github.com/googleapis/sdk-platform-java/tree/v2.53.0/api-common-java
[63] Source available at https://github.com/merlimat/slog/tree/v0.9.8
------------------------------------------------------------------------------------
lib/io.netty-netty-codec-base-4.2.12.Final.jar bundles some 3rd party dependencies

Expand Down
24 changes: 24 additions & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

# this is the top level Lombok configuration file
# see https://projectlombok.org/features/configuration for reference

config.stopBubbling = true
lombok.log.custom.declaration = io.github.merlimat.slog.Logger io.github.merlimat.slog.Logger.get(TYPE)
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
<rocksdb.version>9.9.3</rocksdb.version>
<shrinkwrap.version>3.3.0</shrinkwrap.version>
<slf4j.version>2.0.12</slf4j.version>
<slog.version>0.9.8</slog.version>
<snakeyaml.version>2.0</snakeyaml.version>
<spotbugs-annotations.version>4.6.0</spotbugs-annotations.version>
<spotless.version>2.43.0</spotless.version>
Expand Down Expand Up @@ -273,6 +274,11 @@
</dependency>

<!-- logging dependencies -->
<dependency>
<groupId>io.github.merlimat.slog</groupId>
<artifactId>slog</artifactId>
<version>${slog.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-bom</artifactId>
Expand Down Expand Up @@ -882,6 +888,10 @@
</dependency>

<!-- compilation dependencies (available at all classpaths) -->
<dependency>
<groupId>io.github.merlimat.slog</groupId>
<artifactId>slog</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
*/
package org.apache.bookkeeper.stats;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.CustomLog;

/**
* This class is used to raise alert when we detect an event that should never happen in production.
*/
@CustomLog
public class AlertStatsLogger {
private static final Logger logger = LoggerFactory.getLogger(AlertStatsLogger.class);

public final String alertStatName;

Expand Down Expand Up @@ -73,7 +72,6 @@ public void raise(String msg, Object... args) {
if (null != scopedCounter) {
scopedCounter.inc();
}
logger.error(format(msg), args);
logger.error("fake exception to generate stack trace", new Exception());
log.error().exception(new Exception()).logf(format(msg), args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import lombok.CustomLog;
import org.apache.commons.configuration2.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An umbrella class for loading stats provider.
*/
@CustomLog
public class Stats {
static final Logger LOG = LoggerFactory.getLogger(Stats.class);
public static final String STATS_PROVIDER_CLASS = "statsProviderClass";

static StatsProvider prov = new NullStatsProvider();
Expand All @@ -50,16 +49,27 @@ public static void loadStatsProvider(String className) {
(Constructor<? extends StatsProvider>) cls.getDeclaredConstructor();
prov = cons.newInstance();
} catch (ClassNotFoundException cnfe) {
LOG.error("Couldn't find configured class(" + className + ")", cnfe);
log.error()
.exception(cnfe)
.attr("className", className)
.log("Couldn't find configured class");
} catch (NoSuchMethodException nsme) {
LOG.error("Couldn't find default constructor for class (" + className + ")", nsme);
log.error()
.exception(nsme)
.attr("className", className)
.log("Couldn't find default constructor for class");
} catch (InstantiationException ie) {
LOG.error("Couldn't construct class (" + className + ")", ie);
log.error()
.exception(ie)
.attr("className", className)
.log("Couldn't construct class");
} catch (IllegalAccessException iae) {
LOG.error("Couldn't construct class (" + className + "),"
+ " Is the constructor private?", iae);
log.error()
.exception(iae)
.attr("className", className)
.log("Couldn't construct class, is the constructor private?");
} catch (InvocationTargetException ite) {
LOG.error("Constructor threw an exception. It should not have.", ite);
log.error().exception(ite).log("Constructor threw an exception. It should not have.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.CustomLog;

/**
* For mapping thread ids to thread pools and threads within those pools
* or just for lone named threads. Thread scoped metrics add labels to
* metrics by retrieving the ThreadPoolThread object from this registry.
* For flexibility, this registry is not based on TLS.
*/
@CustomLog
public class ThreadRegistry {
private static Logger logger = LoggerFactory.getLogger(ThreadRegistry.class);
private static ConcurrentMap<Long, ThreadPoolThread> threadPoolMap = new ConcurrentHashMap<>();
private static ConcurrentMap<String, Integer> threadPoolThreadMap = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -59,7 +58,10 @@ public static void register(String threadPool, boolean force) {
public static void forceClearRegistrationForTests(long threadId) {
threadPoolMap.compute(threadId, (id, value) -> {
if (value != null) {
logger.info("Forcibly clearing registry entry {} for thread id {}", value, id);
log.info()
.attr("entry", value)
.attr("threadId", id)
.log("Forcibly clearing registry entry");
}
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import lombok.CustomLog;
import org.apache.bookkeeper.stats.StatsLogger;
import org.apache.bookkeeper.stats.StatsProvider;
import org.apache.bookkeeper.stats.ThreadRegistry;
import org.apache.commons.configuration2.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A {@link StatsProvider} implemented based on <i>Codahale</i> metrics library.
*/
@SuppressWarnings("deprecation")
@CustomLog
public class CodahaleMetricsProvider implements StatsProvider {

static final Logger LOG = LoggerFactory.getLogger(CodahaleMetricsProvider.class);

MetricRegistry metrics = null;
List<ScheduledReporter> reporters = new ArrayList<ScheduledReporter>();
JmxReporter jmx = null;
Expand Down Expand Up @@ -76,7 +75,7 @@ public void start(Configuration conf) {
String jmxDomain = conf.getString("codahaleStatsJmxEndpoint");

if (!Strings.isNullOrEmpty(graphiteHost)) {
LOG.info("Configuring stats with graphite");
log.info("Configuring stats with graphite");
HostAndPort addr = HostAndPort.fromString(graphiteHost);
final Graphite graphite = new Graphite(
new InetSocketAddress(addr.getHost(), addr.getPort()));
Expand All @@ -97,22 +96,22 @@ public void start(Configuration conf) {
} else {
outdir = new File(csvDir);
}
LOG.info("Configuring stats with csv output to directory [{}]", outdir.getAbsolutePath());
log.info().attr("directory", outdir.getAbsolutePath()).log("Configuring stats with csv output");
reporters.add(CsvReporter.forRegistry(getMetrics())
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build(outdir));
}
if (!Strings.isNullOrEmpty(slf4jCat)) {
LOG.info("Configuring stats with slf4j");
log.info("Configuring stats with slf4j");
reporters.add(Slf4jReporter.forRegistry(getMetrics())
.outputTo(LoggerFactory.getLogger(slf4jCat))
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build());
}
if (!Strings.isNullOrEmpty(jmxDomain)) {
LOG.info("Configuring stats with jmx");
log.info("Configuring stats with jmx");
jmx = JmxReporter.forRegistry(getMetrics())
.inDomain(jmxDomain)
.convertRatesTo(TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;
import lombok.extern.slf4j.Slf4j;
import lombok.CustomLog;
import org.apache.bookkeeper.stats.StatsLogger;
import org.apache.bookkeeper.stats.StatsProvider;
import org.apache.commons.configuration2.Configuration;
// CHECKSTYLE.ON: IllegalImport

@Slf4j
@CustomLog
public class OtelMetricsProvider implements StatsProvider {

private static final String METER_NAME = "org.apache.bookkeeper";
Expand Down Expand Up @@ -136,7 +136,7 @@ public StatsLogger getStatsLogger(String scope) {
field.setAccessible(true);
tmpDirectMemoryUsage = (AtomicLong) field.get(null);
} catch (Throwable t) {
log.warn("Failed to access netty DIRECT_MEMORY_COUNTER field {}", t.getMessage());
log.warn().exceptionMessage(t).log("Failed to access netty DIRECT_MEMORY_COUNTER field");
}
directMemoryUsage = tmpDirectMemoryUsage;
getDirectMemoryUsage = () -> directMemoryUsage != null ? directMemoryUsage.get() : Double.NaN;
Expand Down
Loading
Loading