@@ -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 {
@@ -92,6 +93,12 @@ func Test_e2e_editors(t *testing.T) {
9293 tCtx .GetLogRecord ().Attributes ().PutInt ("things.0.value" , 2 )
9394 tCtx .GetLogRecord ().Attributes ().PutStr ("things.1.name" , "bar" )
9495 tCtx .GetLogRecord ().Attributes ().PutInt ("things.1.value" , 5 )
96+
97+ tCtx .GetLogRecord ().Attributes ().Remove ("slice2" )
98+ tCtx .GetLogRecord ().Attributes ().PutStr ("slice2.0" , "val" )
99+ tCtx .GetLogRecord ().Attributes ().PutStr ("slice2.1" , "foo" )
100+ tCtx .GetLogRecord ().Attributes ().PutStr ("slice2.2" , "bar" )
101+ tCtx .GetLogRecord ().Attributes ().PutStr ("slice2.3" , "baz" )
95102 },
96103 },
97104 {
@@ -116,6 +123,11 @@ func Test_e2e_editors(t *testing.T) {
116123 m .PutInt ("test.things.0.value" , 2 )
117124 m .PutStr ("test.things.1.name" , "bar" )
118125 m .PutInt ("test.things.1.value" , 5 )
126+
127+ m .PutStr ("test.slice2.0" , "val" )
128+ m .PutStr ("test.slice2.1" , "foo" )
129+ m .PutStr ("test.slice2.2" , "bar" )
130+ m .PutStr ("test.slice2.3" , "baz" )
119131 m .CopyTo (tCtx .GetLogRecord ().Attributes ())
120132 },
121133 },
@@ -144,6 +156,11 @@ func Test_e2e_editors(t *testing.T) {
144156 m .PutStr ("test.things.1.name" , "bar" )
145157 m .PutInt ("test.things.1.value" , 5 )
146158
159+ m .PutStr ("test.slice2" , "val" )
160+ m .PutStr ("test.slice2.0" , "foo" )
161+ m .PutStr ("test.slice2.1" , "bar" )
162+ m .PutStr ("test.slice2.2" , "baz" )
163+
147164 m .CopyTo (tCtx .GetLogRecord ().Attributes ())
148165 },
149166 },
@@ -160,6 +177,10 @@ func Test_e2e_editors(t *testing.T) {
160177 m .PutStr ("foo.flags" , "pass" )
161178 m .PutStr ("foo.bar" , "pass" )
162179 m .PutStr ("foo.flags" , "pass" )
180+ m .PutStr ("slice2.0" , "val" )
181+ m .PutStr ("slice2.1" , "foo" )
182+ m .PutStr ("slice2.2" , "bar" )
183+ m .PutStr ("slice2.3" , "baz" )
163184 m .PutEmptySlice ("foo.slice" ).AppendEmpty ().SetStr ("val" )
164185 m .PutStr ("conflict.conflict1.conflict2" , "nopass" )
165186 mm := m .PutEmptyMap ("conflict.conflict1" )
@@ -188,6 +209,7 @@ func Test_e2e_editors(t *testing.T) {
188209 tCtx .GetLogRecord ().Attributes ().Remove ("things" )
189210 tCtx .GetLogRecord ().Attributes ().Remove ("conflict.conflict1" )
190211 tCtx .GetLogRecord ().Attributes ().Remove ("conflict" )
212+ tCtx .GetLogRecord ().Attributes ().Remove ("slice2" )
191213 },
192214 },
193215 {
@@ -205,6 +227,7 @@ func Test_e2e_editors(t *testing.T) {
205227 tCtx .GetLogRecord ().Attributes ().Remove ("things" )
206228 tCtx .GetLogRecord ().Attributes ().Remove ("conflict.conflict1" )
207229 tCtx .GetLogRecord ().Attributes ().Remove ("conflict" )
230+ tCtx .GetLogRecord ().Attributes ().Remove ("slice2" )
208231 },
209232 },
210233 {
@@ -386,6 +409,53 @@ func Test_e2e_editors(t *testing.T) {
386409 s .AppendEmpty ().SetInt (6 )
387410 },
388411 },
412+ {
413+ statement : `delete(attributes["slice2"], 0)` ,
414+ want : func (tCtx ottllog.TransformContext ) {
415+ v , _ := tCtx .GetLogRecord ().Attributes ().Get ("slice2" )
416+ s := v .Slice ()
417+ // :ToDo: Implement RemoveAt and RemoveRange in pcommon.Slice
418+ s .RemoveIf (func (v pcommon.Value ) bool {
419+ return v .Str () == "val"
420+ })
421+ },
422+ },
423+ {
424+ statement : `delete(attributes["slice2"], Len(attributes["slice2"]) - 1)` ,
425+ want : func (tCtx ottllog.TransformContext ) {
426+ v , _ := tCtx .GetLogRecord ().Attributes ().Get ("slice2" )
427+ s := v .Slice ()
428+ s .RemoveIf (func (v pcommon.Value ) bool {
429+ return v .Str () == "baz"
430+ })
431+ },
432+ },
433+ {
434+ statement : `delete(attributes["slice2"], 1, length=2)` ,
435+ want : func (tCtx ottllog.TransformContext ) {
436+ v , _ := tCtx .GetLogRecord ().Attributes ().Get ("slice2" )
437+ s := v .Slice ()
438+ s .RemoveIf (func (v pcommon.Value ) bool {
439+ return (v .Str () == "foo" || v .Str () == "bar" )
440+ })
441+ },
442+ },
443+ {
444+ statement : `delete(attributes["slice2"], Index(attributes["slice2"], "foo"))` ,
445+ want : func (tCtx ottllog.TransformContext ) {
446+ v , _ := tCtx .GetLogRecord ().Attributes ().Get ("slice2" )
447+ s := v .Slice ()
448+ s .RemoveIf (func (v pcommon.Value ) bool {
449+ return v .Str () == "foo"
450+ })
451+ },
452+ },
453+ {
454+ statement : `delete(attributes["slice2"], Index(attributes["slice2"], "not_found"))` ,
455+ want : func (tCtx ottllog.TransformContext ) {
456+ // No change as "not_found" does not exist in the slice.
457+ },
458+ },
389459 }
390460
391461 for _ , tt := range tests {
@@ -2013,6 +2083,12 @@ func constructLogTransformContextEditors() ottllog.TransformContext {
20132083 thing2 .PutStr ("name" , "bar" )
20142084 thing2 .PutInt ("value" , 5 )
20152085
2086+ s3 := logRecord .Attributes ().PutEmptySlice ("slice2" )
2087+ s3 .AppendEmpty ().SetStr ("val" )
2088+ s3 .AppendEmpty ().SetStr ("foo" )
2089+ s3 .AppendEmpty ().SetStr ("bar" )
2090+ s3 .AppendEmpty ().SetStr ("baz" )
2091+
20162092 return ottllog .NewTransformContext (logRecord , scope , resource , plog .NewScopeLogs (), plog .NewResourceLogs ())
20172093}
20182094
0 commit comments