Skip to content

Commit

Permalink
Fixed Support add_docker_metadata in Windows (#7797) (#7844)
Browse files Browse the repository at this point in the history
Right now the separator used to parse container's logpaths is "/",
which fails to parse paths on Windows systems. This is resolved
by using os.PathSeparator to identify the seperator of the runtime
system.

Signed-off-by: Chris Mark <[email protected]>
  • Loading branch information
ChrsMark authored and exekias committed Aug 27, 2018
1 parent 3c1c6c1 commit 8c26770
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ https://github.com/elastic/beats/compare/v6.4.0...master[Check the HEAD diff]
- Remove unix-like permission checks on Windows, so files can be opened. {issue}7849[7849]
- Deregister pipeline loader callback when inputsRunner is stopped. {pull}7893[7893]
- Replace index patterns in TSVB visualizations. {pull}7929[7929]
- Fixed Support `add_docker_metadata` in Windows by identifying systems' path separator. {issue}7797[7797]

*Auditbeat*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func buildDockerMetadataProcessor(cfg *common.Config, watcherConstructor docker.
if config.MatchSource {
var procConf, _ = common.NewConfigFrom(map[string]interface{}{
"field": "source",
"separator": "/",
"separator": string(os.PathSeparator),
"index": config.SourceIndex,
"target": "docker.container.id",
})
Expand Down
14 changes: 12 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 @@ -24,6 +24,8 @@ import (

"github.com/stretchr/testify/assert"

"runtime"

"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/bus"
Expand Down Expand Up @@ -167,9 +169,17 @@ func TestMatchSource(t *testing.T) {
}))
assert.NoError(t, err, "initializing add_docker_metadata processor")

var inputSource string
switch runtime.GOOS {
case "windows":
inputSource = "C:\\ProgramData\\docker\\containers\\FABADA\\foo.log"
default:
inputSource = "/var/lib/docker/containers/FABADA/foo.log"
}
input := common.MapStr{
"source": "/var/lib/docker/containers/FABADA/foo.log",
"source": inputSource,
}

result, err := p.Run(&beat.Event{Fields: input})
assert.NoError(t, err, "processing an event")

Expand All @@ -185,7 +195,7 @@ func TestMatchSource(t *testing.T) {
"name": "name",
},
},
"source": "/var/lib/docker/containers/FABADA/foo.log",
"source": inputSource,
}, result.Fields)
}

Expand Down

0 comments on commit 8c26770

Please sign in to comment.