Skip to content

Commit

Permalink
[chore][pkg/stanza] Cleanup uri parser operator files (#32119)
Browse files Browse the repository at this point in the history
Contributes to #32058
  • Loading branch information
djaglowski authored Apr 4, 2024
1 parent 5c7e342 commit 349156c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 41 deletions.
46 changes: 46 additions & 0 deletions pkg/stanza/operator/parser/uri/config.go
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
File renamed without changes.

0 comments on commit 349156c

Please sign in to comment.