Skip to content

Commit

Permalink
[system tests] [transforms] Support commas in the source indices defi…
Browse files Browse the repository at this point in the history
…nition (#2388)

Support commas in source indices definition (transforms) if they
are defined as a list of comma-separated strings. Added also a new
system test configuration/setting to allow skipping the validation
of transforms.
  • Loading branch information
mrodm authored Feb 5, 2025
1 parent 38aefe0 commit b7445a2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
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
}

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

0 comments on commit b7445a2

Please sign in to comment.