Skip to content

Commit

Permalink
[Filebeat] Fix filebeat autodiscover fileset hint for container input (
Browse files Browse the repository at this point in the history
…elastic#13296) (elastic#13449)

Currently, autodiscover hint assumes that input type is docker.

Since docker input is deprecated in 7.2.0, container input should be supported.
So we need to set `stream` or `containers.stream` based on input type.

Closes elastic#12718

(cherry picked from commit 8c34c2b)

Co-authored-by: Kent Wang <pragkent@gmail.com>
  • Loading branch information
jsoriano and pragkent committed Aug 30, 2019
1 parent de9709f commit f2be98c
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Expand Up @@ -77,6 +77,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Improve detection of file deletion on Windows. {pull}10747[10747]
- Add missing Kubernetes metadata fields to Filebeat CoreDNS module, and fix a documentation error. {pull}11591[11591]
- Reduce memory usage if long lines are truncated to fit `max_bytes` limit. The line buffer is copied into a smaller buffer now. This allows the runtime to release unused memory earlier. {pull}11524[11524]
- Fix filebeat autodiscover fileset hint for container input. {pull}13296[13296]
- Fix timezone parsing of system module ingest pipelines. {pull}13308[13308]
- Fix incorrect field references in envoyproxy dashboard {issue}13420[13420] {pull}13421[13421]

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

0 comments on commit f2be98c

Please sign in to comment.