Skip to content

Commit

Permalink
Add a logsdb test that uses ignored dynamic fields (#113639)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkts committed Sep 27, 2024
1 parent e237124 commit 3a51343
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,28 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

class DataGenerationHelper {
public class DataGenerationHelper {
private final ObjectMapper.Subobjects subobjects;
private final boolean keepArraySource;

private final DataGenerator dataGenerator;

DataGenerationHelper() {
public DataGenerationHelper() {
this(b -> {});
}

public DataGenerationHelper(Consumer<DataGeneratorSpecification.Builder> builderConfigurator) {
this.subobjects = ESTestCase.randomFrom(ObjectMapper.Subobjects.values());
this.keepArraySource = ESTestCase.randomBoolean();

var specificationBuilder = DataGeneratorSpecification.builder().withFullyDynamicMapping(ESTestCase.randomBoolean());
if (subobjects != ObjectMapper.Subobjects.ENABLED) {
specificationBuilder = specificationBuilder.withNestedFieldsLimit(0);
}
this.dataGenerator = new DataGenerator(specificationBuilder.withDataSourceHandlers(List.of(new DataSourceHandler() {

specificationBuilder.withDataSourceHandlers(List.of(new DataSourceHandler() {
@Override
public DataSourceResponse.ObjectMappingParametersGenerator handle(DataSourceRequest.ObjectMappingParametersGenerator request) {
if (subobjects == ObjectMapper.Subobjects.ENABLED) {
Expand Down Expand Up @@ -108,8 +114,12 @@ public CheckedConsumer<XContentBuilder, IOException> fieldValueGenerator() {
}
})
)
)
.build());
);

// Customize builder if necessary
builderConfigurator.accept(specificationBuilder);

this.dataGenerator = new DataGenerator(specificationBuilder.build());
}

DataGenerator getDataGenerator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ public class StandardVersusLogsIndexModeRandomDataChallengeRestIT extends Standa
protected final DataGenerationHelper dataGenerationHelper;

public StandardVersusLogsIndexModeRandomDataChallengeRestIT() {
this(new DataGenerationHelper());
}

protected StandardVersusLogsIndexModeRandomDataChallengeRestIT(DataGenerationHelper dataGenerationHelper) {
super();
dataGenerationHelper = new DataGenerationHelper();
this.dataGenerationHelper = dataGenerationHelper;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.datastreams.logsdb.qa;

import org.elasticsearch.common.settings.Settings;

public class StandardVersusLogsIndexModeRandomDataDynamicMappingChallengeRestIT extends
StandardVersusLogsIndexModeRandomDataChallengeRestIT {
public StandardVersusLogsIndexModeRandomDataDynamicMappingChallengeRestIT() {
super(new DataGenerationHelper(builder -> builder.withFullyDynamicMapping(true)));
}

@Override
public void contenderSettings(Settings.Builder builder) {
super.contenderSettings(builder);
// ignore_dynamic_beyond_limit is set in the template so it's always true
builder.put("index.mapping.total_fields.limit", randomIntBetween(1, 5000));
}
}

0 comments on commit 3a51343

Please sign in to comment.