-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 remove operator files (#32067)
Contributes to #32058
- Loading branch information
1 parent
de3e1e7
commit 261b13a
Showing
3 changed files
with
42 additions
and
31 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,42 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package remove // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/transformer/remove" | ||
|
||
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 deletes a field | ||
type Transformer struct { | ||
helper.TransformerOperator | ||
Field rootableField | ||
} | ||
|
||
// Process will process an entry with a remove transformation. | ||
func (t *Transformer) Process(ctx context.Context, entry *entry.Entry) error { | ||
return t.ProcessWith(ctx, entry, t.Transform) | ||
} | ||
|
||
// Transform will apply the remove operation to an entry | ||
func (t *Transformer) Transform(entry *entry.Entry) error { | ||
if t.Field.allAttributes { | ||
entry.Attributes = nil | ||
return nil | ||
} | ||
|
||
if t.Field.allResource { | ||
entry.Resource = nil | ||
return nil | ||
} | ||
|
||
_, exist := entry.Delete(t.Field.Field) | ||
if !exist { | ||
return fmt.Errorf("remove: field does not exist: %s", t.Field.Field.String()) | ||
} | ||
return nil | ||
} |
File renamed without changes.