Skip to content

Commit

Permalink
perf: inline convertToken function
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzej-stencel committed Dec 16, 2024
1 parent f650804 commit de66483
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions pkg/stanza/operator/input/file/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,25 @@ func (i *Input) emitBatch(ctx context.Context, tokens []emit.Token) error {
func (i *Input) convertTokens(tokens []emit.Token) ([]*entry.Entry, error) {
entries := make([]*entry.Entry, 0, len(tokens))
var errs []error

for _, token := range tokens {
if len(token.Body) == 0 {
continue
}
entry, err := i.convertToken(token)

ent, err := i.NewEntry(i.toBody(token.Body))
if err != nil {
errs = append(errs, err)
errs = append(errs, fmt.Errorf("create entry: %w", err))
continue
}
entries = append(entries, entry)
}
return entries, errors.Join(errs...)
}

func (i *Input) convertToken(token emit.Token) (*entry.Entry, error) {
ent, err := i.NewEntry(i.toBody(token.Body))
if err != nil {
return nil, fmt.Errorf("create entry: %w", err)
}

for k, v := range token.Attributes {
if err := ent.Set(entry.NewAttributeField(k), v); err != nil {
i.Logger().Error("set attribute", zap.Error(err))
for k, v := range token.Attributes {
if err := ent.Set(entry.NewAttributeField(k), v); err != nil {
i.Logger().Error("set attribute", zap.Error(err))
}
}

entries = append(entries, ent)
}
return ent, nil
return entries, errors.Join(errs...)
}

0 comments on commit de66483

Please sign in to comment.