Skip to content

Commit

Permalink
hotfix: added object literal check for drop events filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Adnan Rahic committed Apr 7, 2021
1 parent 60a5ae4 commit 31de82f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
36 changes: 14 additions & 22 deletions config/examples/kubernetes-containerd-with-drop-events.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,26 @@ input:

inputFilter:
inputFilterK8sContainerd:
module: input-filter-k8s-containerd # Only needed when running in K8s env with Containerd/CRI-O container runtime

grep:
module: grep
config:
matchSource: !!js/regexp /.*log/ # match log files
include: !!js/regexp /.*/i # include errors
exclude: !!js/regexp /ping/i # exclude noise
module: input-filter-k8s-containerd # Only needed when running in K8s env with Containerd/CRI-O container runtime

outputFilter:
kubernetesEnrichment:
module: kubernetes-enrichment

dropEvents:
module: drop-events
debug: true
filters:
message:
exclude: !!js/regexp /health/i
req:
exclude: !!js/regexp /debug|ping|health/i

output:
stdout: yaml

# elasticsearch:
# module: elasticsearch
# url: https://logsene-receiver.sematext.com
# # index: de1135be-xxxx-xxxx-xxxx-365c63d5aff2
# indices:
# c332463a-xxxx-xxxx-xxxx-535d18521418:
# - app.*\.log
# c1590c8b-xxxx-xxxx-xxxx-10f8f8281b3d:
# - kube-apiserver.*\.log
# stdout: yaml
elasticsearch:
module: elasticsearch
url: https://logsene-receiver.sematext.com
# index: de1135be-xxxx-xxxx-xxxx-365c63d5aff2
indices:
c332463a-xxxx-xxxx-xxxx-535d18521418:
- app.*\.log
c1590c8b-xxxx-xxxx-xxxx-10f8f8281b3d:
- kube-apiserver.*\.log
31 changes: 22 additions & 9 deletions lib/plugins/output-filter/dropEventsFilter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
var consoleLogger = require('../../util/logger.js')

function testCondition (data, fieldName, condition) {
return condition.test(String(data[fieldName]))
const value = data[fieldName]

const isObj = isLiteralObject(value)
if (isObj) {
console.log(JSON.stringify(value))
return condition.test(JSON.stringify(value))
}

console.log(String(value))
return condition.test(String(value))
}

function isLiteralObject (a) {
return !!a && a.constructor === Object
}

function logStatus (debug, a, b, c, d) {
if (debug != false) {
consoleLogger.debug(
function logStatus (data, debug, a, b, c, d) {
if (debug) {
console.log(
`drop-events plugin: ${a} ${b} ${c} ${d}`.replace(/undefined/g, '-')
)
}
Expand All @@ -28,6 +39,7 @@ function dropEventsFilter (context, config, eventEmitter, data, callback) {
if (config.filters[config.keys[i]].include) {
drop = !testCondition(data, config.keys[i], include) || drop
logStatus(
data,
debug,
config.keys[i],
'include',
Expand All @@ -38,6 +50,7 @@ function dropEventsFilter (context, config, eventEmitter, data, callback) {
if (config.filters[config.keys[i]].exclude) {
drop = testCondition(data, config.keys[i], exclude) || drop
logStatus(
data,
debug,
config.keys[i],
'exclude',
Expand All @@ -49,17 +62,17 @@ function dropEventsFilter (context, config, eventEmitter, data, callback) {
logStatus(debug, 'filter result', drop)
if (drop) {
if (debug) {
logStatus(debug, 'drop', JSON.stringify(data))
logStatus(data, debug, 'drop', JSON.stringify(data))
}
return callback(new Error('drop filter'))
} else {
if (debug) {
logStatus(debug, 'pass', JSON.stringify(data))
logStatus(data, debug, 'pass', JSON.stringify(data))
}
return callback(null, data)
}
} catch (ex) {
logStatus(debug, 'exceptoion', ex)
logStatus(data, debug, 'exceptoion', ex)
// pass events in case of error
return callback(null, data)
}
Expand Down

0 comments on commit 31de82f

Please sign in to comment.