Skip to content

Commit

Permalink
[Logs]: Fixed issue with missing tags when collecting logs from docke…
Browse files Browse the repository at this point in the history
…r container (#1420)
  • Loading branch information
ajacquemot authored and truthbk committed Mar 8, 2018
1 parent ae00ca6 commit c179763
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
12 changes: 9 additions & 3 deletions pkg/logs/message/origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ func (o *Origin) TagsPayload() []byte {
if o.LogSource.Config.SourceCategory != "" {
tagsPayload = append(tagsPayload, []byte("[dd ddsourcecategory=\""+o.LogSource.Config.SourceCategory+"\"]")...)
}
var tags string
if o.LogSource.Config.Tags != "" {
tags := o.LogSource.Config.Tags
if len(o.tags) > 0 {
tags = tags + "," + strings.Join(o.tags, ",")
tags = o.LogSource.Config.Tags
}
if len(o.tags) > 0 {
if tags != "" {
tags = tags + ","
}
tags = tags + strings.Join(o.tags, ",")
}
if tags != "" {
tagsPayload = append(tagsPayload, []byte("[dd ddtags=\""+tags+"\"]")...)
}
if len(tagsPayload) == 0 {
Expand Down
28 changes: 27 additions & 1 deletion pkg/logs/message/origin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,33 @@ func TestSetTagsEmpty(t *testing.T) {
assert.Equal(t, []byte{}, origin.TagsPayload())
}

func TestSetTags(t *testing.T) {
func TestTagsWithConfigTagsOnly(t *testing.T) {
cfg := &config.LogsConfig{
Source: "a",
SourceCategory: "b",
Tags: "c:d,e",
}
source := config.NewLogSource("", cfg)
origin := NewOrigin()
origin.LogSource = source
assert.Equal(t, []string{"source:a", "sourcecategory:b", "c:d", "e"}, origin.Tags())
assert.Equal(t, "[dd ddsource=\"a\"][dd ddsourcecategory=\"b\"][dd ddtags=\"c:d,e\"]", string(origin.TagsPayload()))
}

func TestSetTagsWithNoConfigTags(t *testing.T) {
cfg := &config.LogsConfig{
Source: "a",
SourceCategory: "b",
}
source := config.NewLogSource("", cfg)
origin := NewOrigin()
origin.LogSource = source
origin.SetTags([]string{"foo:bar", "baz"})
assert.Equal(t, []string{"foo:bar", "baz", "source:a", "sourcecategory:b"}, origin.Tags())
assert.Equal(t, "[dd ddsource=\"a\"][dd ddsourcecategory=\"b\"][dd ddtags=\"foo:bar,baz\"]", string(origin.TagsPayload()))
}

func TestSetTagsWithConfigTags(t *testing.T) {
cfg := &config.LogsConfig{
Source: "a",
SourceCategory: "b",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Fixed the issue preventing from having docker tags when collecting logs from containers.

0 comments on commit c179763

Please sign in to comment.