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 @@ -92,8 +92,8 @@ private void ensureFileExistsLocally(S3Uri s3Uri, Path localPath) {

public static S3Repo create(Path s3LocalDir, S3Uri s3Uri, String s3Region) {
S3AsyncClient s3Client = S3AsyncClient.crtBuilder()
.credentialsProvider(DefaultCredentialsProvider.create())
.region(Region.of(s3Region))
.credentialsProvider(DefaultCredentialsProvider.create())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attempt to fix lingering sonarqube issue on this builder by changing the order here to match sonarqube's documentation

.retryConfiguration(r -> r.numRetries(3))
.targetThroughputInGbps(S3_TARGET_THROUGHPUT_GIBPS)
.maxNativeMemoryLimitInBytes(S3_MAX_MEMORY_BYTES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;

public class ObjectNodeUtils {
private ObjectNodeUtils() {}

public static void removeFieldsByPath(ObjectNode node, String path) {
var pathParts = path.split("\\.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def setup_parser(parser):
message = f"The tool '{tool_name}' does not have a 'define_arguments' function. \
Please add one to specify its arguments."
logger.error(message)
raise Exception(message)
raise ValueError(message)
tool_parser.set_defaults(func=tool_module.main) # Set the main function as the handler
except Exception as e:
logger.error(f"An error occurred while importing the tool '{tool_name}': {e}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.opensearch.migrations.replay;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

import org.opensearch.migrations.replay.datahandlers.IPacketFinalizingConsumer;
Expand All @@ -15,11 +17,12 @@

@Slf4j
public class PacketToTransformingHttpHandlerFactory
implements
PacketConsumerFactory<TransformedOutputAndResult<ByteBufList>> {
implements PacketConsumerFactory<TransformedOutputAndResult<ByteBufList>>, AutoCloseable {

// Using ThreadLocal to ensure thread safety with the json transformers which will be reused
private final ThreadLocal<IJsonTransformer> localJsonTransformer;
private final Set<AutoCloseable> closeableResources = ConcurrentHashMap.newKeySet();

// The authTransformerFactory is ThreadSafe and getAuthTransformer will be called for every request
private final IAuthTransformerFactory authTransformerFactory;

Expand All @@ -43,4 +46,12 @@ public IPacketFinalizingConsumer<TransformedOutputAndResult<ByteBufList>> create
httpTransactionContext
);
}

@Override
public void close() throws Exception {
for (AutoCloseable resource : closeableResources) {
resource.close();
}
localJsonTransformer.remove();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,14 @@ private static Map<String, Object> convertResponse(
}

private static void encodeBinaryPayloadIfExists(HttpJsonMessageWithFaultingPayload message) {
if (message.payload() != null) {
if (message.payload().containsKey(JsonKeysForHttpMessage.INLINED_BINARY_BODY_DOCUMENT_KEY)) {
var byteBufBinaryBody = (ByteBuf) message.payload().get(JsonKeysForHttpMessage.INLINED_BINARY_BODY_DOCUMENT_KEY);
assert !message.payload().containsKey(JsonKeysForHttpMessage.INLINED_BASE64_BODY_DOCUMENT_KEY) :
"Expected " + JsonKeysForHttpMessage.INLINED_BASE64_BODY_DOCUMENT_KEY + " to not exist.";
message.payload().put(JsonKeysForHttpMessage.INLINED_BASE64_BODY_DOCUMENT_KEY, byteBufToBase64String(byteBufBinaryBody));
message.payload().remove(JsonKeysForHttpMessage.INLINED_BINARY_BODY_DOCUMENT_KEY);
byteBufBinaryBody.release();
}
if (message.payload() != null &&
message.payload().containsKey(JsonKeysForHttpMessage.INLINED_BINARY_BODY_DOCUMENT_KEY)) {
var byteBufBinaryBody = (ByteBuf) message.payload().get(JsonKeysForHttpMessage.INLINED_BINARY_BODY_DOCUMENT_KEY);
assert !message.payload().containsKey(JsonKeysForHttpMessage.INLINED_BASE64_BODY_DOCUMENT_KEY) :
"Expected " + JsonKeysForHttpMessage.INLINED_BASE64_BODY_DOCUMENT_KEY + " to not exist.";
message.payload().put(JsonKeysForHttpMessage.INLINED_BASE64_BODY_DOCUMENT_KEY, byteBufToBase64String(byteBufBinaryBody));
message.payload().remove(JsonKeysForHttpMessage.INLINED_BINARY_BODY_DOCUMENT_KEY);
byteBufBinaryBody.release();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public void setPath(String value) {
this.put(JsonKeysForHttpMessage.URI_KEY, value);
}

@Override
public String protocol() {
return (String) this.get(JsonKeysForHttpMessage.PROTOCOL_KEY);
}

@Override
public void setProtocol(String value) {
this.put(JsonKeysForHttpMessage.PROTOCOL_KEY, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
private boolean hasRequestContentTypeMatching(HttpJsonMessageWithFaultingPayload message,
Predicate<String> contentTypeFilter) {
// ContentType not text if specified and has a value with / and that value does not start with text/
return Optional.ofNullable(capturedHttpJsonMessage.headers().insensitiveGet(HttpHeaderNames.CONTENT_TYPE.toString()))
return Optional.ofNullable(message.headers().insensitiveGet(HttpHeaderNames.CONTENT_TYPE.toString()))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a behavior change since we were only passing in capturedHttpJsonMessage to this method, but it should use the parameter message nonetheless

.map(s -> s.stream()
.filter(v -> v.contains("/"))
.filter(contentTypeFilter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ private static int contextDepth(IScopedInstrumentationAttributes activeScope, in
}

private String activityToString(OrderedWorkerTracker.TimeKeyAndFuture<Void> tkaf) {
var timeStr = "age=" + getAge(tkaf.nanoTimeKey);
return INDENT + timeStr + " " + formatWorkItem.apply(tkaf.future);
return INDENT + "age=" + getAge(tkaf.nanoTimeKey) + " " + formatWorkItem.apply(tkaf.future);
}

private String activityToString(IScopedInstrumentationAttributes context, int depthToInclude) {
Expand Down
Loading