Skip to content

Commit

Permalink
feat: drop CarapaceLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
NiccoMlt committed Nov 21, 2024
1 parent 95f20cc commit 7bc06c2
Show file tree
Hide file tree
Showing 20 changed files with 107 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private static void fillCertificateBean(
}
bean.setStatus(certificateStateToString(state));
} catch (GeneralSecurityException | IOException ex) {
LOG.error("Unable to read Keystore for certificate {}. Reason: {}", certificate.getId(), ex);
LOG.error("Unable to read Keystore for certificate {}", certificate.getId(), ex);
}
}

Expand Down
26 changes: 15 additions & 11 deletions carapace-server/src/main/java/org/carapaceproxy/core/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import org.carapaceproxy.server.config.HostPort;
import org.carapaceproxy.server.config.NetworkListenerConfiguration;
import org.carapaceproxy.server.config.SSLCertificateConfiguration;
import org.carapaceproxy.utils.CarapaceLogger;
import org.carapaceproxy.utils.CertificatesUtils;
import org.carapaceproxy.utils.PrometheusUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -203,19 +202,19 @@ void reloadConfiguration(RuntimeServerConfiguration newConfiguration) throws Int
currentConfiguration = newConfiguration;

try {
for (HostPort hostport : listenersToStop) {
for (final HostPort hostport : listenersToStop) {
LOG.info("Stopping {}", hostport);
stopListener(hostport);
}

for (HostPort hostport : listenersToRestart) {
for (final HostPort hostport : listenersToRestart) {
LOG.info("Restart {}", hostport);
stopListener(hostport);
NetworkListenerConfiguration newConfigurationForListener = currentConfiguration.getListener(hostport);
bootListener(newConfigurationForListener);
}

for (HostPort hostport : listenersToStart) {
for (final HostPort hostport : listenersToStart) {
LOG.info("Starting {}", hostport);
NetworkListenerConfiguration newConfigurationForListener = currentConfiguration.getListener(hostport);
bootListener(newConfigurationForListener);
Expand Down Expand Up @@ -294,10 +293,13 @@ protected SslHandler newSslHandler(SslContext context, ByteBufAllocator allocato
})
.httpRequestDecoder(option -> option.maxHeaderSize(currentConfiguration.getMaxHeaderSize()))
.handle((request, response) -> { // Custom request-response handling
if (CarapaceLogger.isLoggingDebugEnabled()) {
CarapaceLogger.debug("Receive request " + request.uri()
+ " From " + request.remoteAddress()
+ " Timestamp " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")));
if (LOG.isDebugEnabled()) {
LOG.debug(
"Receive request {} From {} Timestamp {}",
request.uri(),
request.remoteAddress(),
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS"))
);
}

ListeningChannel channel = listeningChannels.get(hostPort);
Expand All @@ -310,12 +312,14 @@ protected SslHandler newSslHandler(SslContext context, ByteBufAllocator allocato

// response compression
if (currentConfiguration.getResponseCompressionThreshold() >= 0) {
CarapaceLogger.debug("Response compression enabled with min size = {0} bytes for listener {1}",
currentConfiguration.getResponseCompressionThreshold(), hostPort
LOG.debug(
"Response compression enabled with min size = {} bytes for listener {}",
currentConfiguration.getResponseCompressionThreshold(),
hostPort
);
httpServer = httpServer.compress(currentConfiguration.getResponseCompressionThreshold());
} else {
CarapaceLogger.debug("Response compression disabled for listener {0}", hostPort);
LOG.debug("Response compression disabled for listener {}", hostPort);
}

// Initialization of event loop groups, native transport libraries and the native libraries for the security
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import org.carapaceproxy.server.config.NetworkListenerConfiguration;
import org.carapaceproxy.server.mapper.CustomHeader;
import org.carapaceproxy.server.mapper.MapResult;
import org.carapaceproxy.utils.CarapaceLogger;
import org.carapaceproxy.utils.HttpUtils;
import org.carapaceproxy.utils.PrometheusUtils;
import org.reactivestreams.Publisher;
Expand Down Expand Up @@ -367,12 +366,20 @@ public Publisher<Void> forward(ProxyRequest request, boolean cache) {
var connectionToEndpoint = connectionsManager.apply(request);
ConnectionPoolConfiguration connectionConfig = connectionToEndpoint.getKey();
ConnectionProvider connectionProvider = connectionToEndpoint.getValue();
if (CarapaceLogger.isLoggingDebugEnabled()) {
if (LOGGER.isDebugEnabled()) {
Map<String, HttpProxyServer.ConnectionPoolStats> stats = parent.getConnectionPoolsStats().get(key);
if (stats != null) {
CarapaceLogger.debug("Connection {0} stats: {1}", connectionConfig.getId(), stats.get(connectionConfig.getId()));
LOGGER.debug(
"Connection {} stats: {}",
connectionConfig.getId(),
stats.get(connectionConfig.getId())
);
}
CarapaceLogger.debug("Max connections for {0}: {1}", connectionConfig.getId(), connectionProvider.maxConnectionsPerHost());
LOGGER.debug(
"Max connections for {}: {}",
connectionConfig.getId(),
connectionProvider.maxConnectionsPerHost()
);
}

final var protocol = HttpUtils.toHttpProtocol(request.getHttpProtocol(), request.isSecure());
Expand All @@ -399,22 +406,30 @@ public Publisher<Void> forward(ProxyRequest request, boolean cache) {
: NioChannelOption.of(ExtendedSocketOptions.TCP_KEEPCOUNT), connectionConfig.getKeepaliveCount())
.httpResponseDecoder(option -> option.maxHeaderSize(parent.getCurrentConfiguration().getMaxHeaderSize()))
.doOnRequest((req, conn) -> {
if (CarapaceLogger.isLoggingDebugEnabled()) {
CarapaceLogger.debug("Start sending request for "
+ " Using client id " + key.getHostPort() + "_" + connectionConfig.getId()
+ " Uri " + req.resourceUrl()
+ " Timestamp " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS"))
+ " Backend " + endpointHost + ":" + endpointPort);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Start sending request for Using client id {}_{} Uri {} Timestamp {} Backend {}:{}",
key,
connectionConfig.getId(),
req.resourceUrl(),
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")),
endpointHost,
endpointPort
);
}
endpointStats.getTotalRequests().incrementAndGet();
endpointStats.getLastActivity().set(System.currentTimeMillis());
}).doAfterRequest((req, conn) -> {
if (CarapaceLogger.isLoggingDebugEnabled()) {
CarapaceLogger.debug("Finished sending request for "
+ " Using client id " + key.getHostPort() + "_" + connectionConfig.getId()
+ " Uri " + request.getUri()
+ " Timestamp " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS"))
+ " Backend " + endpointHost + ":" + endpointPort);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Finished sending request for Using client id {}_{} Uri {} Timestamp {} Backend {}:{}",
key,
connectionConfig.getId(),
request.getUri(),
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")),
endpointHost,
endpointPort
);
}
}).doAfterResponseSuccess((resp, conn) -> {
PENDING_REQUESTS_GAUGE.dec();
Expand All @@ -441,12 +456,16 @@ public Publisher<Void> forward(ProxyRequest request, boolean cache) {
return out.send(request.getRequestData()); // client request body
})
.response((resp, flux) -> { // endpoint response
if (CarapaceLogger.isLoggingDebugEnabled()) {
CarapaceLogger.debug("Receive response from backend for " + request.getRemoteAddress()
+ " Using client id " + key.getHostPort() + "_" + connectionConfig.getId()
+ " uri" + request.getUri()
+ " timestamp " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS"))
+ " Backend: " + request.getAction().host);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Receive response from backend for {} Using client id {}_{} uri{} timestamp {} Backend: {}",
request.getRemoteAddress(),
key,
connectionConfig.getId(),
request.getUri(),
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")),
request.getAction().host
);
}

request.setResponseStatus(resp.status());
Expand Down Expand Up @@ -480,12 +499,16 @@ public Publisher<Void> forward(ProxyRequest request, boolean cache) {
cacheReceiver.receivedFromRemote(data, parent.getCachePoolAllocator());
}
}).doOnComplete(() -> {
if (CarapaceLogger.isLoggingDebugEnabled()) {
CarapaceLogger.debug("Send all response to client " + request.getRemoteAddress()
+ " Using client id " + key.getHostPort() + "_" + connectionConfig.getId()
+ " for uri " + request.getUri()
+ " timestamp " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS"))
+ " Backend: " + request.getAction().host);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Send all response to client {} Using client id {}_{} for uri {} timestamp {} Backend: {}",
request.getRemoteAddress(),
key,
connectionConfig.getId(),
request.getUri(),
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")),
request.getAction().host
);
}
if (cacheable.get()) {
parent.getCache().cacheContent(cacheReceiver);
Expand Down Expand Up @@ -631,8 +654,12 @@ public void reloadConfiguration(RuntimeServerConfiguration newConfiguration, Col

// max connections per endpoint limit setup
newEndpoints.forEach(be -> {
CarapaceLogger.debug("Setup max connections per endpoint {0}:{1} = {2} for connectionpool {3}",
be.host(), be.port() + "", connectionPool.getMaxConnectionsPerEndpoint(), connectionPool.getId()
LOGGER.debug(
"Setup max connections per endpoint {}:{} = {} for connectionpool {}",
be.host(),
be.port(),
connectionPool.getMaxConnectionsPerEndpoint(),
connectionPool.getId()
);
builder.forRemoteHost(InetSocketAddress.createUnresolved(be.host(), be.port()), spec -> {
spec.maxConnections(connectionPool.getMaxConnectionsPerEndpoint());
Expand Down Expand Up @@ -678,7 +705,7 @@ public Map.Entry<ConnectionPoolConfiguration, ConnectionProvider> apply(ProxyReq
.findFirst()
.orElse(defaultConnectionPool);

CarapaceLogger.debug("Using connection {0} for domain {1}", selectedPool.getKey().getId(), hostName);
LOGGER.debug("Using connection {} for domain {}", selectedPool.getKey().getId(), hostName);

return selectedPool;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPOutputStream;
import org.carapaceproxy.server.cache.ContentsCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stringtemplate.v4.NoIndentWriter;
Expand All @@ -59,7 +58,7 @@
*/
public class RequestsLogger implements Runnable, Closeable {

private static final Logger LOG = LoggerFactory.getLogger(ContentsCache.class);
private static final Logger LOG = LoggerFactory.getLogger(RequestsLogger.class);

private final BlockingQueue<Entry> queue;

Expand Down Expand Up @@ -201,7 +200,7 @@ private void gzipFile(String source_filepath, String destination_zip_filepath, b
LOG.info("{} was compressed successfully", source_filepath);
}
} catch (IOException ex) {
LOG.error("{} Compression failed: {}", source_filepath, ex);
LOG.error("{} Compression failed", source_filepath, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.carapaceproxy.server.config.SSLCertificateConfiguration;
import org.carapaceproxy.server.config.SSLCertificateConfiguration.CertificateMode;
import org.carapaceproxy.server.mapper.StandardEndpointMapper;
import org.carapaceproxy.utils.CarapaceLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -249,10 +248,6 @@ public void configure(ConfigurationStore properties) throws ConfigurationNotVali
ocspStaplingManagerPeriod = properties.getInt("ocspstaplingmanager.period", 0);
LOG.info("ocspstaplingmanager.period={}", ocspStaplingManagerPeriod);

boolean loggingDebugEnabled = properties.getBoolean("logging.debug.enabled", false);
CarapaceLogger.setLoggingDebugEnabled(loggingDebugEnabled);
LOG.info("logging.debug.enabled={}", loggingDebugEnabled);

clientsIdleTimeoutSeconds = properties.getInt("clients.idle.timeout", clientsIdleTimeoutSeconds);
LOG.info("clients.idle.timeout={}", clientsIdleTimeoutSeconds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static ByteBuf loadResource(String resource) {
throw new IOException("cannot load resource " + resource + ", path must start with " + FILE_RESOURCE + " or " + CLASSPATH_RESOURCE);
}
} catch (IOException | NullPointerException err) {
LOG.error("Cannot load resource {}: {}", resource, err);
LOG.error("Cannot load resource {}", resource, err);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.carapaceproxy.core;

import lombok.Getter;
import org.carapaceproxy.utils.CertificatesUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.TrustManagerFactory;
import static org.carapaceproxy.utils.CertificatesUtils.loadKeyStoreFromFile;
import java.io.File;
import java.io.IOException;
import java.security.KeyStore;
Expand All @@ -14,8 +10,11 @@
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;

import static org.carapaceproxy.utils.CertificatesUtils.loadKeyStoreFromFile;
import javax.net.ssl.TrustManagerFactory;
import lombok.Getter;
import org.carapaceproxy.utils.CertificatesUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TrustStoreManager {

Expand All @@ -39,7 +38,7 @@ private void loadTrustStore() {
String trustStoreFile = currentConfiguration.getSslTrustStoreFile();
String trustStorePassword = currentConfiguration.getSslTrustStorePassword();

if(trustStoreFile == null) {
if (trustStoreFile == null) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public static void main(String... args) {
if (!arg.startsWith("-")) {
File configFile = new File(args[i]).getAbsoluteFile();
LOG.error("Reading configuration from {}", configFile);
try (InputStreamReader reader
= new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8)) {
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8)) {
configuration.load(reader);
}
configFileFromParameter = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.prometheus.client.Gauge;
import org.carapaceproxy.core.HttpProxyServer;
import org.carapaceproxy.utils.PrometheusUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.carapaceproxy.core.HttpProxyServer;
import org.carapaceproxy.utils.PrometheusUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CacheByteBufMemoryUsageMetric implements Runnable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import com.github.benmanes.caffeine.cache.RemovalCause;
import com.github.benmanes.caffeine.cache.RemovalListener;
import java.util.concurrent.atomic.AtomicLong;
import org.carapaceproxy.server.cache.ContentsCache.CachedContent;
import org.carapaceproxy.server.cache.ContentsCache.ContentKey;
import org.slf4j.Logger;
import org.carapaceproxy.server.cache.ContentsCache.CachedContent;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ private void startCertificateProcessing(final String domain, final CertificateDa
}
}
} catch (AcmeException | IOException ex) {
LOG.error("Domain checking failed for {}: {}", name, ex);
LOG.error("Domain checking failed for {}", name, ex);
unreachableNames.put(name, ex.getMessage());
}
}
Expand Down
Loading

0 comments on commit 7bc06c2

Please sign in to comment.