Skip to content

Commit

Permalink
[chore][pkg/stanza] Cleanup move operator files (#32064)
Browse files Browse the repository at this point in the history
Contributes to #32058
  • Loading branch information
djaglowski authored Apr 3, 2024
1 parent a128aed commit e45bde5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package move // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/transformer/move"

import (
"context"
"fmt"

"go.uber.org/zap"
Expand Down Expand Up @@ -56,24 +55,3 @@ func (c Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) {
To: c.To,
}, nil
}

// Transformer is an operator that moves a field's value to a new field
type Transformer struct {
helper.TransformerOperator
From entry.Field
To entry.Field
}

// Process will process an entry with a move transformation.
func (p *Transformer) Process(ctx context.Context, entry *entry.Entry) error {
return p.ProcessWith(ctx, entry, p.Transform)
}

// Transform will apply the move operation to an entry
func (p *Transformer) Transform(e *entry.Entry) error {
val, exist := p.From.Delete(e)
if !exist {
return fmt.Errorf("move: field does not exist: %s", p.From.String())
}
return p.To.Set(e, val)
}
33 changes: 33 additions & 0 deletions pkg/stanza/operator/transformer/move/transformer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package move // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/transformer/move"

import (
"context"
"fmt"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
)

// Transformer is an operator that moves a field's value to a new field
type Transformer struct {
helper.TransformerOperator
From entry.Field
To entry.Field
}

// Process will process an entry with a move transformation.
func (t *Transformer) Process(ctx context.Context, entry *entry.Entry) error {
return t.ProcessWith(ctx, entry, t.Transform)
}

// Transform will apply the move operation to an entry
func (t *Transformer) Transform(e *entry.Entry) error {
val, exist := t.From.Delete(e)
if !exist {
return fmt.Errorf("move: field does not exist: %s", t.From.String())
}
return t.To.Set(e, val)
}

0 comments on commit e45bde5

Please sign in to comment.