Skip to content

Commit

Permalink
[pkg/ottl] Support dynamic indexing
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Dec 9, 2024
1 parent 464969b commit 08d127b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 19 deletions.
3 changes: 0 additions & 3 deletions pkg/ottl/contexts/internal/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ func SetMapValue[K any](ctx context.Context, tCtx K, m pcommon.Map, keys []ottl.
if err != nil {
return err
}
if s == nil {
return fmt.Errorf("non-string indexing is not supported")
}

currentValue, ok := m.Get(*s)
if !ok {
Expand Down
1 change: 1 addition & 0 deletions pkg/ottl/contexts/internal/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func accessResourceAttributesKey[K ResourceContext](keys []ottl.Key[K]) ottl.Sta
Setter: func(ctx context.Context, tCtx K, val any) error {
return SetMapValue[K](ctx, tCtx, tCtx.GetResource().Attributes(), keys, val)
},
// TODO
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ottl/contexts/internal/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func accessInstrumentationScopeAttributesKey[K InstrumentationScopeContext](keys
Setter: func(ctx context.Context, tCtx K, val any) error {
return SetMapValue[K](ctx, tCtx, tCtx.GetInstrumentationScope().Attributes(), keys, val)
},
// TODO
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ottl/contexts/internal/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ func accessAttributesKey[K SpanContext](keys []ottl.Key[K]) ottl.StandardGetSett
Setter: func(ctx context.Context, tCtx K, val any) error {
return SetMapValue[K](ctx, tCtx, tCtx.GetSpan().Attributes(), keys, val)
},
// TODO
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ottl/contexts/ottldatapoint/datapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func accessAttributesKey(key []ottl.Key[TransformContext]) ottl.StandardGetSette
case pmetric.SummaryDataPoint:
return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.SummaryDataPoint).Attributes(), key, val)
}
// TODO
return nil
},
}
Expand Down
1 change: 1 addition & 0 deletions pkg/ottl/contexts/ottllog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ func accessAttributesKey(key []ottl.Key[TransformContext]) ottl.StandardGetSette
Setter: func(ctx context.Context, tCtx TransformContext, val any) error {
return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Attributes(), key, val)
},
// TODO
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ottl/contexts/ottlspanevent/span_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func accessSpanEventAttributesKey(key []ottl.Key[TransformContext]) ottl.Standar
Setter: func(ctx context.Context, tCtx TransformContext, val any) error {
return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetSpanEvent().Attributes(), key, val)
},
// TODO
}
}

Expand Down
32 changes: 16 additions & 16 deletions pkg/ottl/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,22 +329,22 @@ func Test_e2e_converters(t *testing.T) {
statement string
want func(tCtx ottllog.TransformContext)
}{
{
statement: `set(attributes["test"], Base64Decode("cGFzcw=="))`,
want: func(tCtx ottllog.TransformContext) {
tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
},
},
{
statement: `set(attributes["test"], Decode("cGFzcw==", "base64"))`,
want: func(tCtx ottllog.TransformContext) {
tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
},
},
{
statement: `set(attributes["test"], Concat(["A","B"], ":"))`,
want: func(tCtx ottllog.TransformContext) {
tCtx.GetLogRecord().Attributes().PutStr("test", "A:B")
// {
// statement: `set(attributes["test"], Base64Decode("cGFzcw=="))`,
// want: func(tCtx ottllog.TransformContext) {
// tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
// },
// },
// {
// statement: `set(attributes["test"], Decode("cGFzcw==", "base64"))`,
// want: func(tCtx ottllog.TransformContext) {
// tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
// },
// },
{
statement: `set(attributes["foo"], Concat(["A","B"], ":"))`,
want: func(tCtx ottllog.TransformContext) {
tCtx.GetLogRecord().Attributes().PutStr("foo", "A:B")
},
},
{
Expand Down

0 comments on commit 08d127b

Please sign in to comment.