Skip to content

Commit

Permalink
Move attributes action out of processorhelper to coreinternal (#4857)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Aug 24, 2021
1 parent d46048a commit f2f4ad1
Show file tree
Hide file tree
Showing 19 changed files with 147 additions and 145 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/extension/oidcauthextension v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/metrics v0.30.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/processor/cumulativetodeltaprocessor v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatorateprocessor v0.0.0-00010101000000-000000000000
Expand Down
10 changes: 5 additions & 5 deletions internal/components/processors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/processor/memorylimiter"
"go.opentelemetry.io/collector/processor/processorhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/attraction"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourceprocessor"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/spanprocessor"
Expand All @@ -49,8 +49,8 @@ func TestDefaultProcessors(t *testing.T) {
processor: "attributes",
getConfigFn: func() config.Processor {
cfg := procFactories["attributes"].CreateDefaultConfig().(*attributesprocessor.Config)
cfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
cfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
}
return cfg
},
Expand All @@ -77,8 +77,8 @@ func TestDefaultProcessors(t *testing.T) {
processor: "resource",
getConfigFn: func() config.Processor {
cfg := procFactories["resource"].CreateDefaultConfig().(*resourceprocessor.Config)
cfg.AttributesActions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
cfg.AttributesActions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
}
return cfg
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package processorhelper
package attraction

import (
"fmt"
"regexp"
"strings"

"go.opentelemetry.io/collector/internal/processor/filterhelper"
"go.opentelemetry.io/collector/model/pdata"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterhelper"
)

// Settings specifies the processor settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package processorhelper
package attraction

import (
"crypto/sha1" // #nosec
Expand All @@ -25,7 +25,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/model/pdata"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package processorhelper
package attraction

import (
// #nosec
Expand Down
6 changes: 3 additions & 3 deletions processor/attributesprocessor/attributes_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ import (
"context"

"go.opentelemetry.io/collector/model/pdata"
"go.opentelemetry.io/collector/processor/processorhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/attraction"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterlog"
)

type logAttributesProcessor struct {
attrProc *processorhelper.AttrProc
attrProc *attraction.AttrProc
include filterlog.Matcher
exclude filterlog.Matcher
}

// newLogAttributesProcessor returns a processor that modifies attributes of a
// log record. To construct the attributes processors, the use of the factory
// methods are required in order to validate the inputs.
func newLogAttributesProcessor(attrProc *processorhelper.AttrProc, include, exclude filterlog.Matcher) *logAttributesProcessor {
func newLogAttributesProcessor(attrProc *attraction.AttrProc, include, exclude filterlog.Matcher) *logAttributesProcessor {
return &logAttributesProcessor{
attrProc: attrProc,
include: include,
Expand Down
35 changes: 17 additions & 18 deletions processor/attributesprocessor/attributes_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/model/pdata"
"go.opentelemetry.io/collector/processor/processorhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/attraction"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterconfig"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterset"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata"
Expand Down Expand Up @@ -101,9 +100,9 @@ func TestLogProcessor_NilEmptyData(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Settings.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
{Key: "attribute1", Action: processorhelper.DELETE},
oCfg.Settings.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
{Key: "attribute1", Action: attraction.DELETE},
}

tp, err := factory.CreateLogsProcessor(
Expand Down Expand Up @@ -157,8 +156,8 @@ func TestAttributes_FilterLogs(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
}
oCfg.Include = &filterconfig.MatchProperties{
LogNames: []string{"^[^i].*"},
Expand Down Expand Up @@ -222,8 +221,8 @@ func TestAttributes_FilterLogsByNameStrict(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
}
oCfg.Include = &filterconfig.MatchProperties{
LogNames: []string{"apply", "dont_apply"},
Expand Down Expand Up @@ -285,8 +284,8 @@ func TestAttributes_FilterLogsByNameRegexp(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
}
oCfg.Include = &filterconfig.MatchProperties{
LogNames: []string{"^apply.*"},
Expand Down Expand Up @@ -348,11 +347,11 @@ func TestLogAttributes_Hash(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "user.email", Action: processorhelper.HASH},
{Key: "user.id", Action: processorhelper.HASH},
{Key: "user.balance", Action: processorhelper.HASH},
{Key: "user.authenticated", Action: processorhelper.HASH},
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "user.email", Action: attraction.HASH},
{Key: "user.id", Action: attraction.HASH},
{Key: "user.balance", Action: attraction.HASH},
{Key: "user.authenticated", Action: attraction.HASH},
}

tp, err := factory.CreateLogsProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), cfg, consumertest.NewNop())
Expand Down Expand Up @@ -393,8 +392,8 @@ func BenchmarkAttributes_FilterLogsByName(b *testing.B) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
}
oCfg.Include = &filterconfig.MatchProperties{
LogNames: []string{"^apply.*"},
Expand Down
6 changes: 3 additions & 3 deletions processor/attributesprocessor/attributes_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ import (
"context"

"go.opentelemetry.io/collector/model/pdata"
"go.opentelemetry.io/collector/processor/processorhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/attraction"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterspan"
)

type spanAttributesProcessor struct {
attrProc *processorhelper.AttrProc
attrProc *attraction.AttrProc
include filterspan.Matcher
exclude filterspan.Matcher
}

// newTracesProcessor returns a processor that modifies attributes of a span.
// To construct the attributes processors, the use of the factory methods are required
// in order to validate the inputs.
func newSpanAttributesProcessor(attrProc *processorhelper.AttrProc, include, exclude filterspan.Matcher) *spanAttributesProcessor {
func newSpanAttributesProcessor(attrProc *attraction.AttrProc, include, exclude filterspan.Matcher) *spanAttributesProcessor {
return &spanAttributesProcessor{
attrProc: attrProc,
include: include,
Expand Down
35 changes: 17 additions & 18 deletions processor/attributesprocessor/attributes_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/model/pdata"
"go.opentelemetry.io/collector/processor/processorhelper"
conventions "go.opentelemetry.io/collector/translator/conventions/v1.5.0"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/attraction"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterconfig"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterset"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata"
Expand Down Expand Up @@ -112,9 +111,9 @@ func TestSpanProcessor_NilEmptyData(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Settings.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
{Key: "attribute1", Action: processorhelper.DELETE},
oCfg.Settings.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
{Key: "attribute1", Action: attraction.DELETE},
}

tp, err := factory.CreateTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), oCfg, consumertest.NewNop())
Expand Down Expand Up @@ -171,8 +170,8 @@ func TestAttributes_FilterSpans(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
}
oCfg.Include = &filterconfig.MatchProperties{
Services: []string{"svcA", "svcB.*"},
Expand Down Expand Up @@ -241,8 +240,8 @@ func TestAttributes_FilterSpansByNameStrict(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
}
oCfg.Include = &filterconfig.MatchProperties{
SpanNames: []string{"apply", "dont_apply"},
Expand Down Expand Up @@ -309,8 +308,8 @@ func TestAttributes_FilterSpansByNameRegexp(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
}
oCfg.Include = &filterconfig.MatchProperties{
SpanNames: []string{"^apply.*"},
Expand Down Expand Up @@ -372,11 +371,11 @@ func TestAttributes_Hash(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "user.email", Action: processorhelper.HASH},
{Key: "user.id", Action: processorhelper.HASH},
{Key: "user.balance", Action: processorhelper.HASH},
{Key: "user.authenticated", Action: processorhelper.HASH},
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "user.email", Action: attraction.HASH},
{Key: "user.id", Action: attraction.HASH},
{Key: "user.balance", Action: attraction.HASH},
{Key: "user.authenticated", Action: attraction.HASH},
}

tp, err := factory.CreateTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), cfg, consumertest.NewNop())
Expand Down Expand Up @@ -417,8 +416,8 @@ func BenchmarkAttributes_FilterSpansByName(b *testing.B) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
}
oCfg.Include = &filterconfig.MatchProperties{
SpanNames: []string{"^apply.*"},
Expand Down
4 changes: 2 additions & 2 deletions processor/attributesprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package attributesprocessor

import (
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/processor/processorhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/attraction"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterconfig"
)

Expand All @@ -36,7 +36,7 @@ type Config struct {
// Specifies the list of attributes to act on.
// The set of actions are {INSERT, UPDATE, UPSERT, DELETE, HASH, EXTRACT}.
// This is a required field.
processorhelper.Settings `mapstructure:",squash"`
attraction.Settings `mapstructure:",squash"`
}

var _ config.Processor = (*Config)(nil)
Expand Down
Loading

0 comments on commit f2f4ad1

Please sign in to comment.