Skip to content

Commit e03f95d

Browse files
authored
add journal_input support mapstructure (#63)
* journalinput config support mapstructure
1 parent 0576b45 commit e03f95d

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

operator/builtin/input/journald/journald.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ func NewJournaldInputConfig(operatorID string) *JournaldInputConfig {
4747

4848
// JournaldInputConfig is the configuration of a journald input operator
4949
type JournaldInputConfig struct {
50-
helper.InputConfig `yaml:",inline"`
50+
helper.InputConfig `mapstructure:",squash" yaml:",inline"`
5151

52-
Directory *string `json:"directory,omitempty" yaml:"directory,omitempty"`
53-
Files []string `json:"files,omitempty" yaml:"files,omitempty"`
54-
StartAt string `json:"start_at,omitempty" yaml:"start_at,omitempty"`
52+
Directory *string `mapstructure:"directory,omitempty" json:"directory,omitempty" yaml:"directory,omitempty"`
53+
Files []string `mapstructure:"files,omitempty" json:"files,omitempty" yaml:"files,omitempty"`
54+
StartAt string `mapstructure:"start_at,omitempty" json:"start_at,omitempty" yaml:"start_at,omitempty"`
5555
}
5656

5757
// Build will build a journald input operator from the supplied configuration

operator/builtin/input/journald/journald_test.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ import (
2424
"testing"
2525
"time"
2626

27+
"github.com/stretchr/testify/mock"
28+
"github.com/stretchr/testify/require"
29+
2730
"github.com/open-telemetry/opentelemetry-log-collection/entry"
2831
"github.com/open-telemetry/opentelemetry-log-collection/operator"
32+
"github.com/open-telemetry/opentelemetry-log-collection/operator/helper"
2933
"github.com/open-telemetry/opentelemetry-log-collection/testutil"
30-
"github.com/stretchr/testify/mock"
31-
"github.com/stretchr/testify/require"
3234
)
3335

3436
type fakeJournaldCmd struct{}
@@ -113,3 +115,22 @@ func TestInputJournald(t *testing.T) {
113115
require.FailNow(t, "Timed out waiting for entry to be read")
114116
}
115117
}
118+
119+
func TestJournaldInputConfig(t *testing.T) {
120+
expect := NewJournaldInputConfig("my_journald_input")
121+
expect.WriteTo = entry.NewRecordField("to")
122+
123+
input := map[string]interface{}{
124+
"id": "my_journald_input",
125+
"type": "journald_input",
126+
"start_at": "end",
127+
"write_to": "$record.to",
128+
"attributes": map[string]interface{}{},
129+
"resource": map[string]interface{}{},
130+
}
131+
132+
var actual JournaldInputConfig
133+
err := helper.UnmarshalMapstructure(input, &actual)
134+
require.NoError(t, err)
135+
require.Equal(t, expect, &actual)
136+
}

0 commit comments

Comments
 (0)