Skip to content

Commit

Permalink
Merge pull request opensearch-project#986 from AndreKurait/TrafficCap…
Browse files Browse the repository at this point in the history
…tureSonar

SonarQube fixes for Capture Proxy
  • Loading branch information
AndreKurait authored Sep 20, 2024
2 parents df5b2d6 + 127291d commit d6a4e82
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ protected static Settings getSettings(@NonNull String configFile) {
.entrySet().stream()
.filter(kvp -> kvp.getKey().startsWith(HTTPS_CONFIG_PREFIX))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (!httpsSettings.containsKey(SUPPORTED_TLS_PROTOCOLS_LIST_KEY)) {
httpsSettings.put(SUPPORTED_TLS_PROTOCOLS_LIST_KEY, List.of("TLSv1.2", "TLSv1.3"));
}
httpsSettings.putIfAbsent(SUPPORTED_TLS_PROTOCOLS_LIST_KEY, List.of("TLSv1.2", "TLSv1.3"));

return Settings.builder().loadFromMap(httpsSettings)
// Don't bother with configurations the 'transport' (port 9300), which the plugin that we're using
Expand Down Expand Up @@ -299,7 +297,7 @@ static Properties buildKafkaProperties(Parameters params) throws IOException {
return kafkaProps;
}

protected static IConnectionCaptureFactory getConnectionCaptureFactory(
protected static IConnectionCaptureFactory<?> getConnectionCaptureFactory(
Parameters params,
RootCaptureContext rootContext
) throws IOException {
Expand Down Expand Up @@ -433,12 +431,12 @@ public static void main(String[] args) throws InterruptedException, IOException
proxy.waitForClose();
}

static ProxyChannelInitializer buildProxyChannelInitializer(RootCaptureContext rootContext,
static <T> ProxyChannelInitializer<T> buildProxyChannelInitializer(RootCaptureContext rootContext,
BacksideConnectionPool backsideConnectionPool,
Supplier<SSLEngine> sslEngineSupplier,
@NonNull RequestCapturePredicate headerCapturePredicate,
List<String> headerOverridesArgs,
IConnectionCaptureFactory connectionFactory)
IConnectionCaptureFactory<T> connectionFactory)
{
var headers = new ArrayList<>(convertPairListToMap(headerOverridesArgs).entrySet());
Collections.reverse(headers);
Expand All @@ -453,7 +451,7 @@ static ProxyChannelInitializer buildProxyChannelInitializer(RootCaptureContext r
removeStrings.add(kvp.getKey() + ":");
}

return new ProxyChannelInitializer(
return new ProxyChannelInitializer<>(
rootContext,
backsideConnectionPool,
sslEngineSupplier,
Expand All @@ -464,19 +462,16 @@ static ProxyChannelInitializer buildProxyChannelInitializer(RootCaptureContext r
protected void initChannel(@NonNull SocketChannel ch) throws IOException {
super.initChannel(ch);
final var pipeline = ch.pipeline();
{
int i = 0;
for (var kvp : headers) {
pipeline.addAfter(ProxyChannelInitializer.CAPTURE_HANDLER_NAME, "AddHeader-" + kvp.getKey(),
new HeaderAdderHandler(addBufs.get(i++)));
}
int i = 0;
for (var kvp : headers) {
pipeline.addAfter(ProxyChannelInitializer.CAPTURE_HANDLER_NAME, "AddHeader-" + kvp.getKey(),
new HeaderAdderHandler(addBufs.get(i++)));
}
{
int i = 0;
for (var kvp : headers) {
pipeline.addAfter(ProxyChannelInitializer.CAPTURE_HANDLER_NAME, "RemoveHeader-" + kvp.getKey(),
new HeaderRemoverHandler(removeStrings.get(i++)));
}

i = 0;
for (var kvp : headers) {
pipeline.addAfter(ProxyChannelInitializer.CAPTURE_HANDLER_NAME, "RemoveHeader-" + kvp.getKey(),
new HeaderRemoverHandler(removeStrings.get(i++)));
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,15 @@ public F getAvailableOrNewItem() {
throw new PoolClosedException();
}
var startTime = Instant.now();
{
log.trace("getAvailableOrNewItem: readyItems.size()=" + readyItems.size());
var item = readyItems.poll();
log.trace("getAvailableOrNewItem: item=" + item + " remaining readyItems.size()=" + readyItems.size());
if (item != null) {
stats.addHotGet();
beginLoadingNewItemIfNecessary();
stats.addWaitTime(Duration.between(startTime, Instant.now()));
return item.future;
}
log.atTrace().setMessage("getAvailableOrNewItem: readyItems.size()={}").addArgument(readyItems.size()).log();
var item = readyItems.poll();
log.atTrace().setMessage("getAvailableOrNewItem: item={} remaining readyItems.size()={}")
.addArgument(item).addArgument(readyItems.size()).log();
if (item != null) {
stats.addHotGet();
beginLoadingNewItemIfNecessary();
stats.addWaitTime(Duration.between(startTime, Instant.now()));
return item.future;
}

BiFunction<F, String, F> durationTrackingDecoratedItem = (itemsFuture, label) -> (F) itemsFuture.addListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public NettyScanningHttpProxy(int proxyPort) {
this.proxyPort = proxyPort;
}

public void start(ProxyChannelInitializer proxyChannelInitializer, int numThreads)
public void start(ProxyChannelInitializer<?> proxyChannelInitializer, int numThreads)
throws InterruptedException
{
bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("captureProxyPoolBoss"));
Expand Down

0 comments on commit d6a4e82

Please sign in to comment.