diff options
author | Harald Musum <musum@verizonmedia.com> | 2022-07-13 18:10:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-13 18:10:43 +0200 |
commit | e4100cd6a1f17db8911cca4376506590e49bcb9c (patch) | |
tree | 3d7d58c942c62acf98bc0d50167f89e0e399312d | |
parent | 0388ab2a3dc29ad7e9c690c89ed6ded871b6b6ef (diff) | |
parent | c991da942ac3e3dcbc4a170ebca1b32a0a90074a (diff) |
Merge pull request #23497 from vespa-engine/geirst/struct-fields-index-validation-loggingv8.18.12
Change to log warning (for now) as hosted applications are using this…
2 files changed, 38 insertions, 14 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComplexFieldsWithStructFieldIndexesValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComplexFieldsWithStructFieldIndexesValidator.java index a18ce7e245d..fdd71ebccc5 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComplexFieldsWithStructFieldIndexesValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComplexFieldsWithStructFieldIndexesValidator.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.application.validation; +import com.yahoo.config.application.api.DeployLogger; import com.yahoo.config.model.deploy.DeployState; import com.yahoo.schema.Schema; import com.yahoo.schema.document.ImmutableSDField; @@ -9,6 +10,7 @@ import com.yahoo.vespa.model.VespaModel; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.logging.Level; import java.util.stream.Collectors; /** @@ -28,21 +30,22 @@ public class ComplexFieldsWithStructFieldIndexesValidator extends Validator { continue; } for (var spec : cluster.schemas().values()) { - validateComplexFields(cluster.getClusterName(), spec.fullSchema()); + validateComplexFields(cluster.getClusterName(), spec.fullSchema(), deployState.getDeployLogger()); } } } - private static void validateComplexFields(String clusterName, Schema schema) { + private static void validateComplexFields(String clusterName, Schema schema, DeployLogger logger) { String unsupportedFields = schema.allFields() .filter(field -> hasStructFieldsWithIndex(field)) .map(ComplexFieldsWithStructFieldIndexesValidator::toString) .collect(Collectors.joining(", ")); if (!unsupportedFields.isEmpty()) { - throw new IllegalArgumentException( - String.format("For cluster '%s', schema '%s': The following complex fields have struct fields with 'indexing: index' which is not supported: %s. " + - "Change to 'indexing: attribute' instead", + // TODO (Vespa 9 or before): Change back to an exception when no applications are using it wrong. + logger.logApplicationPackage(Level.WARNING, + String.format("For cluster '%s', schema '%s': The following complex fields have struct fields with 'indexing: index' which is not supported and has no effect: %s. " + + "Remove setting or change to 'indexing: attribute' if needed for matching.", clusterName, schema.getName(), unsupportedFields)); } } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexFieldsValidatorTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexFieldsValidatorTestCase.java index 11e4ae855a5..a25b2fdda32 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexFieldsValidatorTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexFieldsValidatorTestCase.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.model.application.validation; import com.yahoo.config.application.api.ApplicationPackage; +import com.yahoo.config.application.api.DeployLogger; import com.yahoo.config.model.NullConfigModelRegistry; import com.yahoo.config.model.api.ValidationParameters; import com.yahoo.config.model.api.ValidationParameters.CheckRouting; @@ -16,8 +17,10 @@ import org.xml.sax.SAXException; import java.io.IOException; import java.util.List; +import java.util.logging.Level; import static com.yahoo.config.model.test.TestUtil.joinLines; +import static org.assertj.core.api.Assertions.assertThat; /** * @author geirst @@ -77,12 +80,17 @@ public class ComplexFieldsValidatorTestCase { "Only supported for the following complex field types: array or map of struct with primitive types, map of primitive types"; } + private class MyLogger implements DeployLogger { + public StringBuilder message = new StringBuilder(); + @Override + public void log(Level level, String message) { + this.message.append(message); + } + } + @Test - public void throws_when_complex_fields_have_struct_fields_with_index() throws IOException, SAXException { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For cluster 'mycluster', schema 'test': " + - "The following complex fields have struct fields with 'indexing: index' which is not supported: " + - "topics (topics.id, topics.label). Change to 'indexing: attribute' instead"); + public void logs_warning_when_complex_fields_have_struct_fields_with_index() throws IOException, SAXException { + var logger = new MyLogger(); createModelAndValidate(joinLines( "schema test {", "document test {", @@ -98,7 +106,12 @@ public class ComplexFieldsValidatorTestCase { " struct-field desc { indexing: attribute }", "}", "}", - "}")); + "}"), logger); + assertThat(logger.message.toString().contains( + "For cluster 'mycluster', schema 'test': " + + "The following complex fields have struct fields with 'indexing: index' which is not supported and has no effect: " + + "topics (topics.id, topics.label). " + + "Remove setting or change to 'indexing: attribute' if needed for matching.")); } @Test @@ -126,18 +139,26 @@ public class ComplexFieldsValidatorTestCase { } private static void createModelAndValidate(String schema) throws IOException, SAXException { - DeployState deployState = createDeployState(servicesXml(), schema); + createModelAndValidate(schema, null); + } + + private static void createModelAndValidate(String schema, DeployLogger logger) throws IOException, SAXException { + DeployState deployState = createDeployState(servicesXml(), schema, logger); VespaModel model = new VespaModel(new NullConfigModelRegistry(), deployState); ValidationParameters validationParameters = new ValidationParameters(CheckRouting.FALSE); new Validation().validate(model, validationParameters, deployState); } - private static DeployState createDeployState(String servicesXml, String schema) { + private static DeployState createDeployState(String servicesXml, String schema, DeployLogger logger) { ApplicationPackage app = new MockApplicationPackage.Builder() .withServices(servicesXml) .withSchemas(List.of(schema)) .build(); - return new DeployState.Builder().applicationPackage(app).build(); + var builder = new DeployState.Builder().applicationPackage(app); + if (logger != null) { + builder.deployLogger(logger); + } + return builder.build(); } private static String servicesXml() { |