Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pkg/ottl] remove support from accessing top-level objects #36872

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .chloggen/ottl-remove-top-level-paths.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/ottl

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: removed the ability to reference entire parent objects.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36872]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Statements like `set(cache["resource"], resource)` in non-resource contexts will no longer work.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
16 changes: 1 addition & 15 deletions pkg/ottl/contexts/internal/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var MetricSymbolTable = map[ottl.EnumSymbol]ottl.Enum{

func MetricPathGetSetter[K MetricContext](path ottl.Path[K]) (ottl.GetSetter[K], error) {
if path == nil {
return accessMetric[K](), nil
return nil, FormatDefaultErrorMessage("metric", "metric", "Metric", MetricRef)
}
switch path.Name() {
case "name":
Expand All @@ -51,20 +51,6 @@ func MetricPathGetSetter[K MetricContext](path ottl.Path[K]) (ottl.GetSetter[K],
}
}

func accessMetric[K MetricContext]() ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(_ context.Context, tCtx K) (any, error) {
return tCtx.GetMetric(), nil
},
Setter: func(_ context.Context, tCtx K, val any) error {
if newMetric, ok := val.(pmetric.Metric); ok {
newMetric.CopyTo(tCtx.GetMetric())
}
return nil
},
}
}

func accessName[K MetricContext]() ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(_ context.Context, tCtx K) (any, error) {
Expand Down
16 changes: 1 addition & 15 deletions pkg/ottl/contexts/internal/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ResourceContext interface {

func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter[K], error) {
if path == nil {
return accessResource[K](), nil
return nil, FormatDefaultErrorMessage("resource", "resource", "Resource", ResourceContextRef)
}
switch path.Name() {
case "attributes":
Expand All @@ -35,20 +35,6 @@ func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter
}
}

func accessResource[K ResourceContext]() ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(_ context.Context, tCtx K) (any, error) {
return tCtx.GetResource(), nil
},
Setter: func(_ context.Context, tCtx K, val any) error {
if newRes, ok := val.(pcommon.Resource); ok {
newRes.CopyTo(tCtx.GetResource())
}
return nil
},
}
}

func accessResourceAttributes[K ResourceContext]() ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(_ context.Context, tCtx K) (any, error) {
Expand Down
9 changes: 0 additions & 9 deletions pkg/ottl/contexts/internal/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ func TestResourcePathGetSetter(t *testing.T) {
newVal any
modified func(resource pcommon.Resource)
}{
{
name: "resource",
path: nil,
orig: refResource,
newVal: pcommon.NewResource(),
modified: func(resource pcommon.Resource) {
pcommon.NewResource().CopyTo(resource)
},
},
{
name: "resource schema_url",
path: &TestPath[*resourceContext]{
Expand Down
16 changes: 1 addition & 15 deletions pkg/ottl/contexts/internal/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type InstrumentationScopeContext interface {

func ScopePathGetSetter[K InstrumentationScopeContext](path ottl.Path[K]) (ottl.GetSetter[K], error) {
if path == nil {
return accessInstrumentationScope[K](), nil
return nil, FormatDefaultErrorMessage("instrumentation_scope", "instrumentation_scope", "Instrumentation Scope", InstrumentationScopeRef)
}
switch path.Name() {
case "name":
Expand All @@ -40,20 +40,6 @@ func ScopePathGetSetter[K InstrumentationScopeContext](path ottl.Path[K]) (ottl.
}
}

func accessInstrumentationScope[K InstrumentationScopeContext]() ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(_ context.Context, tCtx K) (any, error) {
return tCtx.GetInstrumentationScope(), nil
},
Setter: func(_ context.Context, tCtx K, val any) error {
if newIl, ok := val.(pcommon.InstrumentationScope); ok {
newIl.CopyTo(tCtx.GetInstrumentationScope())
}
return nil
},
}
}

func accessInstrumentationScopeAttributes[K InstrumentationScopeContext]() ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(_ context.Context, tCtx K) (any, error) {
Expand Down
9 changes: 0 additions & 9 deletions pkg/ottl/contexts/internal/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ func TestScopePathGetSetter(t *testing.T) {
newVal any
modified func(is pcommon.InstrumentationScope)
}{
{
name: "instrumentation_scope",
path: nil,
orig: refIS,
newVal: pcommon.NewInstrumentationScope(),
modified: func(is pcommon.InstrumentationScope) {
pcommon.NewInstrumentationScope().CopyTo(is)
},
},
{
name: "instrumentation_scope name",
path: &TestPath[*instrumentationScopeContext]{
Expand Down
16 changes: 1 addition & 15 deletions pkg/ottl/contexts/internal/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var SpanSymbolTable = map[ottl.EnumSymbol]ottl.Enum{

func SpanPathGetSetter[K SpanContext](path ottl.Path[K]) (ottl.GetSetter[K], error) {
if path == nil {
return accessSpan[K](), nil
return nil, FormatDefaultErrorMessage("span", "span", SpanContextName, SpanRef)
}
switch path.Name() {
case "trace_id":
Expand Down Expand Up @@ -132,20 +132,6 @@ func SpanPathGetSetter[K SpanContext](path ottl.Path[K]) (ottl.GetSetter[K], err
}
}

func accessSpan[K SpanContext]() ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(_ context.Context, tCtx K) (any, error) {
return tCtx.GetSpan(), nil
},
Setter: func(_ context.Context, tCtx K, val any) error {
if newSpan, ok := val.(ptrace.Span); ok {
newSpan.CopyTo(tCtx.GetSpan())
}
return nil
},
}
}

func accessTraceID[K SpanContext]() ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(_ context.Context, tCtx K) (any, error) {
Expand Down
13 changes: 0 additions & 13 deletions pkg/ottl/contexts/ottldatapoint/datapoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1923,8 +1923,6 @@ func createAttributeTelemetry(attributes pcommon.Map) {
}

func Test_newPathGetSetter_Metric(t *testing.T) {
refMetric := createMetricTelemetry()

newMetric := pmetric.NewMetric()
newMetric.SetName("new name")

Expand All @@ -1935,17 +1933,6 @@ func Test_newPathGetSetter_Metric(t *testing.T) {
newVal any
modified func(metric pmetric.Metric)
}{
{
name: "metric",
path: &internal.TestPath[TransformContext]{
N: "metric",
},
orig: refMetric,
newVal: newMetric,
modified: func(metric pmetric.Metric) {
newMetric.CopyTo(metric)
},
},
{
name: "metric name",
path: &internal.TestPath[TransformContext]{
Expand Down
24 changes: 1 addition & 23 deletions pkg/ottl/contexts/ottllog/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (
)

func Test_newPathGetSetter(t *testing.T) {
refLog, refIS, refResource := createTelemetry("string")
refLog, _, _ := createTelemetry("string")

newAttrs := pcommon.NewMap()
newAttrs.PutStr("hello", "world")
Expand Down Expand Up @@ -596,28 +596,6 @@ func Test_newPathGetSetter(t *testing.T) {
log.SetDroppedAttributesCount(20)
},
},
{
name: "instrumentation_scope",
path: &internal.TestPath[TransformContext]{
N: "instrumentation_scope",
},
orig: refIS,
newVal: pcommon.NewInstrumentationScope(),
modified: func(_ plog.LogRecord, il pcommon.InstrumentationScope, _ pcommon.Resource, _ pcommon.Map) {
pcommon.NewInstrumentationScope().CopyTo(il)
},
},
{
name: "resource",
path: &internal.TestPath[TransformContext]{
N: "resource",
},
orig: refResource,
newVal: pcommon.NewResource(),
modified: func(_ plog.LogRecord, _ pcommon.InstrumentationScope, resource pcommon.Resource, _ pcommon.Map) {
pcommon.NewResource().CopyTo(resource)
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
13 changes: 1 addition & 12 deletions pkg/ottl/contexts/ottlscope/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func Test_newPathGetSetter(t *testing.T) {
refIS, refResource := createTelemetry()
refIS, _ := createTelemetry()

newAttrs := pcommon.NewMap()
newAttrs.PutStr("hello", "world")
Expand Down Expand Up @@ -382,17 +382,6 @@ func Test_newPathGetSetter(t *testing.T) {
is.SetVersion("next")
},
},
{
name: "resource",
path: &internal.TestPath[TransformContext]{
N: "resource",
},
orig: refResource,
newVal: pcommon.NewResource(),
modified: func(_ pcommon.InstrumentationScope, resource pcommon.Resource, _ pcommon.Map) {
pcommon.NewResource().CopyTo(resource)
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
24 changes: 1 addition & 23 deletions pkg/ottl/contexts/ottlspan/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
)

func Test_newPathGetSetter(t *testing.T) {
refSpan, refIS, refResource := createTelemetry()
refSpan, _, _ := createTelemetry()

newAttrs := pcommon.NewMap()
newAttrs.PutStr("hello", "world")
Expand Down Expand Up @@ -649,28 +649,6 @@ func Test_newPathGetSetter(t *testing.T) {
span.Status().SetMessage("bad span")
},
},
{
name: "instrumentation_scope",
path: &internal.TestPath[TransformContext]{
N: "instrumentation_scope",
},
orig: refIS,
newVal: pcommon.NewInstrumentationScope(),
modified: func(_ ptrace.Span, il pcommon.InstrumentationScope, _ pcommon.Resource, _ pcommon.Map) {
pcommon.NewInstrumentationScope().CopyTo(il)
},
},
{
name: "resource",
path: &internal.TestPath[TransformContext]{
N: "resource",
},
orig: refResource,
newVal: pcommon.NewResource(),
modified: func(_ ptrace.Span, _ pcommon.InstrumentationScope, resource pcommon.Resource, _ pcommon.Map) {
pcommon.NewResource().CopyTo(resource)
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
35 changes: 1 addition & 34 deletions pkg/ottl/contexts/ottlspanevent/span_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
var spanID2 = [8]byte{8, 7, 6, 5, 4, 3, 2, 1}

func Test_newPathGetSetter(t *testing.T) {
refSpanEvent, refSpan, refIS, refResource := createTelemetry()
refSpanEvent, _, _, _ := createTelemetry()

newAttrs := pcommon.NewMap()
newAttrs.PutStr("hello", "world")
Expand Down Expand Up @@ -405,39 +405,6 @@ func Test_newPathGetSetter(t *testing.T) {
spanEvent.SetDroppedAttributesCount(20)
},
},
{
name: "instrumentation_scope",
path: &internal.TestPath[TransformContext]{
N: "instrumentation_scope",
},
orig: refIS,
newVal: pcommon.NewInstrumentationScope(),
modified: func(_ ptrace.SpanEvent, _ ptrace.Span, il pcommon.InstrumentationScope, _ pcommon.Resource, _ pcommon.Map) {
pcommon.NewInstrumentationScope().CopyTo(il)
},
},
{
name: "resource",
path: &internal.TestPath[TransformContext]{
N: "resource",
},
orig: refResource,
newVal: pcommon.NewResource(),
modified: func(_ ptrace.SpanEvent, _ ptrace.Span, _ pcommon.InstrumentationScope, resource pcommon.Resource, _ pcommon.Map) {
pcommon.NewResource().CopyTo(resource)
},
},
{
name: "span",
path: &internal.TestPath[TransformContext]{
N: "span",
},
orig: refSpan,
newVal: ptrace.NewSpan(),
modified: func(_ ptrace.SpanEvent, span ptrace.Span, _ pcommon.InstrumentationScope, _ pcommon.Resource, _ pcommon.Map) {
ptrace.NewSpan().CopyTo(span)
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading