@@ -62,6 +62,7 @@ func Test_e2e_editors(t *testing.T) {
6262 tCtx .GetLogRecord ().Attributes ().Remove ("things" )
6363 tCtx .GetLogRecord ().Attributes ().Remove ("conflict.conflict1" )
6464 tCtx .GetLogRecord ().Attributes ().Remove ("conflict" )
65+ tCtx .GetLogRecord ().Attributes ().Remove ("slice2" )
6566 },
6667 },
6768 {
@@ -81,6 +82,12 @@ func Test_e2e_editors(t *testing.T) {
8182 tCtx .GetLogRecord ().Attributes ().PutInt ("things.0.value" , 2 )
8283 tCtx .GetLogRecord ().Attributes ().PutStr ("things.1.name" , "bar" )
8384 tCtx .GetLogRecord ().Attributes ().PutInt ("things.1.value" , 5 )
85+
86+ tCtx .GetLogRecord ().Attributes ().Remove ("slice2" )
87+ tCtx .GetLogRecord ().Attributes ().PutStr ("slice2.0" , "val" )
88+ tCtx .GetLogRecord ().Attributes ().PutStr ("slice2.1" , "foo" )
89+ tCtx .GetLogRecord ().Attributes ().PutStr ("slice2.2" , "bar" )
90+ tCtx .GetLogRecord ().Attributes ().PutStr ("slice2.3" , "baz" )
8491 },
8592 },
8693 {
@@ -105,6 +112,11 @@ func Test_e2e_editors(t *testing.T) {
105112 m .PutInt ("test.things.0.value" , 2 )
106113 m .PutStr ("test.things.1.name" , "bar" )
107114 m .PutInt ("test.things.1.value" , 5 )
115+
116+ m .PutStr ("test.slice2.0" , "val" )
117+ m .PutStr ("test.slice2.1" , "foo" )
118+ m .PutStr ("test.slice2.2" , "bar" )
119+ m .PutStr ("test.slice2.3" , "baz" )
108120 m .CopyTo (tCtx .GetLogRecord ().Attributes ())
109121 },
110122 },
@@ -133,6 +145,11 @@ func Test_e2e_editors(t *testing.T) {
133145 m .PutStr ("test.things.1.name" , "bar" )
134146 m .PutInt ("test.things.1.value" , 5 )
135147
148+ m .PutStr ("test.slice2" , "val" )
149+ m .PutStr ("test.slice2.0" , "foo" )
150+ m .PutStr ("test.slice2.1" , "bar" )
151+ m .PutStr ("test.slice2.2" , "baz" )
152+
136153 m .CopyTo (tCtx .GetLogRecord ().Attributes ())
137154 },
138155 },
@@ -149,6 +166,10 @@ func Test_e2e_editors(t *testing.T) {
149166 m .PutStr ("foo.flags" , "pass" )
150167 m .PutStr ("foo.bar" , "pass" )
151168 m .PutStr ("foo.flags" , "pass" )
169+ m .PutStr ("slice2.0" , "val" )
170+ m .PutStr ("slice2.1" , "foo" )
171+ m .PutStr ("slice2.2" , "bar" )
172+ m .PutStr ("slice2.3" , "baz" )
152173 m .PutEmptySlice ("foo.slice" ).AppendEmpty ().SetStr ("val" )
153174 m .PutStr ("conflict.conflict1.conflict2" , "nopass" )
154175 mm := m .PutEmptyMap ("conflict.conflict1" )
@@ -177,6 +198,7 @@ func Test_e2e_editors(t *testing.T) {
177198 tCtx .GetLogRecord ().Attributes ().Remove ("things" )
178199 tCtx .GetLogRecord ().Attributes ().Remove ("conflict.conflict1" )
179200 tCtx .GetLogRecord ().Attributes ().Remove ("conflict" )
201+ tCtx .GetLogRecord ().Attributes ().Remove ("slice2" )
180202 },
181203 },
182204 {
@@ -194,6 +216,7 @@ func Test_e2e_editors(t *testing.T) {
194216 tCtx .GetLogRecord ().Attributes ().Remove ("things" )
195217 tCtx .GetLogRecord ().Attributes ().Remove ("conflict.conflict1" )
196218 tCtx .GetLogRecord ().Attributes ().Remove ("conflict" )
219+ tCtx .GetLogRecord ().Attributes ().Remove ("slice2" )
197220 },
198221 },
199222 {
@@ -375,6 +398,53 @@ func Test_e2e_editors(t *testing.T) {
375398 s .AppendEmpty ().SetInt (6 )
376399 },
377400 },
401+ {
402+ statement : `delete(attributes["slice2"], 0)` ,
403+ want : func (tCtx ottllog.TransformContext ) {
404+ v , _ := tCtx .GetLogRecord ().Attributes ().Get ("slice2" )
405+ s := v .Slice ()
406+ // :ToDo: Implement RemoveAt and RemoveRange in pcommon.Slice
407+ s .RemoveIf (func (v pcommon.Value ) bool {
408+ return v .Str () == "val"
409+ })
410+ },
411+ },
412+ {
413+ statement : `delete(attributes["slice2"], Len(attributes["slice2"]) - 1)` ,
414+ want : func (tCtx ottllog.TransformContext ) {
415+ v , _ := tCtx .GetLogRecord ().Attributes ().Get ("slice2" )
416+ s := v .Slice ()
417+ s .RemoveIf (func (v pcommon.Value ) bool {
418+ return v .Str () == "baz"
419+ })
420+ },
421+ },
422+ {
423+ statement : `delete(attributes["slice2"], 1, length=2)` ,
424+ want : func (tCtx ottllog.TransformContext ) {
425+ v , _ := tCtx .GetLogRecord ().Attributes ().Get ("slice2" )
426+ s := v .Slice ()
427+ s .RemoveIf (func (v pcommon.Value ) bool {
428+ return (v .Str () == "foo" || v .Str () == "bar" )
429+ })
430+ },
431+ },
432+ {
433+ statement : `delete(attributes["slice2"], Index(attributes["slice2"], "foo"))` ,
434+ want : func (tCtx ottllog.TransformContext ) {
435+ v , _ := tCtx .GetLogRecord ().Attributes ().Get ("slice2" )
436+ s := v .Slice ()
437+ s .RemoveIf (func (v pcommon.Value ) bool {
438+ return v .Str () == "foo"
439+ })
440+ },
441+ },
442+ {
443+ statement : `delete(attributes["slice2"], Index(attributes["slice2"], "not_found"))` ,
444+ want : func (tCtx ottllog.TransformContext ) {
445+ // No change as "not_found" does not exist in the slice.
446+ },
447+ },
378448 }
379449
380450 for _ , tt := range tests {
@@ -1994,6 +2064,12 @@ func constructLogTransformContextEditors() ottllog.TransformContext {
19942064 thing2 .PutStr ("name" , "bar" )
19952065 thing2 .PutInt ("value" , 5 )
19962066
2067+ s3 := logRecord .Attributes ().PutEmptySlice ("slice2" )
2068+ s3 .AppendEmpty ().SetStr ("val" )
2069+ s3 .AppendEmpty ().SetStr ("foo" )
2070+ s3 .AppendEmpty ().SetStr ("bar" )
2071+ s3 .AppendEmpty ().SetStr ("baz" )
2072+
19972073 return ottllog .NewTransformContext (logRecord , scope , resource , plog .NewScopeLogs (), plog .NewResourceLogs ())
19982074}
19992075
0 commit comments