Skip to content

Commit

Permalink
docker metadata processor: replace source field with log.field.path (#…
Browse files Browse the repository at this point in the history
…11577)

* docker metadata processor: replace source field with log.field.path
  • Loading branch information
Pablo Mercado committed Apr 2, 2019
1 parent c0bfdbd commit ce68c78
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix registry entries not being cleaned due to race conditions. {pull}10747[10747]
- Improve detection of file deletion on Windows. {pull}10747[10747]
- Fix goroutine leak happening when harvesters are dynamically stopped. {pull}11263[11263]
- Fix `add_docker_metadata` source matching, using `log.file.path` field now. {pull}11577[11577]

*Heartbeat*

Expand Down
8 changes: 4 additions & 4 deletions libbeat/processors/add_docker_metadata/add_docker_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func buildDockerMetadataProcessor(cfg *common.Config, watcherConstructor docker.
var sourceProcessor processors.Processor
if config.MatchSource {
var procConf, _ = common.NewConfigFrom(map[string]interface{}{
"field": "source",
"field": "log.file.path",
"separator": string(os.PathSeparator),
"index": config.SourceIndex,
"target": dockerContainerIDKey,
Expand Down Expand Up @@ -123,10 +123,10 @@ func lazyCgroupCacheInit(d *addDockerMetadata) {
func (d *addDockerMetadata) Run(event *beat.Event) (*beat.Event, error) {
var cid string
var err error

// Extract CID from the filepath contained in the "source" field.
// Extract CID from the filepath contained in the "log.file.path" field.
if d.sourceProcessor != nil {
if event.Fields["source"] != nil {
lfp, _ := event.Fields.GetValue("log.file.path")
if lfp != nil {
event, err = d.sourceProcessor.Run(event)
if err != nil {
d.log.Debugf("Error while extracting container ID from source path: %v", err)
Expand Down
12 changes: 10 additions & 2 deletions libbeat/processors/add_docker_metadata/add_docker_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ func TestMatchSource(t *testing.T) {
inputSource = "/var/lib/docker/containers/FABADA/foo.log"
}
input := common.MapStr{
"source": inputSource,
"log": common.MapStr{
"file": common.MapStr{
"path": inputSource,
},
},
}

result, err := p.Run(&beat.Event{Fields: input})
Expand All @@ -239,7 +243,11 @@ func TestMatchSource(t *testing.T) {
},
"name": "name",
},
"source": inputSource,
"log": common.MapStr{
"file": common.MapStr{
"path": inputSource,
},
},
}, result.Fields)
}

Expand Down

0 comments on commit ce68c78

Please sign in to comment.