Skip to content

Commit

Permalink
[pkg/stanza] Remove unused json and yaml tags from operators (#14553)
Browse files Browse the repository at this point in the history
Operators are no longer unmarshaled based on json or yaml libaries,
so do not require the associated tags.
  • Loading branch information
djaglowski authored Sep 28, 2022
1 parent 5aa49ba commit f64d7ab
Show file tree
Hide file tree
Showing 50 changed files with 165 additions and 206 deletions.
2 changes: 1 addition & 1 deletion pkg/stanza/adapter/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func init() {

// UnstartableConfig is the configuration of an unstartable mock operator
type UnstartableConfig struct {
helper.OutputConfig `yaml:",inline"`
helper.OutputConfig `mapstructure:",squash"`
}

// UnstartableOperator is an operator that will build but not start
Expand Down
22 changes: 11 additions & 11 deletions pkg/stanza/fileconsumer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ func NewConfig() *Config {

// Config is the configuration of a file input operator
type Config struct {
Finder `mapstructure:",squash" yaml:",inline"`
IncludeFileName bool `mapstructure:"include_file_name,omitempty" json:"include_file_name,omitempty" yaml:"include_file_name,omitempty"`
IncludeFilePath bool `mapstructure:"include_file_path,omitempty" json:"include_file_path,omitempty" yaml:"include_file_path,omitempty"`
IncludeFileNameResolved bool `mapstructure:"include_file_name_resolved,omitempty" json:"include_file_name_resolved,omitempty" yaml:"include_file_name_resolved,omitempty"`
IncludeFilePathResolved bool `mapstructure:"include_file_path_resolved,omitempty" json:"include_file_path_resolved,omitempty" yaml:"include_file_path_resolved,omitempty"`
PollInterval time.Duration `mapstructure:"poll_interval,omitempty" json:"poll_interval,omitempty" yaml:"poll_interval,omitempty"`
StartAt string `mapstructure:"start_at,omitempty" json:"start_at,omitempty" yaml:"start_at,omitempty"`
FingerprintSize helper.ByteSize `mapstructure:"fingerprint_size,omitempty" json:"fingerprint_size,omitempty" yaml:"fingerprint_size,omitempty"`
MaxLogSize helper.ByteSize `mapstructure:"max_log_size,omitempty" json:"max_log_size,omitempty" yaml:"max_log_size,omitempty"`
MaxConcurrentFiles int `mapstructure:"max_concurrent_files,omitempty" json:"max_concurrent_files,omitempty" yaml:"max_concurrent_files,omitempty"`
Splitter helper.SplitterConfig `mapstructure:",squash,omitempty" json:",inline,omitempty" yaml:",inline,omitempty"`
Finder `mapstructure:",squash"`
IncludeFileName bool `mapstructure:"include_file_name,omitempty"`
IncludeFilePath bool `mapstructure:"include_file_path,omitempty"`
IncludeFileNameResolved bool `mapstructure:"include_file_name_resolved,omitempty"`
IncludeFilePathResolved bool `mapstructure:"include_file_path_resolved,omitempty"`
PollInterval time.Duration `mapstructure:"poll_interval,omitempty"`
StartAt string `mapstructure:"start_at,omitempty"`
FingerprintSize helper.ByteSize `mapstructure:"fingerprint_size,omitempty"`
MaxLogSize helper.ByteSize `mapstructure:"max_log_size,omitempty"`
MaxConcurrentFiles int `mapstructure:"max_concurrent_files,omitempty"`
Splitter helper.SplitterConfig `mapstructure:",squash,omitempty"`
}

// Build will build a file input operator from the supplied configuration
Expand Down
4 changes: 2 additions & 2 deletions pkg/stanza/fileconsumer/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
)

type Finder struct {
Include []string `mapstructure:"include,omitempty" json:"include,omitempty" yaml:"include,omitempty"`
Exclude []string `mapstructure:"exclude,omitempty" json:"exclude,omitempty" yaml:"exclude,omitempty"`
Include []string `mapstructure:"include,omitempty"`
Exclude []string `mapstructure:"exclude,omitempty"`
}

// FindFiles gets a list of paths given an array of glob patterns to include and exclude
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/fileconsumer/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type readerConfig struct {

// Reader manages a single file
type Reader struct {
*zap.SugaredLogger `json:"-"`
*zap.SugaredLogger `json:"-"` // json tag excludes embedded fields from storage
*readerConfig
splitter *helper.Splitter

Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/operator/helper/attributer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewAttributerConfig() AttributerConfig {

// AttributerConfig is the configuration of a attributer
type AttributerConfig struct {
Attributes map[string]ExprStringConfig `mapstructure:"attributes" json:"attributes" yaml:"attributes"`
Attributes map[string]ExprStringConfig `mapstructure:"attributes"`
}

// Build will build a attributer from the supplied configuration
Expand Down
24 changes: 7 additions & 17 deletions pkg/stanza/operator/helper/bytesize.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,31 @@ import (

type ByteSize int64

func (h *ByteSize) UnmarshalJSON(raw []byte) error {
return h.unmarshalShared(func(i interface{}) error {
return json.Unmarshal(raw, &i)
})
}

func (h *ByteSize) UnmarshalYAML(unmarshal func(interface{}) error) error {
return h.unmarshalShared(unmarshal)
}
var byteSizeRegex = regexp.MustCompile(`^([0-9]+\.?[0-9]*)\s*([kKmMgGtTpP]i?[bB])?$`)

func (h *ByteSize) UnmarshalText(text []byte) (err error) {
slice := make([]byte, 1, 2+len(text))
slice[0] = byte('"')
slice = append(slice, text...)
slice = append(slice, byte('"'))
return h.UnmarshalJSON(slice)
}

var byteSizeRegex = regexp.MustCompile(`^([0-9]+\.?[0-9]*)\s*([kKmMgGtTpP]i?[bB])?$`)
unmarshal := func(i interface{}) error {
return json.Unmarshal(slice, &i)
}

func (h *ByteSize) unmarshalShared(unmarshal func(interface{}) error) error {
var intType int64
if err := unmarshal(&intType); err == nil {
if err = unmarshal(&intType); err == nil {
*h = ByteSize(intType)
return nil
}

var floatType float64
if err := unmarshal(&floatType); err == nil {
if err = unmarshal(&floatType); err == nil {
*h = ByteSize(int64(floatType))
return nil
}

var stringType string
if err := unmarshal(&stringType); err != nil {
if err = unmarshal(&stringType); err != nil {
return fmt.Errorf("failed to unmarshal to int64, float64, or string: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/operator/helper/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewEncodingConfig() EncodingConfig {

// EncodingConfig is the configuration of a Encoding helper
type EncodingConfig struct {
Encoding string `mapstructure:"encoding,omitempty" json:"encoding,omitempty" yaml:"encoding,omitempty"`
Encoding string `mapstructure:"encoding,omitempty"`
}

// Build will build an Encoding operator.
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/operator/helper/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewIdentifierConfig() IdentifierConfig {

// IdentifierConfig is the configuration of a resource identifier
type IdentifierConfig struct {
Resource map[string]ExprStringConfig `mapstructure:"resource" json:"resource" yaml:"resource"`
Resource map[string]ExprStringConfig `mapstructure:"resource"`
}

// Build will build an identifier from the supplied configuration
Expand Down
6 changes: 3 additions & 3 deletions pkg/stanza/operator/helper/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func NewInputConfig(operatorID, operatorType string) InputConfig {

// InputConfig provides a basic implementation of an input operator config.
type InputConfig struct {
AttributerConfig `mapstructure:",squash" yaml:",inline"`
IdentifierConfig `mapstructure:",squash" yaml:",inline"`
WriterConfig `mapstructure:",squash" yaml:",inline"`
AttributerConfig `mapstructure:",squash"`
IdentifierConfig `mapstructure:",squash"`
WriterConfig `mapstructure:",squash"`
}

// Build will build a base producer.
Expand Down
12 changes: 6 additions & 6 deletions pkg/stanza/operator/helper/multiline.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// FlusherConfig is a configuration of Flusher helper
type FlusherConfig struct {
Period time.Duration `mapstructure:"force_flush_period" json:"force_flush_period" yaml:"force_flush_period"`
Period time.Duration `mapstructure:"force_flush_period"`
}

// NewFlusherConfig creates a default Flusher config
Expand Down Expand Up @@ -131,8 +131,8 @@ func NewMultilineConfig() MultilineConfig {

// MultilineConfig is the configuration of a multiline helper
type MultilineConfig struct {
LineStartPattern string `mapstructure:"line_start_pattern" json:"line_start_pattern" yaml:"line_start_pattern"`
LineEndPattern string `mapstructure:"line_end_pattern" json:"line_end_pattern" yaml:"line_end_pattern"`
LineStartPattern string `mapstructure:"line_start_pattern"`
LineEndPattern string `mapstructure:"line_end_pattern"`
}

// Build will build a Multiline operator.
Expand Down Expand Up @@ -348,9 +348,9 @@ func trimWhitespaces(data []byte) []byte {

// SplitterConfig consolidates MultilineConfig and FlusherConfig
type SplitterConfig struct {
EncodingConfig EncodingConfig `mapstructure:",squash,omitempty" json:",inline,omitempty" yaml:",inline,omitempty"`
Multiline MultilineConfig `mapstructure:"multiline,omitempty" json:"multiline,omitempty" yaml:"multiline,omitempty"`
Flusher FlusherConfig `mapstructure:",squash,omitempty" json:",inline,omitempty" yaml:",inline,omitempty"`
EncodingConfig EncodingConfig `mapstructure:",squash,omitempty"`
Multiline MultilineConfig `mapstructure:"multiline,omitempty"`
Flusher FlusherConfig `mapstructure:",squash,omitempty"`
}

// NewSplitterConfig returns default SplitterConfig
Expand Down
4 changes: 2 additions & 2 deletions pkg/stanza/operator/helper/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func NewBasicConfig(operatorID, operatorType string) BasicConfig {

// BasicConfig provides a basic implemention for an operator config.
type BasicConfig struct {
OperatorID string `mapstructure:"id" json:"id" yaml:"id"`
OperatorType string `mapstructure:"type" json:"type" yaml:"type"`
OperatorID string `mapstructure:"id"`
OperatorType string `mapstructure:"type"`
}

// ID will return the operator id.
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/operator/helper/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewOutputConfig(operatorID, operatorType string) OutputConfig {

// OutputConfig provides a basic implementation of an output operator config.
type OutputConfig struct {
BasicConfig `mapstructure:",squash" yaml:",inline"`
BasicConfig `mapstructure:",squash"`
}

// Build will build an output operator.
Expand Down
16 changes: 8 additions & 8 deletions pkg/stanza/operator/helper/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func NewParserConfig(operatorID, operatorType string) ParserConfig {

// ParserConfig provides the basic implementation of a parser config.
type ParserConfig struct {
TransformerConfig `mapstructure:",squash" yaml:",inline"`
ParseFrom entry.Field `mapstructure:"parse_from" json:"parse_from" yaml:"parse_from"`
ParseTo entry.RootableField `mapstructure:"parse_to" json:"parse_to" yaml:"parse_to"`
BodyField *entry.Field `mapstructure:"body" json:"body" yaml:"body"`
TimeParser *TimeParser `mapstructure:"timestamp,omitempty" json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
SeverityConfig *SeverityConfig `mapstructure:"severity,omitempty" json:"severity,omitempty" yaml:"severity,omitempty"`
TraceParser *TraceParser `mapstructure:"trace,omitempty" json:"trace,omitempty" yaml:"trace,omitempty"`
ScopeNameParser *ScopeNameParser `mapstructure:"scope_name,omitempty" json:"scope_name,omitempty" yaml:"scope_name,omitempty"`
TransformerConfig `mapstructure:",squash"`
ParseFrom entry.Field `mapstructure:"parse_from"`
ParseTo entry.RootableField `mapstructure:"parse_to"`
BodyField *entry.Field `mapstructure:"body"`
TimeParser *TimeParser `mapstructure:"timestamp,omitempty"`
SeverityConfig *SeverityConfig `mapstructure:"severity,omitempty"`
TraceParser *TraceParser `mapstructure:"trace,omitempty"`
ScopeNameParser *ScopeNameParser `mapstructure:"scope_name,omitempty"`
}

// Build will build a parser operator.
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/operator/helper/scope_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

// ScopeNameParser is a helper that parses severity onto an entry.
type ScopeNameParser struct {
ParseFrom entry.Field `mapstructure:"parse_from,omitempty" json:"parse_from,omitempty" yaml:"parse_from,omitempty"`
ParseFrom entry.Field `mapstructure:"parse_from,omitempty"`
}

// NewScopeNameParser creates a new scope parser with default values
Expand Down
6 changes: 3 additions & 3 deletions pkg/stanza/operator/helper/severity_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ func NewSeverityConfig() SeverityConfig {

// SeverityConfig allows users to specify how to parse a severity from a field.
type SeverityConfig struct {
ParseFrom *entry.Field `mapstructure:"parse_from,omitempty" json:"parse_from,omitempty" yaml:"parse_from,omitempty"`
Preset string `mapstructure:"preset,omitempty" json:"preset,omitempty" yaml:"preset,omitempty"`
Mapping map[interface{}]interface{} `mapstructure:"mapping,omitempty" json:"mapping,omitempty" yaml:"mapping,omitempty"`
ParseFrom *entry.Field `mapstructure:"parse_from,omitempty"`
Preset string `mapstructure:"preset,omitempty"`
Mapping map[interface{}]interface{} `mapstructure:"mapping,omitempty"`
}

// Build builds a SeverityParser from a SeverityConfig
Expand Down
8 changes: 4 additions & 4 deletions pkg/stanza/operator/helper/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func NewTimeParser() TimeParser {

// TimeParser is a helper that parses time onto an entry.
type TimeParser struct {
ParseFrom *entry.Field `mapstructure:"parse_from" json:"parse_from" yaml:"parse_from"`
Layout string `mapstructure:"layout" json:"layout" yaml:"layout"`
LayoutType string `mapstructure:"layout_type" json:"layout_type" yaml:"layout_type"`
Location string `mapstructure:"location" json:"location" yaml:"location"`
ParseFrom *entry.Field `mapstructure:"parse_from"`
Layout string `mapstructure:"layout"`
LayoutType string `mapstructure:"layout_type"`
Location string `mapstructure:"location"`

location *time.Location
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/stanza/operator/helper/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ func NewTraceParser() TraceParser {

// TraceParser is a helper that parses trace spans (and flags) onto an entry.
type TraceParser struct {
TraceID *TraceIDConfig `mapstructure:"trace_id,omitempty" json:"trace_id,omitempty" yaml:"trace_id,omitempty"`
SpanID *SpanIDConfig `mapstructure:"span_id,omitempty" json:"span_id,omitempty" yaml:"span_id,omitempty"`
TraceFlags *TraceFlagsConfig `mapstructure:"trace_flags,omitempty" json:"trace_flags,omitempty" yaml:"trace_flags,omitempty"`
TraceID *TraceIDConfig `mapstructure:"trace_id,omitempty"`
SpanID *SpanIDConfig `mapstructure:"span_id,omitempty"`
TraceFlags *TraceFlagsConfig `mapstructure:"trace_flags,omitempty"`
}

type TraceIDConfig struct {
ParseFrom *entry.Field `mapstructure:"parse_from,omitempty" json:"parse_from,omitempty" yaml:"parse_from,omitempty"`
ParseFrom *entry.Field `mapstructure:"parse_from,omitempty"`
}

type SpanIDConfig struct {
ParseFrom *entry.Field `mapstructure:"parse_from,omitempty" json:"parse_from,omitempty" yaml:"parse_from,omitempty"`
ParseFrom *entry.Field `mapstructure:"parse_from,omitempty"`
}

type TraceFlagsConfig struct {
ParseFrom *entry.Field `mapstructure:"parse_from,omitempty" json:"parse_from,omitempty" yaml:"parse_from,omitempty"`
ParseFrom *entry.Field `mapstructure:"parse_from,omitempty"`
}

// Validate validates a TraceParser, and reconfigures it if necessary
Expand Down
6 changes: 3 additions & 3 deletions pkg/stanza/operator/helper/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func NewTransformerConfig(operatorID, operatorType string) TransformerConfig {

// TransformerConfig provides a basic implementation of a transformer config.
type TransformerConfig struct {
WriterConfig `mapstructure:",squash" yaml:",inline"`
OnError string `mapstructure:"on_error" json:"on_error" yaml:"on_error"`
IfExpr string `mapstructure:"if" json:"if" yaml:"if"`
WriterConfig `mapstructure:",squash"`
OnError string `mapstructure:"on_error"`
IfExpr string `mapstructure:"if"`
}

// Build will build a transformer operator.
Expand Down
4 changes: 2 additions & 2 deletions pkg/stanza/operator/input/file/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func NewConfigWithID(operatorID string) *Config {

// Config is the configuration of a file input operator
type Config struct {
helper.InputConfig `mapstructure:",squash" yaml:",inline"`
fileconsumer.Config `mapstructure:",squash" yaml:",inline"`
helper.InputConfig `mapstructure:",squash"`
fileconsumer.Config `mapstructure:",squash"`
}

// Build will build a file input operator from the supplied configuration
Expand Down
8 changes: 4 additions & 4 deletions pkg/stanza/operator/input/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func NewConfig(operatorID string) *Config {

// Config is the configuration of a generate input operator.
type Config struct {
helper.InputConfig `yaml:",inline"`
Entry entry.Entry `json:"entry" yaml:"entry"`
Count int `json:"count,omitempty" yaml:"count,omitempty"`
Static bool `json:"static" yaml:"static,omitempty"`
helper.InputConfig `mapstructure:",squash"`
Entry entry.Entry `mapstructure:"entry"`
Count int `mapstructure:"count"`
Static bool `mapstructure:"static"`
}

// Build will build a generate input operator.
Expand Down
12 changes: 6 additions & 6 deletions pkg/stanza/operator/input/journald/journald.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func NewConfigWithID(operatorID string) *Config {

// Config is the configuration of a journald input operator
type Config struct {
helper.InputConfig `mapstructure:",squash" yaml:",inline"`
helper.InputConfig `mapstructure:",squash"`

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"`
Units []string `mapstructure:"units,omitempty" json:"units,omitempty" yaml:"units,omitempty"`
Priority string `mapstructure:"priority,omitempty" json:"priority,omitempty" yaml:"priority,omitempty"`
Directory *string `mapstructure:"directory,omitempty"`
Files []string `mapstructure:"files,omitempty"`
StartAt string `mapstructure:"start_at,omitempty"`
Units []string `mapstructure:"units,omitempty"`
Priority string `mapstructure:"priority,omitempty"`
}

// Build will build a journald input operator from the supplied configuration
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/operator/input/stdin/stdin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewConfig(operatorID string) *Config {

// Config is the configuration of a stdin input operator.
type Config struct {
helper.InputConfig `yaml:",inline"`
helper.InputConfig `mapstructure:",squash"`
}

// Build will build a stdin input operator.
Expand Down
8 changes: 4 additions & 4 deletions pkg/stanza/operator/input/syslog/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func NewConfigWithID(operatorID string) *Config {
}

type Config struct {
helper.InputConfig `mapstructure:",squash" yaml:",inline"`
syslog.BaseConfig `mapstructure:",squash" yaml:",inline"`
TCP *tcp.BaseConfig `mapstructure:"tcp" json:"tcp" yaml:"tcp"`
UDP *udp.BaseConfig `mapstructure:"udp" json:"udp" yaml:"udp"`
helper.InputConfig `mapstructure:",squash"`
syslog.BaseConfig `mapstructure:",squash"`
TCP *tcp.BaseConfig `mapstructure:"tcp"`
UDP *udp.BaseConfig `mapstructure:"udp"`
}

func (c Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) {
Expand Down
Loading

0 comments on commit f64d7ab

Please sign in to comment.