Skip to content

Commit 38aefe0

Browse files
authored
Run validation based on fields always, keep validation based on mapping optional (#2386)
This PR ensures that the validation based on fields is used for system tests always (as it is done nowadays). Validation based on mappings is kept optional and it can be enabled via environment variable.
1 parent 410c2e4 commit 38aefe0

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

.buildkite/pipeline.trigger.integration.tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ echo " - build/test-coverage/coverage-*.xml" # these files should not b
113113
# Add steps to test validation method mappings
114114
while IFS= read -r -d '' package ; do
115115
package_name=$(basename "${package}")
116-
echo " - label: \":go: Integration test: ${package_name} (just validate mappings)\""
116+
echo " - label: \":go: Integration test: ${package_name} (validate mappings)\""
117117
echo " key: \"integration-parallel-${package_name}-agent-validate-mappings\""
118118
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-check-packages-parallel -p ${package_name}"
119119
echo " env:"

internal/elasticsearch/client.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,16 @@ func (c *Client) SimulateIndexTemplate(ctx context.Context, indexTemplateName st
361361
return nil, nil, fmt.Errorf("error unmarshaling mappings: %w", err)
362362
}
363363

364+
// In case there are no dynamic templates, set an empty array
365+
if string(preview.Template.Mappings.DynamicTemplates) == "" {
366+
preview.Template.Mappings.DynamicTemplates = []byte("[]")
367+
}
368+
369+
// In case there are no mappings defined, set an empty map
370+
if string(preview.Template.Mappings.Properties) == "" {
371+
preview.Template.Mappings.Properties = []byte("{}")
372+
}
373+
364374
return preview.Template.Mappings.DynamicTemplates, preview.Template.Mappings.Properties, nil
365375
}
366376

@@ -403,5 +413,15 @@ func (c *Client) DataStreamMappings(ctx context.Context, dataStreamName string)
403413
mappingsDefinition = v.Mappings
404414
}
405415

416+
// In case there are no dynamic templates, set an empty array
417+
if string(mappingsDefinition.DynamicTemplates) == "" {
418+
mappingsDefinition.DynamicTemplates = []byte("[]")
419+
}
420+
421+
// In case there are no mappings defined, set an empty map
422+
if string(mappingsDefinition.Properties) == "" {
423+
mappingsDefinition.Properties = []byte("{}")
424+
}
425+
406426
return mappingsDefinition.DynamicTemplates, mappingsDefinition.Properties, nil
407427
}

internal/testrunner/runners/system/tester.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,11 @@ var (
141141
type fieldValidationMethod int
142142

143143
const (
144-
allMethods fieldValidationMethod = iota
145-
fieldsMethod
144+
fieldsMethod fieldValidationMethod = iota
146145
mappingsMethod
147146
)
148147

149148
var validationMethods = map[string]fieldValidationMethod{
150-
"all": allMethods,
151149
"fields": fieldsMethod,
152150
"mappings": mappingsMethod,
153151
}
@@ -1632,13 +1630,11 @@ func (r *tester) validateTestScenario(ctx context.Context, result *testrunner.Re
16321630
return result.WithErrorf("creating fields validator for data stream failed (path: %s): %w", r.dataStreamPath, err)
16331631
}
16341632

1635-
if r.fieldValidationMethod == allMethods || r.fieldValidationMethod == fieldsMethod {
1636-
if errs := validateFields(scenario.docs, fieldsValidator); len(errs) > 0 {
1637-
return result.WithError(testrunner.ErrTestCaseFailed{
1638-
Reason: fmt.Sprintf("one or more errors found in documents stored in %s data stream", scenario.dataStream),
1639-
Details: errs.Error(),
1640-
})
1641-
}
1633+
if errs := validateFields(scenario.docs, fieldsValidator); len(errs) > 0 {
1634+
return result.WithError(testrunner.ErrTestCaseFailed{
1635+
Reason: fmt.Sprintf("one or more errors found in documents stored in %s data stream", scenario.dataStream),
1636+
Details: errs.Error(),
1637+
})
16421638
}
16431639

16441640
stackVersion, err := semver.NewVersion(r.stackVersion.Number)
@@ -1651,8 +1647,8 @@ func (r *tester) validateTestScenario(ctx context.Context, result *testrunner.Re
16511647
return result.WithError(err)
16521648
}
16531649

1654-
if r.fieldValidationMethod == allMethods || r.fieldValidationMethod == mappingsMethod {
1655-
logger.Warn("Validate mappings found (technical preview)")
1650+
if r.fieldValidationMethod == mappingsMethod {
1651+
logger.Warn("Validation based on mappings enabled (technical preview)")
16561652
exceptionFields := listExceptionFields(scenario.docs, fieldsValidator)
16571653

16581654
mappingsValidator, err := fields.CreateValidatorForMappings(r.esClient,

0 commit comments

Comments
 (0)