Skip to content

Commit

Permalink
update stanza api
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Sep 14, 2023
1 parent cfbe4b7 commit a768a62
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
26 changes: 14 additions & 12 deletions internal/receiver/scriptedinputsreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (
"sort"
"time"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/decode"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/split"
"go.uber.org/zap"
)

Expand All @@ -43,12 +45,12 @@ var availableScripts = func() []string {
}()

type Config struct {
Multiline helper.MultilineConfig `mapstructure:"multiline,omitempty"`
ScriptName string `mapstructure:"script_name,omitempty"`
Encoding helper.EncodingConfig `mapstructure:",squash,omitempty"`
Source string `mapstructure:"source"`
SourceType string `mapstructure:"sourcetype"`
CollectionInterval string `mapstructure:"collection_interval"`
Multiline split.Config `mapstructure:"multiline,omitempty"`
ScriptName string `mapstructure:"script_name,omitempty"`
Encoding string `mapstructure:"encoding,omitempty"`
Source string `mapstructure:"source"`
SourceType string `mapstructure:"sourcetype"`
CollectionInterval string `mapstructure:"collection_interval"`
helper.InputConfig `mapstructure:",squash"`
MaxLogSize helper.ByteSize `mapstructure:"max_log_size,omitempty"`
interval time.Duration
Expand All @@ -57,9 +59,9 @@ type Config struct {

func createDefaultConfig() *Config {
return &Config{
Encoding: "utf-8",
InputConfig: helper.NewInputConfig(typeStr, typeStr),
Multiline: helper.NewMultilineConfig(),
Encoding: helper.NewEncodingConfig(),
Multiline: split.Config{},
CollectionInterval: defaultCollectionInterval,
MaxLogSize: defaultMaxLogSize,
}
Expand Down Expand Up @@ -99,17 +101,17 @@ func (c *Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) {
return nil, err
}

enc, err := helper.LookupEncoding(c.Encoding.Encoding)
enc, err := decode.LookupEncoding(c.Encoding)
if err != nil {
return nil, err
}

// Build multiline
var splitFunc bufio.SplitFunc
if c.Multiline.LineStartPattern == "" && c.Multiline.LineEndPattern == "" {
splitFunc = helper.SplitNone(int(c.MaxLogSize))
splitFunc = split.NoSplitFunc(int(c.MaxLogSize))
} else {
splitFunc, err = c.Multiline.Build(enc, true, false, false, nil, int(c.MaxLogSize))
splitFunc, err = c.Multiline.Func(enc, true, int(c.MaxLogSize), nil)
if err != nil {
return nil, err
}
Expand All @@ -125,7 +127,7 @@ func (c *Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) {
cfg: c,
InputOperator: inputOperator,
logger: logger,
decoder: helper.NewDecoder(enc),
decoder: decode.New(enc),
splitFunc: splitFunc,
scriptContent: scriptContent,
}, nil
Expand Down
7 changes: 4 additions & 3 deletions internal/receiver/scriptedinputsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/split"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -64,12 +65,12 @@ func TestValidConfig(t *testing.T) {
OperatorType: "scripted_inputs",
}, OutputIDs: []string(nil)},
},
Multiline: helper.MultilineConfig{
Multiline: split.Config{
LineStartPattern: "",
LineEndPattern: "",
},
ScriptName: "cpu",
Encoding: helper.EncodingConfig{Encoding: "utf-8"},
Encoding: "utf-8",
Source: "",
SourceType: "",
CollectionInterval: "60s",
Expand Down Expand Up @@ -123,7 +124,7 @@ func TestCreateWithNonEmptyMultiline(t *testing.T) {
config.ScriptName = "aasd"
config.OperatorType = "test-operator"

config.Multiline = helper.MultilineConfig{
config.Multiline = split.Config{
LineStartPattern: "a",
LineEndPattern: "",
}
Expand Down
3 changes: 2 additions & 1 deletion internal/receiver/scriptedinputsreceiver/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sync"
"time"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/decode"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
"go.uber.org/zap"
Expand All @@ -43,7 +44,7 @@ type stdoutOperator struct {
logger *zap.SugaredLogger
cancelAll context.CancelFunc
splitFunc bufio.SplitFunc
decoder *helper.Decoder
decoder *decode.Decoder
scriptContent string
helper.InputOperator
wg sync.WaitGroup
Expand Down

0 comments on commit a768a62

Please sign in to comment.