-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore][pkg/stanza] Cleanup move operator files (#32064)
Contributes to #32058
- Loading branch information
1 parent
a128aed
commit e45bde5
Showing
3 changed files
with
33 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
File renamed without changes.