Skip to content

Commit 48cfd78

Browse files
committed
Exclude filter overrides Include Filter
1 parent d0be75c commit 48cfd78

2 files changed

Lines changed: 98 additions & 2 deletions

File tree

sumoCFFirehose/sumoLogicAppender.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ func WantedEvent(event string, includeOnlyMatchingFilter string, excludeAlwaysMa
119119
subsliceExclude := ParseCustomInput(excludeAlwaysMatchingFilter)
120120
for key, value := range subsliceInclude {
121121
if strings.Contains(event, "\""+key+"\":\""+value+"\"") {
122+
for key, value := range subsliceExclude {
123+
if strings.Contains(event, "\""+key+"\":\""+value+"\"") {
124+
return false
125+
}
126+
}
122127
return true
123128
}
124129
}
@@ -127,7 +132,7 @@ func WantedEvent(event string, includeOnlyMatchingFilter string, excludeAlwaysMa
127132
return false
128133
}
129134
}
130-
return false
135+
return true
131136
} else if includeOnlyMatchingFilter != "" {
132137
subslice := ParseCustomInput(includeOnlyMatchingFilter)
133138
for key, value := range subslice {

sumoCFFirehose/sumoLogicAppender_test.go

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func TestSendExcludeAlwaysFilter(t *testing.T) {
188188
excludeAlwaysFilter := "source_type:other,cf_app_id:7833dc75-4484-409c-9b74-90b6454906c6"
189189
assert.False(t, WantedEvent(buf.String(), "", excludeAlwaysFilter), "This Event should be excluded")
190190
}
191-
func TestSendIncludeOnlyAlwaysFilter(t *testing.T) {
191+
func TestSendIncludeExcludeFilterOverride(t *testing.T) {
192192
eventToExclude := Event{
193193
Fields: map[string]interface{}{
194194
"message_type": "OUT",
@@ -215,8 +215,99 @@ func TestSendIncludeOnlyAlwaysFilter(t *testing.T) {
215215
buf.Write(msg)
216216
includeOnlyFilter := "job:diego_cell,source_type:other"
217217
excludeAlwaysFilter := "source_type:other,cf_app_id:7833dc75-4484-409c-9b74-90b6454906c6"
218+
assert.False(t, WantedEvent(buf.String(), includeOnlyFilter, excludeAlwaysFilter), "This Event should be not included, override filter")
219+
}
220+
221+
func TestSendIncludeExcludeFilterAppMatchIncluded(t *testing.T) {
222+
eventToExclude := Event{
223+
Fields: map[string]interface{}{
224+
"message_type": "OUT",
225+
"source_instance": 0,
226+
"deployment": "cf",
227+
"ip": "10.193.166.47",
228+
"job": "diego_cell",
229+
"job_index": "c62aebe5-16b8-43f5-a589-1267e09b9537",
230+
"cf_ignored_app": "false",
231+
"timestamp": "2017-01-10 17:31:02.662133274 -0300 CLST",
232+
"source_type": "APP",
233+
"origin": "rep",
234+
"cf_app_id": "7833dc75-4484-409c-9b74-90b6454906c6",
235+
},
236+
Msg: "Triggering 'app usage events fetcher'",
237+
Type: "LogMessage",
238+
}
239+
message, err := json.Marshal(eventToExclude)
240+
var msg []byte
241+
if err == nil {
242+
msg = message
243+
}
244+
buf := new(bytes.Buffer)
245+
buf.Write(msg)
246+
includeOnlyFilter := "job:diego_cell,source_type:other"
247+
excludeAlwaysFilter := "source_type:other,origin:router"
218248
assert.True(t, WantedEvent(buf.String(), includeOnlyFilter, excludeAlwaysFilter), "This Event should be included")
219249
}
250+
251+
func TestSendIncludeExcludeFilterAppMatchExcluded(t *testing.T) {
252+
eventToExclude := Event{
253+
Fields: map[string]interface{}{
254+
"message_type": "OUT",
255+
"source_instance": 0,
256+
"deployment": "cf",
257+
"ip": "10.193.166.47",
258+
"job": "diego_cell",
259+
"job_index": "c62aebe5-16b8-43f5-a589-1267e09b9537",
260+
"cf_ignored_app": "false",
261+
"timestamp": "2017-01-10 17:31:02.662133274 -0300 CLST",
262+
"source_type": "APP",
263+
"origin": "rep",
264+
"cf_app_id": "7833dc75-4484-409c-9b74-90b6454906c6",
265+
},
266+
Msg: "Triggering 'app usage events fetcher'",
267+
Type: "LogMessage",
268+
}
269+
message, err := json.Marshal(eventToExclude)
270+
var msg []byte
271+
if err == nil {
272+
msg = message
273+
}
274+
buf := new(bytes.Buffer)
275+
buf.Write(msg)
276+
includeOnlyFilter := "job:dedicated-node,source_type:other"
277+
excludeAlwaysFilter := "source_type:other,origin:rep"
278+
assert.False(t, WantedEvent(buf.String(), includeOnlyFilter, excludeAlwaysFilter), "This Event should not be included")
279+
}
280+
281+
func TestSendIncludeExcludeFilterAppNotMatchAnyFilter(t *testing.T) {
282+
eventToExclude := Event{
283+
Fields: map[string]interface{}{
284+
"message_type": "OUT",
285+
"source_instance": 0,
286+
"deployment": "cf",
287+
"ip": "10.193.166.47",
288+
"job": "diego_cell",
289+
"job_index": "c62aebe5-16b8-43f5-a589-1267e09b9537",
290+
"cf_ignored_app": "false",
291+
"timestamp": "2017-01-10 17:31:02.662133274 -0300 CLST",
292+
"source_type": "APP",
293+
"origin": "rep",
294+
"cf_app_id": "7833dc75-4484-409c-9b74-90b6454906c6",
295+
},
296+
Msg: "Triggering 'app usage events fetcher'",
297+
Type: "LogMessage",
298+
}
299+
message, err := json.Marshal(eventToExclude)
300+
var msg []byte
301+
if err == nil {
302+
msg = message
303+
}
304+
buf := new(bytes.Buffer)
305+
buf.Write(msg)
306+
includeOnlyFilter := "job:dedicated-node,source_type:other"
307+
excludeAlwaysFilter := "source_type:other,origin:reps"
308+
assert.True(t, WantedEvent(buf.String(), includeOnlyFilter, excludeAlwaysFilter), "This Event should be included")
309+
}
310+
220311
func TestSendNoFilter(t *testing.T) {
221312
eventToExclude := Event{
222313
Fields: map[string]interface{}{

0 commit comments

Comments
 (0)