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 @@ -60,6 +60,7 @@ public abstract class AbstractChallengeRestTest extends ESRestTestCase {
.setting("xpack.security.autoconfiguration.enabled", "false")
.setting("xpack.license.self_generated.type", "trial")
.setting("cluster.logsdb.enabled", "true")
.setting("xpack.ml.enabled", "false")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this will really affect test coverage. This isn't like disabling security.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right...I guess it is still useful anyway as it is not really needed and allows to reproduce the test locally. When I tried to run the test locally it was failing with:

[2025-12-18T07:11:59,849][ERROR][o.e.b.Elasticsearch      ] [test-cluster-0] fatal exception while booting Elasticsearch org.elasticsearch.ElasticsearchException: Failure running machine learning native code. This could be due to running on an unsupported OS or distribution, missing OS libraries, or a problem with the temp directory. To bypass this problem by running Elasticsearch without machine learning functionality set [xpack.ml.enabled: false].

.build();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.IntFunction;

/**
* Challenge test that uses bulk indexing for both baseline and contender sides.
Expand All @@ -23,6 +25,8 @@
*/
public class BulkChallengeRestIT extends StandardVersusLogsIndexModeChallengeRestIT {

private static final int BULK_BATCH_SIZE = 20;

public BulkChallengeRestIT() {}

protected BulkChallengeRestIT(DataGenerationHelper dataGenerationHelper) {
Expand All @@ -38,40 +42,62 @@ public void indexDocuments(
indexBaselineDocuments(baselineSupplier, contenderResponseEntity);
}

private Map<String, Object> indexContenderDocuments(final CheckedSupplier<List<XContentBuilder>, IOException> documentsSupplier)
private List<Map<String, Object>> indexContenderDocuments(final CheckedSupplier<List<XContentBuilder>, IOException> documentsSupplier)
throws IOException {
final StringBuilder sb = new StringBuilder();
int id = 0;
for (var document : documentsSupplier.get()) {
if (autoGenerateId()) {
sb.append("{ \"create\": { } }\n");
} else {
sb.append(Strings.format("{ \"create\": { \"_id\" : \"%d\" } }\n", id));
}
sb.append(Strings.toString(document)).append("\n");
id++;
}
return performBulkRequest(sb.toString(), false);
final IntFunction<String> bulkActionGenerator = id -> autoGenerateId()
? "{ \"create\": { } }\n"
: Strings.format("{ \"create\": { \"_id\" : \"%d\" } }\n", id);

return indexDocumentsInBatches(documentsSupplier.get(), bulkActionGenerator, false);
}

@SuppressWarnings("unchecked")
private void indexBaselineDocuments(
final CheckedSupplier<List<XContentBuilder>, IOException> documentsSupplier,
final Map<String, Object> contenderResponseEntity
final List<Map<String, Object>> contenderItems
) throws IOException {
final StringBuilder sb = new StringBuilder();
int id = 0;
final List<Map<String, Object>> items = (List<Map<String, Object>>) contenderResponseEntity.get("items");
for (var document : documentsSupplier.get()) {
final IntFunction<String> bulkActionGenerator = id -> {
if (autoGenerateId()) {
var contenderId = ((Map<String, Object>) items.get(id).get("create")).get("_id");
sb.append(Strings.format("{ \"create\": { \"_id\" : \"%s\" } }\n", contenderId));
final var contenderId = ((Map<String, Object>) contenderItems.get(id).get("create")).get("_id");
return Strings.format("{ \"create\": { \"_id\" : \"%s\" } }\n", contenderId);
} else {
sb.append(Strings.format("{ \"create\": { \"_id\" : \"%d\" } }\n", id));
return Strings.format("{ \"create\": { \"_id\" : \"%d\" } }\n", id);
}
};

indexDocumentsInBatches(documentsSupplier.get(), bulkActionGenerator, true);
}

@SuppressWarnings("unchecked")
private List<Map<String, Object>> indexDocumentsInBatches(
final List<XContentBuilder> documents,
final IntFunction<String> bulkActionGenerator,
final boolean isBaseline
) throws IOException {
final List<Map<String, Object>> allItems = new ArrayList<>();
final StringBuilder sb = new StringBuilder();
int id = 0;
int batchCount = 0;

for (final var document : documents) {
sb.append(bulkActionGenerator.apply(id));
sb.append(Strings.toString(document)).append("\n");
id++;
batchCount++;

if (batchCount >= BULK_BATCH_SIZE) {
final Map<String, Object> response = performBulkRequest(sb.toString(), isBaseline);
allItems.addAll((List<Map<String, Object>>) response.get("items"));
sb.setLength(0);
batchCount = 0;
}
}
performBulkRequest(sb.toString(), true);

if (batchCount > 0) {
final Map<String, Object> response = performBulkRequest(sb.toString(), isBaseline);
allItems.addAll((List<Map<String, Object>>) response.get("items"));
}

return allItems;
}
}