@@ -61,6 +61,7 @@ func Test_e2e_editors(t *testing.T) {
61
61
tCtx .GetLogRecord ().Attributes ().Remove ("total.string" )
62
62
tCtx .GetLogRecord ().Attributes ().Remove ("foo" )
63
63
tCtx .GetLogRecord ().Attributes ().Remove ("things" )
64
+ tCtx .GetLogRecord ().Attributes ().Remove ("map_slice" )
64
65
},
65
66
},
66
67
{
@@ -77,6 +78,12 @@ func Test_e2e_editors(t *testing.T) {
77
78
tCtx .GetLogRecord ().Attributes ().PutInt ("things.0.value" , 2 )
78
79
tCtx .GetLogRecord ().Attributes ().PutStr ("things.1.name" , "bar" )
79
80
tCtx .GetLogRecord ().Attributes ().PutInt ("things.1.value" , 5 )
81
+
82
+ tCtx .GetLogRecord ().Attributes ().Remove ("map_slice" )
83
+ tCtx .GetLogRecord ().Attributes ().PutStr ("map_slice.0.foo1" , "bar1" )
84
+ tCtx .GetLogRecord ().Attributes ().PutStr ("map_slice.0.foo2" , "bar2" )
85
+ tCtx .GetLogRecord ().Attributes ().PutStr ("map_slice.1.total.string" , "barbar1" )
86
+
80
87
},
81
88
},
82
89
{
@@ -100,6 +107,10 @@ func Test_e2e_editors(t *testing.T) {
100
107
m .PutInt ("test.things.0.value" , 2 )
101
108
m .PutStr ("test.things.1.name" , "bar" )
102
109
m .PutInt ("test.things.1.value" , 5 )
110
+
111
+ m .PutStr ("test.map_slice.0.foo1" , "bar1" )
112
+ m .PutStr ("test.map_slice.0.foo2" , "bar2" )
113
+ m .PutStr ("test.map_slice.1.total.string" , "barbar1" )
103
114
m .CopyTo (tCtx .GetLogRecord ().Attributes ())
104
115
},
105
116
},
@@ -128,6 +139,14 @@ func Test_e2e_editors(t *testing.T) {
128
139
129
140
m3 := m .PutEmptyMap ("foo.nested" )
130
141
m3 .PutStr ("test" , "pass" )
142
+
143
+ m4 := m .PutEmptyMap ("map_slice.0" )
144
+ m4 .PutStr ("foo1" , "bar1" )
145
+ m4 .PutStr ("foo2" , "bar2" )
146
+
147
+ m5 := m .PutEmptyMap ("map_slice.1" )
148
+ m5 .PutStr ("total.string" , "barbar1" )
149
+
131
150
m .CopyTo (tCtx .GetLogRecord ().Attributes ())
132
151
},
133
152
},
@@ -139,6 +158,7 @@ func Test_e2e_editors(t *testing.T) {
139
158
tCtx .GetLogRecord ().Attributes ().Remove ("http.url" )
140
159
tCtx .GetLogRecord ().Attributes ().Remove ("foo" )
141
160
tCtx .GetLogRecord ().Attributes ().Remove ("things" )
161
+ tCtx .GetLogRecord ().Attributes ().Remove ("map_slice" )
142
162
},
143
163
},
144
164
{
@@ -154,6 +174,7 @@ func Test_e2e_editors(t *testing.T) {
154
174
tCtx .GetLogRecord ().Attributes ().Remove ("flags" )
155
175
tCtx .GetLogRecord ().Attributes ().Remove ("foo" )
156
176
tCtx .GetLogRecord ().Attributes ().Remove ("things" )
177
+ tCtx .GetLogRecord ().Attributes ().Remove ("map_slice" )
157
178
},
158
179
},
159
180
{
@@ -185,6 +206,41 @@ func Test_e2e_editors(t *testing.T) {
185
206
m2 .PutStr ("test" , "pass" )
186
207
},
187
208
},
209
+ {
210
+ statement : `merge_maps(attributes, "insert", attributes["foo"], attributes["map_slice"])` ,
211
+ want : func (tCtx ottllog.TransformContext ) {
212
+ tCtx .GetLogRecord ().Attributes ().PutStr ("bar" , "pass" )
213
+ tCtx .GetLogRecord ().Attributes ().PutStr ("foo1" , "bar1" )
214
+ tCtx .GetLogRecord ().Attributes ().PutStr ("foo2" , "bar2" )
215
+ s := tCtx .GetLogRecord ().Attributes ().PutEmptySlice ("slice" )
216
+ v := s .AppendEmpty ()
217
+ v .SetStr ("val" )
218
+ m2 := tCtx .GetLogRecord ().Attributes ().PutEmptyMap ("nested" )
219
+ m2 .PutStr ("test" , "pass" )
220
+ },
221
+ },
222
+ {
223
+ statement : `merge_maps(attributes, "update", attributes["foo"], attributes["map_slice"])` ,
224
+ want : func (tCtx ottllog.TransformContext ) {
225
+ tCtx .GetLogRecord ().Attributes ().PutStr ("flags" , "pass" )
226
+ tCtx .GetLogRecord ().Attributes ().PutStr ("total.string" , "barbar1" )
227
+ },
228
+ },
229
+ {
230
+ statement : `merge_maps(attributes, "upsert", attributes["foo"], attributes["map_slice"])` ,
231
+ want : func (tCtx ottllog.TransformContext ) {
232
+ tCtx .GetLogRecord ().Attributes ().PutStr ("bar" , "pass" )
233
+ tCtx .GetLogRecord ().Attributes ().PutStr ("foo1" , "bar1" )
234
+ tCtx .GetLogRecord ().Attributes ().PutStr ("foo2" , "bar2" )
235
+ tCtx .GetLogRecord ().Attributes ().PutStr ("flags" , "pass" )
236
+ tCtx .GetLogRecord ().Attributes ().PutStr ("total.string" , "barbar1" )
237
+ s := tCtx .GetLogRecord ().Attributes ().PutEmptySlice ("slice" )
238
+ v := s .AppendEmpty ()
239
+ v .SetStr ("val" )
240
+ m2 := tCtx .GetLogRecord ().Attributes ().PutEmptyMap ("nested" )
241
+ m2 .PutStr ("test" , "pass" )
242
+ },
243
+ },
188
244
{
189
245
statement : `replace_all_matches(attributes, "*/*", "test")` ,
190
246
want : func (tCtx ottllog.TransformContext ) {
@@ -1459,6 +1515,12 @@ func constructLogTransformContextEditors() ottllog.TransformContext {
1459
1515
logRecord .Attributes ().PutStr ("http.url" , "http://localhost/health" )
1460
1516
logRecord .Attributes ().PutStr ("flags" , "A|B|C" )
1461
1517
logRecord .Attributes ().PutStr ("total.string" , "123456789" )
1518
+ slice := logRecord .Attributes ().PutEmptySlice ("map_slice" )
1519
+ ms := slice .AppendEmpty ().SetEmptyMap ()
1520
+ ms .PutStr ("foo1" , "bar1" )
1521
+ ms .PutStr ("foo2" , "bar2" )
1522
+ ms2 := slice .AppendEmpty ().SetEmptyMap ()
1523
+ ms2 .PutStr ("total.string" , "barbar1" )
1462
1524
m := logRecord .Attributes ().PutEmptyMap ("foo" )
1463
1525
m .PutStr ("bar" , "pass" )
1464
1526
m .PutStr ("flags" , "pass" )
0 commit comments