@@ -63,6 +63,7 @@ func Test_e2e_editors(t *testing.T) {
6363 tCtx .GetLogRecord ().Attributes ().Remove ("things" )
6464 tCtx .GetLogRecord ().Attributes ().Remove ("conflict.conflict1" )
6565 tCtx .GetLogRecord ().Attributes ().Remove ("conflict" )
66+ tCtx .GetLogRecord ().Attributes ().Remove ("slice2" )
6667 },
6768 },
6869 {
@@ -74,6 +75,7 @@ func Test_e2e_editors(t *testing.T) {
7475 tCtx .GetLogRecord ().Attributes ().Remove ("things" )
7576 tCtx .GetLogRecord ().Attributes ().Remove ("conflict.conflict1" )
7677 tCtx .GetLogRecord ().Attributes ().Remove ("conflict" )
78+ tCtx .GetLogRecord ().Attributes ().Remove ("slice2" )
7779 },
7880 },
7981 {
@@ -93,6 +95,12 @@ func Test_e2e_editors(t *testing.T) {
9395 tCtx .GetLogRecord ().Attributes ().PutInt ("things.0.value" , 2 )
9496 tCtx .GetLogRecord ().Attributes ().PutStr ("things.1.name" , "bar" )
9597 tCtx .GetLogRecord ().Attributes ().PutInt ("things.1.value" , 5 )
98+
99+ tCtx .GetLogRecord ().Attributes ().Remove ("slice2" )
100+ tCtx .GetLogRecord ().Attributes ().PutStr ("slice2.0" , "val" )
101+ tCtx .GetLogRecord ().Attributes ().PutStr ("slice2.1" , "foo" )
102+ tCtx .GetLogRecord ().Attributes ().PutStr ("slice2.2" , "bar" )
103+ tCtx .GetLogRecord ().Attributes ().PutStr ("slice2.3" , "baz" )
96104 },
97105 },
98106 {
@@ -117,6 +125,11 @@ func Test_e2e_editors(t *testing.T) {
117125 m .PutInt ("test.things.0.value" , 2 )
118126 m .PutStr ("test.things.1.name" , "bar" )
119127 m .PutInt ("test.things.1.value" , 5 )
128+
129+ m .PutStr ("test.slice2.0" , "val" )
130+ m .PutStr ("test.slice2.1" , "foo" )
131+ m .PutStr ("test.slice2.2" , "bar" )
132+ m .PutStr ("test.slice2.3" , "baz" )
120133 m .CopyTo (tCtx .GetLogRecord ().Attributes ())
121134 },
122135 },
@@ -145,6 +158,11 @@ func Test_e2e_editors(t *testing.T) {
145158 m .PutStr ("test.things.1.name" , "bar" )
146159 m .PutInt ("test.things.1.value" , 5 )
147160
161+ m .PutStr ("test.slice2" , "val" )
162+ m .PutStr ("test.slice2.0" , "foo" )
163+ m .PutStr ("test.slice2.1" , "bar" )
164+ m .PutStr ("test.slice2.2" , "baz" )
165+
148166 m .CopyTo (tCtx .GetLogRecord ().Attributes ())
149167 },
150168 },
@@ -161,6 +179,10 @@ func Test_e2e_editors(t *testing.T) {
161179 m .PutStr ("foo.flags" , "pass" )
162180 m .PutStr ("foo.bar" , "pass" )
163181 m .PutStr ("foo.flags" , "pass" )
182+ m .PutStr ("slice2.0" , "val" )
183+ m .PutStr ("slice2.1" , "foo" )
184+ m .PutStr ("slice2.2" , "bar" )
185+ m .PutStr ("slice2.3" , "baz" )
164186 m .PutEmptySlice ("foo.slice" ).AppendEmpty ().SetStr ("val" )
165187 m .PutStr ("conflict.conflict1.conflict2" , "nopass" )
166188 mm := m .PutEmptyMap ("conflict.conflict1" )
@@ -189,6 +211,7 @@ func Test_e2e_editors(t *testing.T) {
189211 tCtx .GetLogRecord ().Attributes ().Remove ("things" )
190212 tCtx .GetLogRecord ().Attributes ().Remove ("conflict.conflict1" )
191213 tCtx .GetLogRecord ().Attributes ().Remove ("conflict" )
214+ tCtx .GetLogRecord ().Attributes ().Remove ("slice2" )
192215 },
193216 },
194217 {
@@ -206,6 +229,7 @@ func Test_e2e_editors(t *testing.T) {
206229 tCtx .GetLogRecord ().Attributes ().Remove ("things" )
207230 tCtx .GetLogRecord ().Attributes ().Remove ("conflict.conflict1" )
208231 tCtx .GetLogRecord ().Attributes ().Remove ("conflict" )
232+ tCtx .GetLogRecord ().Attributes ().Remove ("slice2" )
209233 },
210234 },
211235 {
@@ -393,6 +417,46 @@ func Test_e2e_editors(t *testing.T) {
393417 s .AppendEmpty ().SetInt (6 )
394418 },
395419 },
420+ {
421+ statement : `delete_index(attributes["slice2"], 0)` ,
422+ want : func (tCtx * ottllog.TransformContext ) {
423+ v , _ := tCtx .GetLogRecord ().Attributes ().Get ("slice2" )
424+ s := v .Slice ()
425+ s .RemoveIf (func (v pcommon.Value ) bool {
426+ return v .Str () == "val"
427+ })
428+ },
429+ },
430+ {
431+ statement : `delete_index(attributes["slice2"], Len(attributes["slice2"]) - 1)` ,
432+ want : func (tCtx * ottllog.TransformContext ) {
433+ v , _ := tCtx .GetLogRecord ().Attributes ().Get ("slice2" )
434+ s := v .Slice ()
435+ s .RemoveIf (func (v pcommon.Value ) bool {
436+ return v .Str () == "baz"
437+ })
438+ },
439+ },
440+ {
441+ statement : `delete_index(attributes["slice2"], 1, endIndex=3)` ,
442+ want : func (tCtx * ottllog.TransformContext ) {
443+ v , _ := tCtx .GetLogRecord ().Attributes ().Get ("slice2" )
444+ s := v .Slice ()
445+ s .RemoveIf (func (v pcommon.Value ) bool {
446+ return (v .Str () == "foo" || v .Str () == "bar" )
447+ })
448+ },
449+ },
450+ {
451+ statement : `delete_index(attributes["slice2"], Index(attributes["slice2"], "foo"))` ,
452+ want : func (tCtx * ottllog.TransformContext ) {
453+ v , _ := tCtx .GetLogRecord ().Attributes ().Get ("slice2" )
454+ s := v .Slice ()
455+ s .RemoveIf (func (v pcommon.Value ) bool {
456+ return v .Str () == "foo"
457+ })
458+ },
459+ },
396460 }
397461
398462 for _ , tt := range tests {
@@ -2190,6 +2254,12 @@ func constructLogTransformContextEditors() *ottllog.TransformContext {
21902254 thing2 .PutStr ("name" , "bar" )
21912255 thing2 .PutInt ("value" , 5 )
21922256
2257+ s3 := logRecord .Attributes ().PutEmptySlice ("slice2" )
2258+ s3 .AppendEmpty ().SetStr ("val" )
2259+ s3 .AppendEmpty ().SetStr ("foo" )
2260+ s3 .AppendEmpty ().SetStr ("bar" )
2261+ s3 .AppendEmpty ().SetStr ("baz" )
2262+
21932263 return ottllog .NewTransformContextPtr (rLogs , rLogs .ScopeLogs ().At (0 ), logRecord )
21942264}
21952265
0 commit comments