Skip to content

Commit

Permalink
rename operator to transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitpatel96 committed Oct 16, 2024
1 parent 2ce01f7 commit 9589ec9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 49 deletions.
22 changes: 11 additions & 11 deletions processor/schemaprocessor/internal/changelist/changelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
27 changes: 13 additions & 14 deletions processor/schemaprocessor/internal/translation/revision_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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)
}
}
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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}
Expand Down
48 changes: 24 additions & 24 deletions processor/schemaprocessor/internal/translation/revision_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
}),
Expand All @@ -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{
Expand All @@ -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",
}),
},
Expand All @@ -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)
}
})
Expand Down

0 comments on commit 9589ec9

Please sign in to comment.