From 9589ec96e3ab2f23fe6089fbb309092ebfd15e83 Mon Sep 17 00:00:00 2001 From: Ankit Patel <8731662+ankitpatel96@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:05:23 -0400 Subject: [PATCH] rename operator to transformer --- .../internal/changelist/changelist.go | 22 ++++----- .../internal/translation/revision_v1.go | 27 +++++------ .../internal/translation/revision_v1_test.go | 48 +++++++++---------- 3 files changed, 48 insertions(+), 49 deletions(-) diff --git a/processor/schemaprocessor/internal/changelist/changelist.go b/processor/schemaprocessor/internal/changelist/changelist.go index d1fbb42ecdc1..2ed253989340 100644 --- a/processor/schemaprocessor/internal/changelist/changelist.go +++ b/processor/schemaprocessor/internal/changelist/changelist.go @@ -12,7 +12,7 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/migrate" - "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/operator" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/transformer" ) // ChangeList represents a list of changes within a section of the schema processor. It can take in a list of different migrators for a specific section and will apply them in order, based on whether Apply or Rollback is called @@ -29,42 +29,42 @@ func (c ChangeList) Do(ss migrate.StateSelector, signal any) error { } else { migrator = c.Migrators[len(c.Migrators)-1-i] } - // switch between operator types - what do the operators act on? + // switch between transformer types - what do the transformers act on? switch thisMigrator := migrator.(type) { // this one acts on both spans and span events! - case operator.Operator[ptrace.Span]: + case transformer.Transformer[ptrace.Span]: if span, ok := signal.(ptrace.Span); ok { if err := thisMigrator.Do(ss, span); err != nil { return err } } else { - return fmt.Errorf("SpanOperator %T can't act on %T", thisMigrator, signal) + return fmt.Errorf("span Transformer %T can't act on %T", thisMigrator, signal) } - case operator.Operator[pmetric.Metric]: + case transformer.Transformer[pmetric.Metric]: if metric, ok := signal.(pmetric.Metric); ok { if err := thisMigrator.Do(ss, metric); err != nil { return err } } else { - return fmt.Errorf("MetricOperator %T can't act on %T", thisMigrator, signal) + return fmt.Errorf("metric Transformer %T can't act on %T", thisMigrator, signal) } - case operator.Operator[plog.LogRecord]: + case transformer.Transformer[plog.LogRecord]: if log, ok := signal.(plog.LogRecord); ok { if err := thisMigrator.Do(ss, log); err != nil { return err } } else { - return fmt.Errorf("LogOperator %T can't act on %T", thisMigrator, signal) + return fmt.Errorf("log Transformer %T can't act on %T", thisMigrator, signal) } - case operator.Operator[pcommon.Resource]: + case transformer.Transformer[pcommon.Resource]: if resource, ok := signal.(pcommon.Resource); ok { if err := thisMigrator.Do(ss, resource); err != nil { return err } } else { - return fmt.Errorf("ResourceOperator %T can't act on %T", thisMigrator, signal) + return fmt.Errorf("resource Transformer %T can't act on %T", thisMigrator, signal) } - case operator.AllOperator: + case transformer.AllAttributes: if err := thisMigrator.Do(ss, signal); err != nil { return err } diff --git a/processor/schemaprocessor/internal/translation/revision_v1.go b/processor/schemaprocessor/internal/translation/revision_v1.go index f4f4c294fb62..d3aa449cb63e 100644 --- a/processor/schemaprocessor/internal/translation/revision_v1.go +++ b/processor/schemaprocessor/internal/translation/revision_v1.go @@ -8,7 +8,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/changelist" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/migrate" - "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/operator" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/transformer" ) // RevisionV1 represents all changes that are to be @@ -59,9 +59,8 @@ func newAllChangeList(all ast.Attributes) *changelist.ChangeList { for _, at := range all.Changes { if renamed := at.RenameAttributes; renamed != nil { attributeChangeSet := migrate.NewAttributeChangeSet(renamed.AttributeMap) - - allOperator := operator.NewAllOperator(attributeChangeSet) - values = append(values, allOperator) + allTransformer := transformer.NewAllAttributesTransformer(attributeChangeSet) + values = append(values, allTransformer) } } return &changelist.ChangeList{Migrators: values} @@ -72,8 +71,8 @@ func newResourceChangeList(resource ast.Attributes) *changelist.ChangeList { for _, at := range resource.Changes { if renamed := at.RenameAttributes; renamed != nil { attributeChangeSet := migrate.NewAttributeChangeSet(renamed.AttributeMap) - resourceOperator := operator.ResourceAttributeOperator{AttributeChange: attributeChangeSet} - values = append(values, resourceOperator) + resourceTransformer := transformer.ResourceAttributes{AttributeChange: attributeChangeSet} + values = append(values, resourceTransformer) } } return &changelist.ChangeList{Migrators: values} @@ -83,8 +82,8 @@ func newSpanChangeList(spans ast.Spans) *changelist.ChangeList { values := make([]migrate.Migrator, 0) for _, at := range spans.Changes { if renamed := at.RenameAttributes; renamed != nil { - conditionalAttributeChangeSet := operator.SpanConditionalAttributeOperator{Migrator: migrate.NewConditionalAttributeSet(renamed.AttributeMap, renamed.ApplyToSpans...)} - values = append(values, conditionalAttributeChangeSet) + conditionalAttributesChangeSet := transformer.SpanConditionalAttributes{Migrator: migrate.NewConditionalAttributeSet(renamed.AttributeMap, renamed.ApplyToSpans...)} + values = append(values, conditionalAttributesChangeSet) } } return &changelist.ChangeList{Migrators: values} @@ -95,12 +94,12 @@ func newMetricChangeList(metrics ast.Metrics) *changelist.ChangeList { values := make([]migrate.Migrator, 0) for _, at := range metrics.Changes { if renameAttributes := at.RenameAttributes; renameAttributes != nil { - attributeChangeSet := operator.MetricDataPointAttributeOperator{ + attributeChangeSet := transformer.MetricDataPointAttributes{ ConditionalAttributeChange: migrate.NewConditionalAttributeSet(renameAttributes.AttributeMap, renameAttributes.ApplyToMetrics...), } values = append(values, attributeChangeSet) } else if renamedMetrics := at.RenameMetrics; renamedMetrics != nil { - signalNameChange := operator.MetricSignalNameChange{SignalNameChange: migrate.NewSignalNameChange(renamedMetrics)} + signalNameChange := transformer.MetricSignalNameChange{SignalNameChange: migrate.NewSignalNameChange(renamedMetrics)} values = append(values, signalNameChange) } } @@ -112,7 +111,7 @@ func newSpanEventChangeList(spanEvents ast.SpanEvents) *changelist.ChangeList { for _, at := range spanEvents.Changes { if renamedEvent := at.RenameEvents; renamedEvent != nil { signalNameChange := migrate.NewSignalNameChange(renamedEvent.EventNameMap) - spanEventSignalNameChange := operator.SpanEventSignalNameChange{SignalNameChange: signalNameChange} + spanEventSignalNameChange := transformer.SpanEventSignalNameChange{SignalNameChange: signalNameChange} values = append(values, spanEventSignalNameChange) } else if renamedAttribute := at.RenameAttributes; renamedAttribute != nil { acceptableSpanNames := make([]string, 0) @@ -128,7 +127,7 @@ func newSpanEventChangeList(spanEvents ast.SpanEvents) *changelist.ChangeList { "span.name": acceptableSpanNames, "event.name": acceptableEventNames, }) - spanEventAttributeChangeSet := operator.SpanEventConditionalAttributeOperator{MultiConditionalAttributeSet: multiConditionalAttributeSet} + spanEventAttributeChangeSet := transformer.SpanEventConditionalAttributes{MultiConditionalAttributeSet: multiConditionalAttributeSet} values = append(values, spanEventAttributeChangeSet) } else { panic("spanEvents change must have either RenameEvents or RenameAttributes") @@ -142,8 +141,8 @@ func newLogsChangelist(logs ast.Logs) *changelist.ChangeList { for _, at := range logs.Changes { if renamed := at.RenameAttributes; renamed != nil { attributeChangeSet := migrate.NewAttributeChangeSet(renamed.AttributeMap) - logOperator := operator.LogAttributeOperator{AttributeChange: attributeChangeSet} - values = append(values, logOperator) + logTransformer := transformer.LogAttributes{AttributeChange: attributeChangeSet} + values = append(values, logTransformer) } } return &changelist.ChangeList{Migrators: values} diff --git a/processor/schemaprocessor/internal/translation/revision_v1_test.go b/processor/schemaprocessor/internal/translation/revision_v1_test.go index dffdf84bdef0..38de041ec46b 100644 --- a/processor/schemaprocessor/internal/translation/revision_v1_test.go +++ b/processor/schemaprocessor/internal/translation/revision_v1_test.go @@ -11,7 +11,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/changelist" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/migrate" - "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/operator" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/transformer" ) func TestNewRevisionV1(t *testing.T) { @@ -149,57 +149,57 @@ func TestNewRevisionV1(t *testing.T) { expect: &RevisionV1{ ver: &Version{1, 0, 0}, all: &changelist.ChangeList{Migrators: []migrate.Migrator{ - operator.AllOperator{ - // initialize one of each operator with the attribute set - MetricOperator: operator.MetricAttributeOperator{ + transformer.AllAttributes{ + // initialize one of each transformer with the attribute set + MetricAttributes: transformer.MetricAttributes{ AttributeChange: migrate.NewAttributeChangeSet(map[string]string{ "state": "status", }), }, - LogOperator: operator.LogAttributeOperator{ + LogAttributes: transformer.LogAttributes{ AttributeChange: migrate.NewAttributeChangeSet(map[string]string{ "state": "status", }), }, - SpanOperator: operator.SpanAttributeOperator{ + SpanAttributes: transformer.SpanAttributes{ AttributeChange: migrate.NewAttributeChangeSet(map[string]string{ "state": "status", }), }, - SpanEventOperator: operator.SpanEventAttributeOperator{ + SpanEventAttributes: transformer.SpanEventAttributes{ AttributeChange: migrate.NewAttributeChangeSet(map[string]string{ "state": "status", }), }, - ResourceMigrator: operator.ResourceAttributeOperator{ + ResourceAttributes: transformer.ResourceAttributes{ AttributeChange: migrate.NewAttributeChangeSet(map[string]string{ "state": "status", }), }, }, - operator.AllOperator{ - // initialize one of each operator with the attribute set - MetricOperator: operator.MetricAttributeOperator{ + transformer.AllAttributes{ + // initialize one of each transformer with the attribute set + MetricAttributes: transformer.MetricAttributes{ AttributeChange: migrate.NewAttributeChangeSet(map[string]string{ "status": "state", }), }, - LogOperator: operator.LogAttributeOperator{ + LogAttributes: transformer.LogAttributes{ AttributeChange: migrate.NewAttributeChangeSet(map[string]string{ "status": "state", }), }, - SpanOperator: operator.SpanAttributeOperator{ + SpanAttributes: transformer.SpanAttributes{ AttributeChange: migrate.NewAttributeChangeSet(map[string]string{ "status": "state", }), }, - SpanEventOperator: operator.SpanEventAttributeOperator{ + SpanEventAttributes: transformer.SpanEventAttributes{ AttributeChange: migrate.NewAttributeChangeSet(map[string]string{ "status": "state", }), }, - ResourceMigrator: operator.ResourceAttributeOperator{ + ResourceAttributes: transformer.ResourceAttributes{ AttributeChange: migrate.NewAttributeChangeSet(map[string]string{ "status": "state", }), @@ -208,26 +208,26 @@ func TestNewRevisionV1(t *testing.T) { }, }, resources: &changelist.ChangeList{Migrators: []migrate.Migrator{ - operator.ResourceAttributeOperator{AttributeChange: migrate.NewAttributeChangeSet( + transformer.ResourceAttributes{AttributeChange: migrate.NewAttributeChangeSet( map[string]string{"service_name": "service.name"}, )}, }}, spans: &changelist.ChangeList{Migrators: []migrate.Migrator{ - operator.SpanConditionalAttributeOperator{Migrator: migrate.NewConditionalAttributeSet( + transformer.SpanConditionalAttributes{Migrator: migrate.NewConditionalAttributeSet( map[string]string{"service_version": "service.version"}, "application start", )}, - operator.SpanConditionalAttributeOperator{Migrator: migrate.NewConditionalAttributeSet[string]( + transformer.SpanConditionalAttributes{Migrator: migrate.NewConditionalAttributeSet[string]( map[string]string{"deployment.environment": "service.deployment.environment"}, )}, }}, spanEvents: &changelist.ChangeList{Migrators: []migrate.Migrator{ - operator.SpanEventSignalNameChange{ + transformer.SpanEventSignalNameChange{ SignalNameChange: migrate.NewSignalNameChange(map[string]string{ "started": "application started", }), }, - operator.SpanEventConditionalAttributeOperator{ + transformer.SpanEventConditionalAttributes{ MultiConditionalAttributeSet: migrate.NewMultiConditionalAttributeSet( map[string]string{"service.app.name": "service.name"}, map[string][]string{ @@ -238,16 +238,16 @@ func TestNewRevisionV1(t *testing.T) { }, }}, metrics: &changelist.ChangeList{Migrators: []migrate.Migrator{ - operator.MetricSignalNameChange{SignalNameChange: migrate.NewSignalNameChange(map[string]string{ + transformer.MetricSignalNameChange{SignalNameChange: migrate.NewSignalNameChange(map[string]string{ "service.computed.uptime": "service.uptime", })}, - operator.MetricDataPointAttributeOperator{ConditionalAttributeChange: migrate.NewConditionalAttributeSet( + transformer.MetricDataPointAttributes{ConditionalAttributeChange: migrate.NewConditionalAttributeSet( map[string]string{"runtime": "service.language"}, "service.runtime", )}, }}, logs: &changelist.ChangeList{Migrators: []migrate.Migrator{ - operator.LogAttributeOperator{AttributeChange: migrate.NewAttributeChangeSet(map[string]string{ + transformer.LogAttributes{AttributeChange: migrate.NewAttributeChangeSet(map[string]string{ "ERROR": "error", }), }, @@ -263,7 +263,7 @@ func TestNewRevisionV1(t *testing.T) { rev := NewRevision(tc.inVersion, tc.inDefinition) // use go-cmp to compare tc.expect and rev and fail the test if there's a difference - if diff := cmp.Diff(tc.expect, rev, cmp.AllowUnexported(RevisionV1{}, migrate.AttributeChangeSet{}, migrate.ConditionalAttributeSet{}, migrate.SignalNameChange{}, operator.SpanEventConditionalAttributeOperator{}, migrate.MultiConditionalAttributeSet{})); diff != "" { + if diff := cmp.Diff(tc.expect, rev, cmp.AllowUnexported(RevisionV1{}, migrate.AttributeChangeSet{}, migrate.ConditionalAttributeSet{}, migrate.SignalNameChange{}, transformer.SpanEventConditionalAttributes{}, migrate.MultiConditionalAttributeSet{})); diff != "" { t.Errorf("NewRevisionV1() mismatch (-want +got):\n%s", diff) } })