Skip to content
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

Disable normalization validating fields in transforms if synthetics is enabled #2011

Merged
38 changes: 30 additions & 8 deletions internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,14 +842,35 @@ type scenarioTest struct {
startTestTime time.Time
}

type pipelineTrace []string

func (p *pipelineTrace) UnmarshalJSON(d []byte) error {
var alias interface{}
if err := json.Unmarshal(d, &alias); err != nil {
return err
}
switch v := alias.(type) {
case string:
*p = append(*p, v)
case []any:
// asume it is going to be an array of strings
for _, value := range v {
*p = append(*p, fmt.Sprint(value))
}
Comment on lines +853 to +859
Copy link
Contributor Author

@mrodm mrodm Aug 12, 2024

Choose a reason for hiding this comment

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

Support string and slice of strings.

Examples of the response:

  • logsdb disabled in the stack:
    {
      "type": "illegal_argument_exception",
      "message": "unable to convert [eight] to integer",
      "stack_trace": "...",
      "pipeline_trace": [
        "logs-failure_store.test-0.0.1"
      ],
      "pipeline": "logs-failure_store.test-0.0.1",
      "processor_type": "convert"
    }
  • logsdb enabled in the stack:
    {
      "message": "unable to convert [eight] to integer",
      "pipeline": "logs-failure_store.test-0.0.1",
      "pipeline_trace": "logs-failure_store.test-0.0.1",
      "processor_type": "convert",
      "stack_trace": "...",
      "type": "illegal_argument_exception"
    }

default:
return fmt.Errorf("unexpected type found for pipeline_trace: %T", v)
}
return nil
}

type failureStoreDocument struct {
Error struct {
Type string `json:"type"`
Message string `json:"message"`
StackTrace string `json:"stack_trace"`
PipelineTrace []string `json:"pipeline_trace"`
Pipeline string `json:"pipeline"`
ProcessorType string `json:"processor_type"`
Type string `json:"type"`
Message string `json:"message"`
StackTrace string `json:"stack_trace"`
PipelineTrace pipelineTrace `json:"pipeline_trace"`
Pipeline string `json:"pipeline"`
ProcessorType string `json:"processor_type"`
} `json:"error"`
}

Expand Down Expand Up @@ -1462,7 +1483,7 @@ func (r *tester) validateTestScenario(ctx context.Context, result *testrunner.Re
}

// Check transforms if present
if err := r.checkTransforms(ctx, config, r.pkgManifest, scenario.kibanaDataStream, scenario.dataStream); err != nil {
if err := r.checkTransforms(ctx, config, r.pkgManifest, scenario.kibanaDataStream, scenario.dataStream, scenario.syntheticEnabled); err != nil {
Copy link
Contributor Author

@mrodm mrodm Aug 9, 2024

Choose a reason for hiding this comment

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

Use the same value as in the main data stream.
Would that assumption be right?

Copy link
Member

Choose a reason for hiding this comment

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

Not sure what Fleet does with transform indexes. Could we add a test case that would fail without this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll check to run a test package for that use case (with logsdb enabled).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a new test package ti_anomali_logsdb copied from ti_anomali. This allows to test the package with both logsdb enabled and disabled.

results, _ := result.WithError(err)
return results, nil
}
Expand Down Expand Up @@ -1793,7 +1814,7 @@ func selectPolicyTemplateByName(policies []packages.PolicyTemplate, name string)
return packages.PolicyTemplate{}, fmt.Errorf("policy template %q not found", name)
}

func (r *tester) checkTransforms(ctx context.Context, config *testConfig, pkgManifest *packages.PackageManifest, ds kibana.PackageDataStream, dataStream string) error {
func (r *tester) checkTransforms(ctx context.Context, config *testConfig, pkgManifest *packages.PackageManifest, ds kibana.PackageDataStream, dataStream string, syntheticEnabled bool) error {
transforms, err := packages.ReadTransformsFromPackageRoot(r.packageRootPath)
if err != nil {
return fmt.Errorf("loading transforms for package failed (root: %s): %w", r.packageRootPath, err)
Expand Down Expand Up @@ -1839,6 +1860,7 @@ func (r *tester) checkTransforms(ctx context.Context, config *testConfig, pkgMan
fields.WithSpecVersion(pkgManifest.SpecVersion),
fields.WithNumericKeywordFields(config.NumericKeywordFields),
fields.WithEnabledImportAllECSSChema(true),
fields.WithDisableNormalization(syntheticEnabled),
)
if err != nil {
return fmt.Errorf("creating fields validator for data stream failed (path: %s): %w", transformRootPath, err)
Expand Down