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

[Filebeat] Fix filebeat autodiscover fileset hint for container input #13296

Merged
merged 4 commits into from Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Expand Up @@ -127,6 +127,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Syslog input will now omit the `process` object from events if it is empty. {pull}12700[12700]
- Fix multiline pattern in Postgres which was too permissive {issue}12078[12078] {pull}13069[13069]
- Allow path variables to be used in files loaded from modules.d. {issue}13184[13184]
- Fix filebeat autodiscover fileset hint for container input. {pull}13296[13296]

*Heartbeat*

Expand Down
8 changes: 7 additions & 1 deletion filebeat/autodiscover/builder/hints/logs.go
Expand Up @@ -22,6 +22,7 @@ import (
"regexp"

"github.com/elastic/beats/filebeat/fileset"
"github.com/elastic/beats/filebeat/harvester"
"github.com/elastic/beats/libbeat/autodiscover"
"github.com/elastic/beats/libbeat/autodiscover/builder"
"github.com/elastic/beats/libbeat/autodiscover/template"
Expand Down Expand Up @@ -140,7 +141,12 @@ func (l *logHints) CreateConfig(event bus.Event) []*common.Config {
filesets := l.getFilesets(hints, module)
for fileset, conf := range filesets {
filesetConf, _ := common.NewConfigFrom(config)
filesetConf.SetString("containers.stream", -1, conf.Stream)

if inputType, _ := filesetConf.String("type", -1); inputType == harvester.ContainerType {
filesetConf.SetString("stream", -1, conf.Stream)
} else {
filesetConf.SetString("containers.stream", -1, conf.Stream)
}

moduleConf[fileset+".enabled"] = conf.Enabled
moduleConf[fileset+".input"] = filesetConf
Expand Down
141 changes: 141 additions & 0 deletions filebeat/autodiscover/builder/hints/logs_test.go
Expand Up @@ -473,6 +473,147 @@ func TestGenerateHints(t *testing.T) {
},
},
},
{
msg: "Hint with module should attach input to its filesets",
config: defaultCfg,
event: bus.Event{
"host": "1.2.3.4",
"kubernetes": common.MapStr{
"container": common.MapStr{
"name": "foobar",
"id": "abc",
},
},
"container": common.MapStr{
"name": "foobar",
"id": "abc",
},
"hints": common.MapStr{
"logs": common.MapStr{
"module": "apache2",
},
},
},
len: 1,
result: common.MapStr{
"module": "apache2",
"error": map[string]interface{}{
"enabled": true,
"input": map[string]interface{}{
"type": "container",
"stream": "all",
"paths": []interface{}{
"/var/lib/docker/containers/abc/*-json.log",
},
},
},
"access": map[string]interface{}{
"enabled": true,
"input": map[string]interface{}{
"type": "container",
"stream": "all",
"paths": []interface{}{
"/var/lib/docker/containers/abc/*-json.log",
},
},
},
},
},
{
msg: "Hint with module should honor defined filesets",
config: defaultCfg,
event: bus.Event{
"host": "1.2.3.4",
"kubernetes": common.MapStr{
"container": common.MapStr{
"name": "foobar",
"id": "abc",
},
},
"container": common.MapStr{
"name": "foobar",
"id": "abc",
},
"hints": common.MapStr{
"logs": common.MapStr{
"module": "apache2",
"fileset": "access",
},
},
},
len: 1,
result: common.MapStr{
"module": "apache2",
"access": map[string]interface{}{
"enabled": true,
"input": map[string]interface{}{
"type": "container",
"stream": "all",
"paths": []interface{}{
"/var/lib/docker/containers/abc/*-json.log",
},
},
},
"error": map[string]interface{}{
"enabled": false,
"input": map[string]interface{}{
"type": "container",
"stream": "all",
"paths": []interface{}{
"/var/lib/docker/containers/abc/*-json.log",
},
},
},
},
},
{
msg: "Hint with module should honor defined filesets with streams",
config: defaultCfg,
event: bus.Event{
"host": "1.2.3.4",
"kubernetes": common.MapStr{
"container": common.MapStr{
"name": "foobar",
"id": "abc",
},
},
"container": common.MapStr{
"name": "foobar",
"id": "abc",
},
"hints": common.MapStr{
"logs": common.MapStr{
"module": "apache2",
"fileset.stdout": "access",
"fileset.stderr": "error",
},
},
},
len: 1,
result: common.MapStr{
"module": "apache2",
"access": map[string]interface{}{
"enabled": true,
"input": map[string]interface{}{
"type": "container",
"stream": "stdout",
"paths": []interface{}{
"/var/lib/docker/containers/abc/*-json.log",
},
},
},
"error": map[string]interface{}{
"enabled": true,
"input": map[string]interface{}{
"type": "container",
"stream": "stderr",
"paths": []interface{}{
"/var/lib/docker/containers/abc/*-json.log",
},
},
},
},
},
}

for _, test := range tests {
Expand Down