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

Cherry-pick #11577 to 7.0: docker metadata processor: replace source field with log.field.path #11600

Merged
merged 1 commit into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ https://github.com/elastic/beats/compare/v7.0.0-rc1...master[Check the HEAD diff
- Don't apply multiline rules in Logstash json logs. {pull}11346[11346]
- Fix goroutine leak happening when harvesters are dynamically stopped. {pull}11263[11263]
- Fix panic in add_kubernetes_metadata processor when key `log` does not exist. {issue}11543[11543] {pull}11549[11549]
- 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 @@ -86,7 +86,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 @@ -122,10 +122,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