-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Re-enable some performance updates to ES|QL spec tests after resilience improvement to EsqlSpecTestCase #136781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7b6749d
f39fb57
c13c071
15c6458
56fd509
4a91ed7
f9453f1
955fbcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| import org.apache.http.client.CredentialsProvider; | ||
| import org.apache.http.impl.client.BasicCredentialsProvider; | ||
| import org.apache.logging.log4j.core.config.plugins.util.PluginManager; | ||
| import org.apache.lucene.util.IOConsumer; | ||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.Response; | ||
| import org.elasticsearch.client.ResponseException; | ||
|
|
@@ -30,6 +31,7 @@ | |
| import org.elasticsearch.inference.TaskType; | ||
| import org.elasticsearch.logging.LogManager; | ||
| import org.elasticsearch.logging.Logger; | ||
| import org.elasticsearch.test.ESTestCase; | ||
| import org.elasticsearch.test.rest.ESRestTestCase; | ||
| import org.elasticsearch.xcontent.XContentType; | ||
|
|
||
|
|
@@ -43,6 +45,7 @@ | |
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.Semaphore; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
|
|
@@ -55,6 +58,7 @@ | |
| import static org.elasticsearch.xpack.esql.EsqlTestUtils.reader; | ||
|
|
||
| public class CsvTestsDataLoader { | ||
| private static final int PARALLEL_THREADS = 10; | ||
| private static final int BULK_DATA_SIZE = 100_000; | ||
| private static final TestDataset EMPLOYEES = new TestDataset("employees", "mapping-default.json", "employees.csv").noSubfields(); | ||
| private static final TestDataset EMPLOYEES_INCOMPATIBLE = new TestDataset( | ||
|
|
@@ -429,18 +433,42 @@ private static void loadDataSetIntoEs( | |
| IndexCreator indexCreator | ||
| ) throws IOException { | ||
| Logger logger = LogManager.getLogger(CsvTestsDataLoader.class); | ||
| List<TestDataset> datasets = availableDatasetsForEs( | ||
| supportsIndexModeLookup, | ||
| supportsSourceFieldMapping, | ||
| inferenceEnabled, | ||
| timeSeriesOnly | ||
| ).stream().toList(); | ||
|
|
||
| logger.info("Creating test indices"); | ||
| executeInParallel(datasets, dataset -> createIndex(client, dataset, indexCreator), "Failed to create indices in parallel"); | ||
|
|
||
| Set<String> loadedDatasets = new HashSet<>(); | ||
| logger.info("Loading test datasets"); | ||
| for (var dataset : availableDatasetsForEs(supportsIndexModeLookup, supportsSourceFieldMapping, inferenceEnabled, timeSeriesOnly)) { | ||
| load(client, dataset, logger, indexCreator); | ||
| loadedDatasets.add(dataset.indexName); | ||
| } | ||
| forceMerge(client, loadedDatasets, logger); | ||
| executeInParallel(datasets, dataset -> loadData(client, dataset, logger), "Failed to load data in parallel"); | ||
|
|
||
| forceMerge(client, datasets.stream().map(d -> d.indexName).collect(Collectors.toSet()), logger); | ||
|
|
||
| logger.info("Loading enrich policies"); | ||
| for (var policy : ENRICH_POLICIES) { | ||
| loadEnrichPolicy(client, policy.policyName, policy.policyFileName, logger); | ||
| } | ||
| executeInParallel( | ||
| ENRICH_POLICIES, | ||
| policy -> loadEnrichPolicy(client, policy.policyName, policy.policyFileName, logger), | ||
| "Failed to load enrich policies in parallel" | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| private static <T> void executeInParallel(List<T> items, IOConsumer<T> consumer, String errorMessage) { | ||
| Semaphore semaphore = new Semaphore(PARALLEL_THREADS); | ||
| ESTestCase.runInParallel(items.size(), i -> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| try { | ||
| semaphore.acquire(); | ||
| consumer.accept(items.get(i)); | ||
| } catch (IOException | InterruptedException e) { | ||
| throw new RuntimeException(errorMessage, e); | ||
| } finally { | ||
| semaphore.release(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| public static void createInferenceEndpoints(RestClient client) throws IOException { | ||
|
|
@@ -598,12 +626,14 @@ private static URL getResource(String name) { | |
| return result; | ||
| } | ||
|
|
||
| private static void load(RestClient client, TestDataset dataset, Logger logger, IndexCreator indexCreator) throws IOException { | ||
| logger.info("Loading dataset [{}] into ES index [{}]", dataset.dataFileName, dataset.indexName); | ||
| private static void createIndex(RestClient client, TestDataset dataset, IndexCreator indexCreator) throws IOException { | ||
| URL mapping = getResource("/" + dataset.mappingFileName); | ||
| Settings indexSettings = dataset.readSettingsFile(); | ||
| indexCreator.createIndex(client, dataset.indexName, readMappingFile(mapping, dataset.typeMapping), indexSettings); | ||
| } | ||
|
|
||
| private static void loadData(RestClient client, TestDataset dataset, Logger logger) throws IOException { | ||
| logger.info("Loading dataset [{}] into ES index [{}]", dataset.dataFileName, dataset.indexName); | ||
| // Some examples only test that the query and mappings are valid, and don't need example data. Use .noData() for those | ||
| if (dataset.dataFileName != null) { | ||
| URL data = getResource("/data/" + dataset.dataFileName); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: you could use
PlainActionFutureinstead of anonymous listeners implementations here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this code comes from a revert of a revert of an approved PR, I do not want to fiddle with it.