Skip to content

Commit 9e58d4d

Browse files
authored
Merge pull request #769 from alkshmir/main
fix event_group_by not handling delete events
2 parents f88dca4 + 409da40 commit 9e58d4d

File tree

2 files changed

+207
-2
lines changed

2 files changed

+207
-2
lines changed

pkg/formatters/event_group_by/event_group_by.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (p *groupBy) byTagsOld(es []*formatters.EventMsg) []*formatters.EventMsg {
113113
groups := make(map[string]*formatters.EventMsg)
114114
keys := make([]string, 0)
115115
for _, e := range es {
116-
if e == nil || e.Tags == nil || e.Values == nil {
116+
if e == nil || e.Tags == nil || (e.Values == nil && e.Deletes == nil) {
117117
continue
118118
}
119119
exist := true
@@ -172,7 +172,7 @@ func (p *groupBy) byTags(es []*formatters.EventMsg) []*formatters.EventMsg {
172172
groups := make(map[uint64]*formatters.EventMsg)
173173

174174
for _, e := range es {
175-
if e == nil || e.Tags == nil || e.Values == nil {
175+
if e == nil || e.Tags == nil || (e.Values == nil && e.Deletes == nil) {
176176
continue
177177
}
178178

pkg/formatters/event_group_by/event_group_by_test.go

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,42 @@ var testset = map[string]struct {
7575
},
7676
},
7777
},
78+
{
79+
input: []*formatters.EventMsg{
80+
{
81+
Deletes: []string{"value1"},
82+
Tags: map[string]string{"tag1": "1"},
83+
},
84+
{
85+
Deletes: []string{"value2"},
86+
Tags: map[string]string{"tag1": "1"},
87+
},
88+
{
89+
Deletes: []string{"value3"},
90+
Tags: map[string]string{"tag2": "2"},
91+
},
92+
},
93+
output: []*formatters.EventMsg{
94+
{
95+
Deletes: []string{
96+
"value3",
97+
},
98+
Tags: map[string]string{
99+
"tag2": "2",
100+
},
101+
},
102+
{
103+
Values: make(map[string]interface{}),
104+
Deletes: []string{
105+
"value1",
106+
"value2",
107+
},
108+
Tags: map[string]string{
109+
"tag1": "1",
110+
},
111+
},
112+
},
113+
},
78114
},
79115
},
80116
"group_by_2_tags": {
@@ -145,6 +181,62 @@ var testset = map[string]struct {
145181
},
146182
},
147183
},
184+
{
185+
input: []*formatters.EventMsg{
186+
{
187+
Deletes: []string{"value1"},
188+
Tags: map[string]string{
189+
"tag1": "1",
190+
"tag2": "2",
191+
},
192+
},
193+
{
194+
Deletes: []string{"value2"},
195+
Tags: map[string]string{
196+
"tag1": "1",
197+
"tag2": "2",
198+
},
199+
},
200+
{
201+
Deletes: []string{"value3"},
202+
Tags: map[string]string{
203+
"tag1": "1",
204+
"tag2": "3",
205+
},
206+
},
207+
{
208+
Deletes: []string{"value4"},
209+
Tags: map[string]string{
210+
"tag1": "1",
211+
"tag2": "3",
212+
},
213+
},
214+
},
215+
output: []*formatters.EventMsg{
216+
{
217+
Values: make(map[string]interface{}),
218+
Deletes: []string{
219+
"value1",
220+
"value2",
221+
},
222+
Tags: map[string]string{
223+
"tag1": "1",
224+
"tag2": "2",
225+
},
226+
},
227+
{
228+
Values: make(map[string]interface{}),
229+
Deletes: []string{
230+
"value3",
231+
"value4",
232+
},
233+
Tags: map[string]string{
234+
"tag1": "1",
235+
"tag2": "3",
236+
},
237+
},
238+
},
239+
},
148240
{
149241
input: []*formatters.EventMsg{
150242
{
@@ -261,6 +353,52 @@ var testset = map[string]struct {
261353
},
262354
},
263355
},
356+
{
357+
input: []*formatters.EventMsg{
358+
{
359+
Name: "sub1",
360+
Values: make(map[string]interface{}),
361+
Deletes: []string{
362+
"value1",
363+
},
364+
Tags: map[string]string{
365+
"tag1": "1",
366+
},
367+
},
368+
{
369+
Name: "sub1",
370+
Values: make(map[string]interface{}),
371+
Deletes: []string{
372+
"value2",
373+
},
374+
Tags: map[string]string{
375+
"tag2": "2",
376+
},
377+
},
378+
},
379+
output: []*formatters.EventMsg{
380+
{
381+
Name: "sub1",
382+
Values: make(map[string]interface{}),
383+
Deletes: []string{
384+
"value1",
385+
},
386+
Tags: map[string]string{
387+
"tag1": "1",
388+
},
389+
},
390+
{
391+
Name: "sub1",
392+
Values: make(map[string]interface{}),
393+
Deletes: []string{
394+
"value2",
395+
},
396+
Tags: map[string]string{
397+
"tag2": "2",
398+
},
399+
},
400+
},
401+
},
264402
{
265403
input: []*formatters.EventMsg{
266404
{
@@ -356,6 +494,37 @@ var testset = map[string]struct {
356494
},
357495
},
358496
},
497+
{
498+
input: []*formatters.EventMsg{
499+
{
500+
Name: "sub1",
501+
Deletes: []string{"value1"},
502+
Tags: map[string]string{
503+
"tag1": "1",
504+
},
505+
},
506+
{
507+
Name: "sub1",
508+
Deletes: []string{"value2"},
509+
Tags: map[string]string{
510+
"tag1": "1",
511+
},
512+
},
513+
},
514+
output: []*formatters.EventMsg{
515+
{
516+
Name: "sub1",
517+
Values: make(map[string]interface{}),
518+
Deletes: []string{
519+
"value1",
520+
"value2",
521+
},
522+
Tags: map[string]string{
523+
"tag1": "1",
524+
},
525+
},
526+
},
527+
},
359528
{
360529
input: []*formatters.EventMsg{
361530
{
@@ -394,6 +563,42 @@ var testset = map[string]struct {
394563
},
395564
},
396565
},
566+
{
567+
input: []*formatters.EventMsg{
568+
{
569+
Name: "sub1",
570+
Deletes: []string{"value1"},
571+
Tags: map[string]string{
572+
"tag1": "1",
573+
},
574+
},
575+
{
576+
Name: "sub1",
577+
Deletes: []string{"value2"},
578+
Tags: map[string]string{
579+
"tag1": "2",
580+
},
581+
},
582+
},
583+
output: []*formatters.EventMsg{
584+
{
585+
Name: "sub1",
586+
Values: make(map[string]interface{}),
587+
Deletes: []string{"value1"},
588+
Tags: map[string]string{
589+
"tag1": "1",
590+
},
591+
},
592+
{
593+
Name: "sub1",
594+
Values: make(map[string]interface{}),
595+
Deletes: []string{"value2"},
596+
Tags: map[string]string{
597+
"tag1": "2",
598+
},
599+
},
600+
},
601+
},
397602
},
398603
},
399604
}

0 commit comments

Comments
 (0)