From 349156cd9c84487b0c433a90a67f6b6408a53d2b Mon Sep 17 00:00:00 2001 From: Daniel Jaglowski Date: Wed, 3 Apr 2024 20:40:25 -0500 Subject: [PATCH] [chore][pkg/stanza] Cleanup uri parser operator files (#32119) Contributes to #32058 --- pkg/stanza/operator/parser/uri/config.go | 46 +++++++++++++++++++ .../operator/parser/uri/{uri.go => parser.go} | 44 ++---------------- .../uri/{uri_test.go => parser_test.go} | 0 3 files changed, 49 insertions(+), 41 deletions(-) create mode 100644 pkg/stanza/operator/parser/uri/config.go rename pkg/stanza/operator/parser/uri/{uri.go => parser.go} (68%) rename pkg/stanza/operator/parser/uri/{uri_test.go => parser_test.go} (100%) diff --git a/pkg/stanza/operator/parser/uri/config.go b/pkg/stanza/operator/parser/uri/config.go new file mode 100644 index 000000000000..0c2efe436805 --- /dev/null +++ b/pkg/stanza/operator/parser/uri/config.go @@ -0,0 +1,46 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package uri // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/parser/uri" + +import ( + "go.uber.org/zap" + + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper" +) + +const operatorType = "uri_parser" + +func init() { + operator.Register(operatorType, func() operator.Builder { return NewConfig() }) +} + +// NewConfig creates a new uri parser config with default values. +func NewConfig() *Config { + return NewConfigWithID(operatorType) +} + +// NewConfigWithID creates a new uri parser config with default values. +func NewConfigWithID(operatorID string) *Config { + return &Config{ + ParserConfig: helper.NewParserConfig(operatorID, operatorType), + } +} + +// Config is the configuration of a uri parser operator. +type Config struct { + helper.ParserConfig `mapstructure:",squash"` +} + +// Build will build a uri parser operator. +func (c Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) { + parserOperator, err := c.ParserConfig.Build(logger) + if err != nil { + return nil, err + } + + return &Parser{ + ParserOperator: parserOperator, + }, nil +} diff --git a/pkg/stanza/operator/parser/uri/uri.go b/pkg/stanza/operator/parser/uri/parser.go similarity index 68% rename from pkg/stanza/operator/parser/uri/uri.go rename to pkg/stanza/operator/parser/uri/parser.go index 621709c8364b..e7761239cbbc 100644 --- a/pkg/stanza/operator/parser/uri/uri.go +++ b/pkg/stanza/operator/parser/uri/parser.go @@ -9,60 +9,22 @@ import ( "net/url" "strings" - "go.uber.org/zap" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper" ) -const operatorType = "uri_parser" - -func init() { - operator.Register(operatorType, func() operator.Builder { return NewConfig() }) -} - -// NewConfig creates a new uri parser config with default values. -func NewConfig() *Config { - return NewConfigWithID(operatorType) -} - -// NewConfigWithID creates a new uri parser config with default values. -func NewConfigWithID(operatorID string) *Config { - return &Config{ - ParserConfig: helper.NewParserConfig(operatorID, operatorType), - } -} - -// Config is the configuration of a uri parser operator. -type Config struct { - helper.ParserConfig `mapstructure:",squash"` -} - -// Build will build a uri parser operator. -func (c Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) { - parserOperator, err := c.ParserConfig.Build(logger) - if err != nil { - return nil, err - } - - return &Parser{ - ParserOperator: parserOperator, - }, nil -} - // Parser is an operator that parses a uri. type Parser struct { helper.ParserOperator } // Process will parse an entry. -func (u *Parser) Process(ctx context.Context, entry *entry.Entry) error { - return u.ParserOperator.ProcessWith(ctx, entry, u.parse) +func (p *Parser) Process(ctx context.Context, entry *entry.Entry) error { + return p.ParserOperator.ProcessWith(ctx, entry, p.parse) } // parse will parse a uri from a field and attach it to an entry. -func (u *Parser) parse(value any) (any, error) { +func (p *Parser) parse(value any) (any, error) { switch m := value.(type) { case string: return parseURI(m) diff --git a/pkg/stanza/operator/parser/uri/uri_test.go b/pkg/stanza/operator/parser/uri/parser_test.go similarity index 100% rename from pkg/stanza/operator/parser/uri/uri_test.go rename to pkg/stanza/operator/parser/uri/parser_test.go