Skip to content

Commit

Permalink
Moved common processor files and updated refs (#1574)
Browse files Browse the repository at this point in the history
* Moved pkg files and updated refs

Signed-off-by: Joe Elliott <number101010@gmail.com>

* Added hash test

Signed-off-by: Joe Elliott <number101010@gmail.com>

* lint

Signed-off-by: Joe Elliott <number101010@gmail.com>

* Moved to processorhelper

Signed-off-by: Joe Elliott <number101010@gmail.com>
  • Loading branch information
joe-elliott committed Aug 19, 2020
1 parent 64befbc commit cadd498
Show file tree
Hide file tree
Showing 15 changed files with 214 additions and 112 deletions.
6 changes: 3 additions & 3 deletions processor/attributesprocessor/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ import (
"context"

"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/internal/processor/attraction"
"go.opentelemetry.io/collector/internal/processor/filterspan"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"
)

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

// newTraceProcessor 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 newAttributesProcessor(attrProc *attraction.AttrProc, include, exclude filterspan.Matcher) *attributesProcessor {
func newAttributesProcessor(attrProc *processorhelper.AttrProc, include, exclude filterspan.Matcher) *attributesProcessor {
return &attributesProcessor{
attrProc: attrProc,
include: include,
Expand Down
34 changes: 17 additions & 17 deletions processor/attributesprocessor/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/internal/data/testdata"
"go.opentelemetry.io/collector/internal/processor/attraction"
"go.opentelemetry.io/collector/internal/processor/filterset"
"go.opentelemetry.io/collector/internal/processor/filterspan"
"go.opentelemetry.io/collector/processor/processorhelper"
"go.opentelemetry.io/collector/translator/conventions"
)

Expand Down Expand Up @@ -138,9 +138,9 @@ func TestSpanProcessor_NilEmptyData(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Settings.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
{Key: "attribute1", Action: attraction.DELETE},
oCfg.Settings.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
{Key: "attribute1", Action: processorhelper.DELETE},
}

tp, err := factory.CreateTraceProcessor(
Expand Down Expand Up @@ -198,8 +198,8 @@ func TestAttributes_FilterSpans(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
}
oCfg.Include = &filterspan.MatchProperties{
Services: []string{"svcA", "svcB.*"},
Expand Down Expand Up @@ -268,8 +268,8 @@ func TestAttributes_FilterSpansByNameStrict(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
}
oCfg.Include = &filterspan.MatchProperties{
SpanNames: []string{"apply", "dont_apply"},
Expand Down Expand Up @@ -336,8 +336,8 @@ func TestAttributes_FilterSpansByNameRegexp(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
}
oCfg.Include = &filterspan.MatchProperties{
SpanNames: []string{"^apply.*"},
Expand Down Expand Up @@ -399,11 +399,11 @@ func TestAttributes_Hash(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
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},
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},
}

tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, exportertest.NewNopTraceExporter(), cfg)
Expand Down Expand Up @@ -444,8 +444,8 @@ func BenchmarkAttributes_FilterSpansByName(b *testing.B) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "attribute1", Action: attraction.INSERT, Value: 123},
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "attribute1", Action: processorhelper.INSERT, Value: 123},
}
oCfg.Include = &filterspan.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/configmodels"
"go.opentelemetry.io/collector/internal/processor/attraction"
"go.opentelemetry.io/collector/internal/processor/filterspan"
"go.opentelemetry.io/collector/processor/processorhelper"
)

// Config specifies the set of attributes to be inserted, updated, upserted and
Expand All @@ -35,5 +35,5 @@ 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.
attraction.Settings `mapstructure:",squash"`
processorhelper.Settings `mapstructure:",squash"`
}
96 changes: 48 additions & 48 deletions processor/attributesprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/config/configtest"
"go.opentelemetry.io/collector/internal/processor/attraction"
"go.opentelemetry.io/collector/internal/processor/filterset"
"go.opentelemetry.io/collector/internal/processor/filterspan"
"go.opentelemetry.io/collector/processor/processorhelper"
)

func TestLoadingConifg(t *testing.T) {
Expand All @@ -45,10 +45,10 @@ func TestLoadingConifg(t *testing.T) {
NameVal: "attributes/insert",
TypeVal: typeStr,
},
Settings: attraction.Settings{
Actions: []attraction.ActionKeyValue{
{Key: "attribute1", Value: 123, Action: attraction.INSERT},
{Key: "string key", FromAttribute: "anotherkey", Action: attraction.INSERT},
Settings: processorhelper.Settings{
Actions: []processorhelper.ActionKeyValue{
{Key: "attribute1", Value: 123, Action: processorhelper.INSERT},
{Key: "string key", FromAttribute: "anotherkey", Action: processorhelper.INSERT},
},
},
})
Expand All @@ -59,10 +59,10 @@ func TestLoadingConifg(t *testing.T) {
NameVal: "attributes/update",
TypeVal: typeStr,
},
Settings: attraction.Settings{
Actions: []attraction.ActionKeyValue{
{Key: "boo", FromAttribute: "foo", Action: attraction.UPDATE},
{Key: "db.secret", Value: "redacted", Action: attraction.UPDATE},
Settings: processorhelper.Settings{
Actions: []processorhelper.ActionKeyValue{
{Key: "boo", FromAttribute: "foo", Action: processorhelper.UPDATE},
{Key: "db.secret", Value: "redacted", Action: processorhelper.UPDATE},
},
},
})
Expand All @@ -73,10 +73,10 @@ func TestLoadingConifg(t *testing.T) {
NameVal: "attributes/upsert",
TypeVal: typeStr,
},
Settings: attraction.Settings{
Actions: []attraction.ActionKeyValue{
{Key: "region", Value: "planet-earth", Action: attraction.UPSERT},
{Key: "new_user_key", FromAttribute: "user_key", Action: attraction.UPSERT},
Settings: processorhelper.Settings{
Actions: []processorhelper.ActionKeyValue{
{Key: "region", Value: "planet-earth", Action: processorhelper.UPSERT},
{Key: "new_user_key", FromAttribute: "user_key", Action: processorhelper.UPSERT},
},
},
})
Expand All @@ -87,10 +87,10 @@ func TestLoadingConifg(t *testing.T) {
NameVal: "attributes/delete",
TypeVal: typeStr,
},
Settings: attraction.Settings{
Actions: []attraction.ActionKeyValue{
{Key: "credit_card", Action: attraction.DELETE},
{Key: "duplicate_key", Action: attraction.DELETE},
Settings: processorhelper.Settings{
Actions: []processorhelper.ActionKeyValue{
{Key: "credit_card", Action: processorhelper.DELETE},
{Key: "duplicate_key", Action: processorhelper.DELETE},
},
},
})
Expand All @@ -101,9 +101,9 @@ func TestLoadingConifg(t *testing.T) {
NameVal: "attributes/hash",
TypeVal: typeStr,
},
Settings: attraction.Settings{
Actions: []attraction.ActionKeyValue{
{Key: "user.email", Action: attraction.HASH},
Settings: processorhelper.Settings{
Actions: []processorhelper.ActionKeyValue{
{Key: "user.email", Action: processorhelper.HASH},
},
},
})
Expand All @@ -124,10 +124,10 @@ func TestLoadingConifg(t *testing.T) {
},
},
},
Settings: attraction.Settings{
Actions: []attraction.ActionKeyValue{
{Key: "credit_card", Action: attraction.DELETE},
{Key: "duplicate_key", Action: attraction.DELETE},
Settings: processorhelper.Settings{
Actions: []processorhelper.ActionKeyValue{
{Key: "credit_card", Action: processorhelper.DELETE},
{Key: "duplicate_key", Action: processorhelper.DELETE},
},
},
})
Expand All @@ -144,10 +144,10 @@ func TestLoadingConifg(t *testing.T) {
Services: []string{"auth.*", "login.*"},
},
},
Settings: attraction.Settings{
Actions: []attraction.ActionKeyValue{
{Key: "credit_card", Action: attraction.DELETE},
{Key: "duplicate_key", Action: attraction.DELETE},
Settings: processorhelper.Settings{
Actions: []processorhelper.ActionKeyValue{
{Key: "credit_card", Action: processorhelper.DELETE},
{Key: "duplicate_key", Action: processorhelper.DELETE},
},
},
})
Expand All @@ -170,10 +170,10 @@ func TestLoadingConifg(t *testing.T) {
},
},
},
Settings: attraction.Settings{
Actions: []attraction.ActionKeyValue{
{Key: "credit_card", Action: attraction.DELETE},
{Key: "duplicate_key", Action: attraction.DELETE},
Settings: processorhelper.Settings{
Actions: []processorhelper.ActionKeyValue{
{Key: "credit_card", Action: processorhelper.DELETE},
{Key: "duplicate_key", Action: processorhelper.DELETE},
},
},
})
Expand All @@ -184,11 +184,11 @@ func TestLoadingConifg(t *testing.T) {
NameVal: "attributes/complex",
TypeVal: typeStr,
},
Settings: attraction.Settings{
Actions: []attraction.ActionKeyValue{
{Key: "operation", Value: "default", Action: attraction.INSERT},
{Key: "svc.operation", FromAttribute: "operation", Action: attraction.UPSERT},
{Key: "operation", Action: attraction.DELETE},
Settings: processorhelper.Settings{
Actions: []processorhelper.ActionKeyValue{
{Key: "operation", Value: "default", Action: processorhelper.INSERT},
{Key: "svc.operation", FromAttribute: "operation", Action: processorhelper.UPSERT},
{Key: "operation", Action: processorhelper.DELETE},
},
},
})
Expand All @@ -199,13 +199,13 @@ func TestLoadingConifg(t *testing.T) {
NameVal: "attributes/example",
TypeVal: typeStr,
},
Settings: attraction.Settings{
Actions: []attraction.ActionKeyValue{
{Key: "db.table", Action: attraction.DELETE},
{Key: "redacted_span", Value: true, Action: attraction.UPSERT},
{Key: "copy_key", FromAttribute: "key_original", Action: attraction.UPDATE},
{Key: "account_id", Value: 2245, Action: attraction.INSERT},
{Key: "account_password", Action: attraction.DELETE},
Settings: processorhelper.Settings{
Actions: []processorhelper.ActionKeyValue{
{Key: "db.table", Action: processorhelper.DELETE},
{Key: "redacted_span", Value: true, Action: processorhelper.UPSERT},
{Key: "copy_key", FromAttribute: "key_original", Action: processorhelper.UPDATE},
{Key: "account_id", Value: 2245, Action: processorhelper.INSERT},
{Key: "account_password", Action: processorhelper.DELETE},
},
},
})
Expand All @@ -226,10 +226,10 @@ func TestLoadingConifg(t *testing.T) {
SpanNames: []string{"login.*"},
},
},
Settings: attraction.Settings{
Actions: []attraction.ActionKeyValue{
{Key: "password", Action: attraction.UPDATE, Value: "obfuscated"},
{Key: "token", Action: attraction.DELETE},
Settings: processorhelper.Settings{
Actions: []processorhelper.ActionKeyValue{
{Key: "password", Action: processorhelper.UPDATE, Value: "obfuscated"},
{Key: "token", Action: processorhelper.DELETE},
},
},
})
Expand Down
3 changes: 1 addition & 2 deletions processor/attributesprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/internal/processor/attraction"
"go.opentelemetry.io/collector/internal/processor/filterspan"
"go.opentelemetry.io/collector/processor/processorhelper"
)
Expand Down Expand Up @@ -61,7 +60,7 @@ func createTraceProcessor(
if len(oCfg.Actions) == 0 {
return nil, fmt.Errorf("error creating \"attributes\" processor due to missing required field \"actions\" of processor %q", cfg.Name())
}
attrProc, err := attraction.NewAttrProc(&oCfg.Settings)
attrProc, err := processorhelper.NewAttrProc(&oCfg.Settings)
if err != nil {
return nil, fmt.Errorf("error creating \"attributes\" processor: %w of processor %q", err, cfg.Name())
}
Expand Down
14 changes: 7 additions & 7 deletions processor/attributesprocessor/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/internal/processor/attraction"
"go.opentelemetry.io/collector/processor/processorhelper"
)

func TestFactory_Type(t *testing.T) {
Expand Down Expand Up @@ -59,8 +59,8 @@ func TestFactoryCreateTraceProcessor_InvalidActions(t *testing.T) {
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
// Missing key
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "", Value: 123, Action: attraction.UPSERT},
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "", Value: 123, Action: processorhelper.UPSERT},
}
ap, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, exportertest.NewNopTraceExporter(), cfg)
assert.Error(t, err)
Expand All @@ -71,8 +71,8 @@ func TestFactoryCreateTraceProcessor(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
oCfg := cfg.(*Config)
oCfg.Actions = []attraction.ActionKeyValue{
{Key: "a key", Action: attraction.DELETE},
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "a key", Action: processorhelper.DELETE},
}

tp, err := factory.CreateTraceProcessor(
Expand All @@ -85,8 +85,8 @@ func TestFactoryCreateTraceProcessor(t *testing.T) {
assert.Nil(t, tp)
assert.Error(t, err)

oCfg.Actions = []attraction.ActionKeyValue{
{Action: attraction.DELETE},
oCfg.Actions = []processorhelper.ActionKeyValue{
{Action: processorhelper.DELETE},
}
tp, err = factory.CreateTraceProcessor(
context.Background(), component.ProcessorCreateParams{}, exportertest.NewNopTraceExporter(), cfg)
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 attraction
package processorhelper

import (
"fmt"
Expand Down
Loading

0 comments on commit cadd498

Please sign in to comment.