-
Notifications
You must be signed in to change notification settings - Fork 124
Support routing_rules.yml and ingest pipeline test for reroute processor #1372
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
Merged
kaiyan-sheng
merged 12 commits into
elastic:main
from
kaiyan-sheng:add_default_index_name
Aug 7, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
09e534c
Support ingest pipeline test for reroute processor
kaiyan-sheng dca842e
check for reroute processor to skip checking dataset
kaiyan-sheng 2a8673a
read routing_rules.yml
kaiyan-sheng 2a2756f
address target_dataset and namespace to be either string or array
kaiyan-sheng 3cc742b
Merge remote-tracking branch 'upstream/main' into add_default_index_name
kaiyan-sheng bc82c16
add test package and unit tests
kaiyan-sheng eacd48e
run make check-static
kaiyan-sheng 19feb7a
run make update
kaiyan-sheng 5ec0790
Merge remote-tracking branch 'upstream/main' into add_default_index_name
kaiyan-sheng 17000b9
Merge remote-tracking branch 'upstream/main' into add_default_index_name
kaiyan-sheng d5f3077
only append routing rules after default pipeline
kaiyan-sheng d3444e8
rename SourceData to RoutingRule
kaiyan-sheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package ingest | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLoadRoutingRuleFileGoodSingleRule(t *testing.T) { | ||
mockDataStreamPath := "../testdata/routing_rules/good/single_rule" | ||
rerouteProcessors, err := loadRoutingRuleFile(mockDataStreamPath) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 3, len(rerouteProcessors)) | ||
|
||
expectedProcessors := map[string]struct { | ||
expectedIf string | ||
expectedDataset []string | ||
expectedNamespace []string | ||
}{ | ||
"multiple_namespace": { | ||
"ctx['aws.cloudwatch.log_stream'].contains('CloudTrail')", | ||
[]string{"aws.cloudtrail"}, | ||
[]string{"{{labels.data_stream.namespace}}", "default"}, | ||
}, | ||
"multiple_target_dataset": { | ||
"ctx['aws.cloudwatch.log_stream'].contains('Firewall')", | ||
[]string{"aws.firewall_logs", "aws.test_logs"}, | ||
[]string{"default"}, | ||
}, | ||
"single_namespace_target_dataset": { | ||
"ctx['aws.cloudwatch.log_stream'].contains('Route53')", | ||
[]string{"aws.route53_public_logs"}, | ||
[]string{"{{labels.data_stream.namespace}}"}, | ||
}, | ||
} | ||
|
||
for _, rerouteProcessor := range rerouteProcessors { | ||
p := rerouteProcessor["reroute"].(RerouteProcessor) | ||
assert.Equal(t, expectedProcessors[p.Tag].expectedIf, p.If) | ||
assert.Equal(t, expectedProcessors[p.Tag].expectedDataset, p.Dataset) | ||
assert.Equal(t, expectedProcessors[p.Tag].expectedNamespace, p.Namespace) | ||
} | ||
} | ||
|
||
func TestLoadRoutingRuleFileGoodMultipleRules(t *testing.T) { | ||
mockDataStreamPath := "../testdata/routing_rules/good/multiple_rules" | ||
rerouteProcessors, err := loadRoutingRuleFile(mockDataStreamPath) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 2, len(rerouteProcessors)) | ||
|
||
expectedProcessors := map[string]struct { | ||
expectedSourceDataset string | ||
expectedDataset []string | ||
expectedNamespace []string | ||
}{ | ||
"ctx['aws.cloudwatch.log_stream'].contains('Test1')": { | ||
"multiple_rules", | ||
[]string{"aws.test1_logs"}, | ||
[]string{"default"}, | ||
}, | ||
"ctx['aws.cloudwatch.log_stream'].contains('Test2')": { | ||
"multiple_rules", | ||
[]string{"aws.test2_logs"}, | ||
[]string{"{{labels.data_stream.namespace}}"}, | ||
}, | ||
} | ||
|
||
for _, rerouteProcessor := range rerouteProcessors { | ||
p := rerouteProcessor["reroute"].(RerouteProcessor) | ||
assert.Equal(t, expectedProcessors[p.If].expectedSourceDataset, p.Tag) | ||
assert.Equal(t, expectedProcessors[p.If].expectedDataset, p.Dataset) | ||
assert.Equal(t, expectedProcessors[p.If].expectedNamespace, p.Namespace) | ||
} | ||
} | ||
|
||
func TestLoadRoutingRuleFileGoodEmpty(t *testing.T) { | ||
mockDataStreamPath := "../testdata/routing_rules/good/empty" | ||
rerouteProcessors, err := loadRoutingRuleFile(mockDataStreamPath) | ||
assert.Equal(t, 0, len(rerouteProcessors)) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestLoadRoutingRuleFileBadMultipleSourceDataset(t *testing.T) { | ||
mockDataStreamPath := "../testdata/routing_rules/bad/multiple_source_dataset" | ||
rerouteProcessors, err := loadRoutingRuleFile(mockDataStreamPath) | ||
assert.Equal(t, 0, len(rerouteProcessors)) | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestLoadRoutingRuleFileBadNotString(t *testing.T) { | ||
mockDataStreamPath := "../testdata/routing_rules/bad/not_string" | ||
rerouteProcessors, err := loadRoutingRuleFile(mockDataStreamPath) | ||
assert.Equal(t, 0, len(rerouteProcessors)) | ||
assert.Error(t, err) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
internal/elasticsearch/testdata/routing_rules/bad/multiple_source_dataset/routing_rules.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
- source_dataset: | ||
- test1 | ||
- test2 | ||
rules: | ||
- target_dataset: aws.route53_public_logs | ||
if: ctx['aws.cloudwatch.log_stream'].contains('Route53') | ||
namespace: "{{labels.data_stream.namespace}}" |
5 changes: 5 additions & 0 deletions
5
internal/elasticsearch/testdata/routing_rules/bad/not_string/routing_rules.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- source_dataset: multiple_rules | ||
rules: | ||
- target_dataset: aws.test1_logs | ||
if: ctx['aws.cloudwatch.log_stream'].contains('Test1') | ||
namespace: 1 |
8 changes: 8 additions & 0 deletions
8
internal/elasticsearch/testdata/routing_rules/good/multiple_rules/routing_rules.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- source_dataset: multiple_rules | ||
rules: | ||
- target_dataset: aws.test1_logs | ||
if: ctx['aws.cloudwatch.log_stream'].contains('Test1') | ||
namespace: default | ||
- target_dataset: aws.test2_logs | ||
if: ctx['aws.cloudwatch.log_stream'].contains('Test2') | ||
namespace: "{{labels.data_stream.namespace}}" |
19 changes: 19 additions & 0 deletions
19
internal/elasticsearch/testdata/routing_rules/good/single_rule/routing_rules.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
- source_dataset: multiple_namespace | ||
rules: | ||
- target_dataset: aws.cloudtrail | ||
if: ctx['aws.cloudwatch.log_stream'].contains('CloudTrail') | ||
namespace: | ||
- "{{labels.data_stream.namespace}}" | ||
- default | ||
- source_dataset: multiple_target_dataset | ||
rules: | ||
- target_dataset: | ||
- aws.firewall_logs | ||
- aws.test_logs | ||
if: ctx['aws.cloudwatch.log_stream'].contains('Firewall') | ||
namespace: default | ||
- source_dataset: single_namespace_target_dataset | ||
rules: | ||
- target_dataset: aws.route53_public_logs | ||
if: ctx['aws.cloudwatch.log_stream'].contains('Route53') | ||
namespace: "{{labels.data_stream.namespace}}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.