Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore][pkg/stanza] Cleanup move operator files #32064

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}