From 7efa68114f8451d54e2c4e8cb6464414ae485a8f Mon Sep 17 00:00:00 2001 From: wph95 Date: Tue, 16 Mar 2021 13:54:01 +0800 Subject: [PATCH 1/7] journalinput config support mapstructure --- operator/builtin/input/journald/journald.go | 8 +++---- .../builtin/input/journald/journald_test.go | 24 +++++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/operator/builtin/input/journald/journald.go b/operator/builtin/input/journald/journald.go index 0335d4a9..810993d4 100644 --- a/operator/builtin/input/journald/journald.go +++ b/operator/builtin/input/journald/journald.go @@ -47,11 +47,11 @@ func NewJournaldInputConfig(operatorID string) *JournaldInputConfig { // JournaldInputConfig is the configuration of a journald input operator type JournaldInputConfig struct { - helper.InputConfig `yaml:",inline"` + helper.InputConfig `mapstructure:",squash" yaml:",inline"` - Directory *string `json:"directory,omitempty" yaml:"directory,omitempty"` - Files []string `json:"files,omitempty" yaml:"files,omitempty"` - StartAt string `json:"start_at,omitempty" yaml:"start_at,omitempty"` + Directory *string `mapstructure:"directory,omitempty" json:"directory,omitempty" yaml:"directory,omitempty"` + Files []string `mapstructure:"files,omitempty" json:"files,omitempty" yaml:"files,omitempty"` + StartAt string `mapstructure:"start_at,omitempty" json:"start_at,omitempty" yaml:"start_at,omitempty"` } // Build will build a journald input operator from the supplied configuration diff --git a/operator/builtin/input/journald/journald_test.go b/operator/builtin/input/journald/journald_test.go index 3d9c9971..65ce6232 100644 --- a/operator/builtin/input/journald/journald_test.go +++ b/operator/builtin/input/journald/journald_test.go @@ -24,11 +24,13 @@ import ( "testing" "time" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + "github.com/open-telemetry/opentelemetry-log-collection/entry" "github.com/open-telemetry/opentelemetry-log-collection/operator" + "github.com/open-telemetry/opentelemetry-log-collection/operator/helper" "github.com/open-telemetry/opentelemetry-log-collection/testutil" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" ) type fakeJournaldCmd struct{} @@ -113,3 +115,21 @@ func TestInputJournald(t *testing.T) { require.FailNow(t, "Timed out waiting for entry to be read") } } + +func TestJournaldInputConfig(t *testing.T) { + expect := NewJournaldInputConfig("my_journald_input") + expect.WriteTo = entry.NewRecordField("to") + + input := map[string]interface{}{ + "id": "my_journald_input", + "type": "journald_input", + "start_at": "end", + "write_to": "$record.to", + } + + var actual JournaldInputConfig + err := helper.UnmarshalMapstructure(input, &actual) + require.NoError(t, err) + require.Equal(t, expect, actual) + +} From cf5e965395efa9e51d88fc335bde60140224dc9a Mon Sep 17 00:00:00 2001 From: wph95 Date: Tue, 16 Mar 2021 14:21:01 +0800 Subject: [PATCH 2/7] fix ci --- operator/builtin/input/journald/journald_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/operator/builtin/input/journald/journald_test.go b/operator/builtin/input/journald/journald_test.go index 65ce6232..76f1d7a8 100644 --- a/operator/builtin/input/journald/journald_test.go +++ b/operator/builtin/input/journald/journald_test.go @@ -125,6 +125,8 @@ func TestJournaldInputConfig(t *testing.T) { "type": "journald_input", "start_at": "end", "write_to": "$record.to", + "attributes": map[string]interface{}{}, + "resource": map[string]interface{}{}, } var actual JournaldInputConfig From 9320773c4b5d694a6d6657724a859f3b9545dd3f Mon Sep 17 00:00:00 2001 From: wph95 Date: Tue, 16 Mar 2021 17:17:30 +0800 Subject: [PATCH 3/7] fix ci --- operator/builtin/input/journald/journald_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator/builtin/input/journald/journald_test.go b/operator/builtin/input/journald/journald_test.go index 76f1d7a8..6e620ccc 100644 --- a/operator/builtin/input/journald/journald_test.go +++ b/operator/builtin/input/journald/journald_test.go @@ -132,6 +132,6 @@ func TestJournaldInputConfig(t *testing.T) { var actual JournaldInputConfig err := helper.UnmarshalMapstructure(input, &actual) require.NoError(t, err) - require.Equal(t, expect, actual) + require.Equal(t, expect, &actual) } From 4318bf0267610254f5987f4d64e06066a41e1457 Mon Sep 17 00:00:00 2001 From: wph95 Date: Tue, 16 Mar 2021 21:41:20 +0800 Subject: [PATCH 4/7] restart ci From dc00f825377bc61dc82e7856105cb1b0b8d9e988 Mon Sep 17 00:00:00 2001 From: wph95 Date: Tue, 16 Mar 2021 22:04:30 +0800 Subject: [PATCH 5/7] restart ci From 0846dc7cf0813d21b3db1d9d0cc09c3617c395bb Mon Sep 17 00:00:00 2001 From: wph95 Date: Tue, 16 Mar 2021 22:20:07 +0800 Subject: [PATCH 6/7] fix ci --- operator/builtin/input/journald/journald_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/operator/builtin/input/journald/journald_test.go b/operator/builtin/input/journald/journald_test.go index 6e620ccc..e794aefa 100644 --- a/operator/builtin/input/journald/journald_test.go +++ b/operator/builtin/input/journald/journald_test.go @@ -121,12 +121,12 @@ func TestJournaldInputConfig(t *testing.T) { expect.WriteTo = entry.NewRecordField("to") input := map[string]interface{}{ - "id": "my_journald_input", - "type": "journald_input", - "start_at": "end", - "write_to": "$record.to", - "attributes": map[string]interface{}{}, - "resource": map[string]interface{}{}, + "id": "my_journald_input", + "type": "journald_input", + "start_at": "end", + "write_to": "$record.to", + "attributes": map[string]interface{}{}, + "resource": map[string]interface{}{}, } var actual JournaldInputConfig From 3124cfc49ca3e28437ac1cf19194bd0384c5a43f Mon Sep 17 00:00:00 2001 From: wph95 Date: Tue, 16 Mar 2021 22:48:23 +0800 Subject: [PATCH 7/7] remove unnecessary trailing newline --- operator/builtin/input/journald/journald_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/operator/builtin/input/journald/journald_test.go b/operator/builtin/input/journald/journald_test.go index e794aefa..87f22e3c 100644 --- a/operator/builtin/input/journald/journald_test.go +++ b/operator/builtin/input/journald/journald_test.go @@ -133,5 +133,4 @@ func TestJournaldInputConfig(t *testing.T) { err := helper.UnmarshalMapstructure(input, &actual) require.NoError(t, err) require.Equal(t, expect, &actual) - }