From 8f9ce11eefec439a9b9b60117eb083c288203a8c Mon Sep 17 00:00:00 2001
From: odubajDT <ondrej.dubaj@dynatrace.com>
Date: Thu, 19 Dec 2024 09:04:14 +0100
Subject: [PATCH] support converters as attribute keys

Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
---
 pkg/ottl/contexts/internal/path.go |  4 ++--
 pkg/ottl/e2e/e2e_test.go           | 12 +++++------
 pkg/ottl/functions.go              | 33 ++++++++++++++++++++++--------
 3 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/pkg/ottl/contexts/internal/path.go b/pkg/ottl/contexts/internal/path.go
index 11f0ce558e1f..b83dfefd1299 100644
--- a/pkg/ottl/contexts/internal/path.go
+++ b/pkg/ottl/contexts/internal/path.go
@@ -46,7 +46,7 @@ var _ ottl.Key[any] = &TestKey[any]{}
 type TestKey[K any] struct {
 	S *string
 	I *int64
-	P ottl.GetSetter[K]
+	P ottl.Getter[K]
 }
 
 func (k *TestKey[K]) String(_ context.Context, _ K) (*string, error) {
@@ -57,6 +57,6 @@ func (k *TestKey[K]) Int(_ context.Context, _ K) (*int64, error) {
 	return k.I, nil
 }
 
-func (k *TestKey[K]) PathGetter(_ context.Context, _ K) (ottl.GetSetter[K], error) {
+func (k *TestKey[K]) PathGetter(_ context.Context, _ K) (ottl.Getter[K], error) {
 	return k.P, nil
 }
diff --git a/pkg/ottl/e2e/e2e_test.go b/pkg/ottl/e2e/e2e_test.go
index 0babf19bc525..2f31e6c434fa 100644
--- a/pkg/ottl/e2e/e2e_test.go
+++ b/pkg/ottl/e2e/e2e_test.go
@@ -329,12 +329,12 @@ func Test_e2e_converters(t *testing.T) {
 		statement string
 		want      func(tCtx ottllog.TransformContext)
 	}{
-		// {
-		// 	statement: `set(attributes[ConvertCase(attributes["A|B|C"], "upper")], "myvalue")`,
-		// 	want: func(tCtx ottllog.TransformContext) {
-		// 		tCtx.GetLogRecord().Attributes().PutStr("SOMETHING", "myvalue")
-		// 	},
-		// },
+		{
+			statement: `set(attributes[ConvertCase(attributes["A|B|C"], "upper")], "myvalue")`,
+			want: func(tCtx ottllog.TransformContext) {
+				tCtx.GetLogRecord().Attributes().PutStr("SOMETHING", "myvalue")
+			},
+		},
 		{
 			statement: `set(attributes[attributes["flags"]], "something33")`,
 			want: func(tCtx ottllog.TransformContext) {
diff --git a/pkg/ottl/functions.go b/pkg/ottl/functions.go
index 76fb106294a8..bbc7ee630225 100644
--- a/pkg/ottl/functions.go
+++ b/pkg/ottl/functions.go
@@ -216,13 +216,28 @@ func (p *Parser[K]) newKeys(keys []key) ([]Key[K], error) {
 	}
 	ks := make([]Key[K], len(keys))
 	for i := range keys {
-		var par GetSetter[K]
-		if keys[i].Expression != nil && keys[i].Expression.Path != nil {
-			arg, err := p.buildGetSetterFromPath(keys[i].Expression.Path)
-			if err != nil {
-				return nil, err
+		var par Getter[K]
+		if keys[i].Expression != nil {
+			if keys[i].Expression.Path != nil {
+				arg, err := p.buildGetSetterFromPath(keys[i].Expression.Path)
+				if err != nil {
+					return nil, err
+				}
+				par = arg
+			}
+			if f := keys[i].Expression.Float; f != nil {
+				par = literal[K]{value: *f}
+			}
+			if i := keys[i].Expression.Int; i != nil {
+				par = literal[K]{value: *i}
+			}
+			if keys[i].Expression.Converter != nil {
+				g, err := p.newGetterFromConverter(*keys[i].Expression.Converter)
+				if err != nil {
+					return nil, err
+				}
+				par = g
 			}
-			par = arg
 		}
 		ks[i] = &baseKey[K]{
 			s: keys[i].String,
@@ -247,7 +262,7 @@ type Key[K any] interface {
 	// If Key experiences an error retrieving the value it is returned.
 	Int(context.Context, K) (*int64, error)
 
-	PathGetter(context.Context, K) (GetSetter[K], error)
+	PathGetter(context.Context, K) (Getter[K], error)
 }
 
 var _ Key[any] = &baseKey[any]{}
@@ -255,7 +270,7 @@ var _ Key[any] = &baseKey[any]{}
 type baseKey[K any] struct {
 	s *string
 	i *int64
-	p GetSetter[K]
+	p Getter[K]
 }
 
 func (k *baseKey[K]) String(_ context.Context, _ K) (*string, error) {
@@ -266,7 +281,7 @@ func (k *baseKey[K]) Int(_ context.Context, _ K) (*int64, error) {
 	return k.i, nil
 }
 
-func (k *baseKey[K]) PathGetter(_ context.Context, _ K) (GetSetter[K], error) {
+func (k *baseKey[K]) PathGetter(_ context.Context, _ K) (Getter[K], error) {
 	return k.p, nil
 }