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

[system tests] [transforms] Support commas in the source indices definition #2388

Merged
merged 4 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/howto/system_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ for system tests.
| skip.link | URL | | URL linking to an issue about why the test is skipped. |
| skip.reason | string | | Reason to skip the test. If specified the test will not execute. |
| skip_ignored_fields | array string | | List of fields to be skipped when performing validation of fields ignored during ingestion. |
| skip_transform_validation | boolean | | Disable or enable the transforms validation performed in system tests. |
| vars | dictionary | | Package level variables to set (i.e. declared in `$package_root/manifest.yml`). If not specified the defaults from the manifest are used. |
| wait_for_data_timeout | duration | | Amount of time to wait for data to be present in Elasticsearch. Defaults to 10m. |

Expand Down
22 changes: 14 additions & 8 deletions internal/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"path/filepath"
"slices"
"strings"

"github.com/elastic/go-ucfg"
"github.com/elastic/go-ucfg/yaml"
Expand Down Expand Up @@ -207,14 +208,19 @@ type TransformDefinition struct {
// HasSource checks if a given index or data stream name maches the transform sources
func (t *Transform) HasSource(name string) (bool, error) {
for _, indexPattern := range t.Definition.Source.Index {
// Using filepath.Match to match index patterns because the syntax
// is basically the same.
found, err := filepath.Match(indexPattern, name)
if err != nil {
return false, fmt.Errorf("maching pattern %q with %q: %w", indexPattern, name, err)
}
if found {
return true, nil
// Split the pattern by commas in case the source indexes are provided with a
// comma-separated index strings
patterns := strings.Split(indexPattern, ",")
for _, pattern := range patterns {
// Using filepath.Match to match index patterns because the syntax
// is basically the same.
found, err := filepath.Match(pattern, name)
if err != nil {
return false, fmt.Errorf("maching pattern %q with %q: %w", pattern, name, err)
}
if found {
return true, nil
}
}
}
return false, nil
Expand Down
2 changes: 2 additions & 0 deletions internal/testrunner/runners/system/test_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type testConfig struct {
Vars common.MapStr `config:"vars"`
} `config:"data_stream"`

SkipTransformValidation bool `config:"skip_transform_validation"`

Assert struct {
// Expected number of hits for a given test
HitCount int `config:"hit_count"`
Expand Down
9 changes: 8 additions & 1 deletion internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,10 @@ func selectPolicyTemplateByName(policies []packages.PolicyTemplate, name string)
}

func (r *tester) checkTransforms(ctx context.Context, config *testConfig, pkgManifest *packages.PackageManifest, ds kibana.PackageDataStream, dataStream string, syntheticEnabled bool) error {
if config.SkipTransformValidation {
return nil
}

Comment on lines +2060 to +2063
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Due to the errors found in the elasticsearch package from integrations (see PR description) when testing to check each index independently, it looks like it would be needed to add this kind of setting in the system tests.

transforms, err := packages.ReadTransformsFromPackageRoot(r.packageRootPath)
if err != nil {
return fmt.Errorf("loading transforms for package failed (root: %s): %w", r.packageRootPath, err)
Expand All @@ -2076,7 +2080,10 @@ func (r *tester) checkTransforms(ctx context.Context, config *testConfig, pkgMan
// IDs format is: "<type>-<package>.<transform>-<namespace>-<version>"
// For instance: "logs-ti_anomali.latest_ioc-default-0.1.0"
transformPattern := fmt.Sprintf("%s-%s.%s-*-%s",
ds.Inputs[0].Streams[0].DataStream.Type,
// It cannot be used "ds.Inputs[0].Streams[0].DataStream.Type" since Fleet
// always create the transform with the prefix "logs-"
// https://github.com/elastic/kibana/blob/eed02b930ad332ad7261a0a4dff521e36021fb31/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/transform/install.ts#L855
"logs",
pkgManifest.Name,
transform.Name,
transform.Definition.Meta.FleetTransformVersion,
Expand Down