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

[Ingest Manager] Guard against empty stream.datasource and namespace #18769

Merged
merged 5 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
- Remove fleet admin from setup script {pull}18611[18611]
- Correctly report platform and family. {issue}18665[18665]
- Clean action store after enrolling to new configuration {pull}18656[18656]
[Ingest Manager] Avoid watching monitor logs {pull}18723[18723]
- Avoid watching monitor logs {pull}18723[18723]
Copy link
Contributor

Choose a reason for hiding this comment

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

double entry?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no i'm just fixing format of previous one

- Guard against empty stream.datasource and namespace {pull}18769[18769]

==== New features

Expand Down
16 changes: 12 additions & 4 deletions x-pack/elastic-agent/pkg/agent/transpiler/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ func (r *InjectIndexRule) Apply(ast *AST) error {
if found {
nsKey, ok := nsNode.(*Key)
if ok {
namespace = nsKey.value.String()
if newNamespace := nsKey.value.String(); newNamespace != "" {
namespace = newNamespace
}
}
}

Expand Down Expand Up @@ -413,7 +415,9 @@ func (r *InjectIndexRule) Apply(ast *AST) error {
if found {
dsKey, ok := dsNode.(*Key)
if ok {
dataset = dsKey.value.String()
if newDataset := dsKey.value.String(); newDataset != "" {
dataset = newDataset
}
}

}
Expand Down Expand Up @@ -464,7 +468,9 @@ func (r *InjectStreamProcessorRule) Apply(ast *AST) error {
if found {
nsKey, ok := nsNode.(*Key)
if ok {
namespace = nsKey.value.String()
if newNamespace := nsKey.value.String(); newNamespace != "" {
namespace = newNamespace
}
}
}

Expand Down Expand Up @@ -502,7 +508,9 @@ func (r *InjectStreamProcessorRule) Apply(ast *AST) error {
if found {
dsKey, ok := dsNode.(*Key)
if ok {
dataset = dsKey.value.String()
if newDataset := dsKey.value.String(); newDataset != "" {
dataset = newDataset
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions x-pack/elastic-agent/pkg/agent/transpiler/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ datasources:
streams:
- paths: /var/log/mysql/access.log
dataset: dsds
- name: All specified with empty strings
namespace: ""
inputs:
- type: file
streams:
- paths: /var/log/mysql/access.log
dataset: ""
`,
expectedYAML: `
datasources:
Expand Down Expand Up @@ -80,6 +87,14 @@ datasources:
- paths: /var/log/mysql/access.log
dataset: dsds
index: mytype-dsds-nsns
- name: All specified with empty strings
namespace: ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the expected now be default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is test for injecting index, it does not change existing values.
we either generate index based on these values or we're adding add_fields processor with correct values

Copy link
Contributor

Choose a reason for hiding this comment

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

we need both. values and index must match.

In a follow up we can discuss, if we should even error if it is "".

Copy link
Contributor

Choose a reason for hiding this comment

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

@michalpristas I also thought the result should be default?

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 think we can fix it but outside of injectIndex rule, what this should do is injecting index and not modifying anything on top of that.

inputs:
- type: file
streams:
- paths: /var/log/mysql/access.log
dataset: ""
index: mytype-generic-default
`,
rule: &RuleList{
Rules: []Rule{
Expand Down