Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

add journal_input support mapstructure #63

Merged
8 changes: 4 additions & 4 deletions operator/builtin/input/journald/journald.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 23 additions & 2 deletions operator/builtin/input/journald/journald_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -113,3 +115,22 @@ 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",
"attributes": map[string]interface{}{},
"resource": map[string]interface{}{},
}

var actual JournaldInputConfig
err := helper.UnmarshalMapstructure(input, &actual)
require.NoError(t, err)
require.Equal(t, expect, &actual)
}