Skip to content

Commit

Permalink
cleanup; added comments; removed consolelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanrahic committed Jun 3, 2020
1 parent 159223f commit e68de73
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 113 deletions.
2 changes: 0 additions & 2 deletions bin/logagent.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ var moduleAlias = {
// input filters
'input-filter-k8s-containerd':
'../lib/plugins/input-filter/kubernetesContainerd.js',
'input-filter-k8s-containerd-multiline':
'../lib/plugins/input-filter/kubernetesContainerdMultiline.js',
grep: '../lib/plugins/input-filter/grep.js',
grok: 'logagent-input-filter-grok',
// output filters
Expand Down
56 changes: 24 additions & 32 deletions lib/plugins/input-filter/kubernetesContainerd.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
var containerdSplitRegexp = /^(.+[stdout|stderr] [F|P]) /
const containerdSplitRegexp = /^(.+[stdout|stderr] [F|P]) /

// Dictionary to store sources and log lines
/**
* Key: sourceName
* Value (Object): { streamFlag, previousStreamFlag, logLines }
*/
const sources = {}

/**
* sourceName - origin of the log, e.g. file name
* config - properties from the config section for this plugin
* data - the log message as string
* callback - callback function (err, data).
*/

// fileName: app-77b4d5595b-hmjxs_default_app-80209fd578c6be842b5b8a2d6389227ccab0196b7b658bd245eed4767c9b843c.log
// meta: {
// 0: app-77b4d5595b-hmjxs, // pod
// 1: default // namespace
// 2: app-80209fd578c6be842b5b8a2d6389227ccab0196b7b658bd245eed4767c9b843c.log // container with .log suffix
// }

function parseK8sFileName (sourceName) {
/**
* SAMPLE sourceName *
* ***************** *
* sourceName: /var/log/containers/app-77b4d5595b-hmjxs_default_app-80209fd578c6be842b5b8a2d6389227ccab0196b7b658bd245eed4767c9b843c.log
* fileName: app-77b4d5595b-hmjxs_default_app-80209fd578c6be842b5b8a2d6389227ccab0196b7b658bd245eed4767c9b843c.log
* meta: {
* 0: app-77b4d5595b-hmjxs, // pod
* 1: default // namespace
* 2: app-80209fd578c6be842b5b8a2d6389227ccab0196b7b658bd245eed4767c9b843c.log // container with .log suffix
* }
*/

// cut path from /var/log/containers/<pod_name>_<pod_namespace>_<container_name>-<container_id>.log
// Reference: https://github.com/kubernetes/community/blob/master/contributors/design-proposals/node/kubelet-cri-logging.md
var index = sourceName.lastIndexOf('/')
var fileName = sourceName.substr(index + 1, sourceName.length)
var meta = fileName.split('_')
var info = {}
const index = sourceName.lastIndexOf('/')
const fileName = sourceName.substr(index + 1, sourceName.length)
const meta = fileName.split('_')
const info = {}

if (meta.length === 3) {
const { 0: name, 1: namespace, 2: containerWithLogSuffix } = meta
Expand Down Expand Up @@ -69,12 +80,6 @@ module.exports = function (context, config, data, callback) {
}
sources[sourceName].streamFlag = k8sInfo.streamFlag

console.log('\n\n\n\n\n\n\n\n\n\n\n\n')
console.log('BEFORE')
console.log(sourceName)
console.log(sources[sourceName])
console.log('\n\n\n\n\n\n\n\n\n\n\n\n')

if (sources[sourceName].streamFlag === 'P') {
if (sources[sourceName].logLines === undefined) {
sources[sourceName].logLines = []
Expand All @@ -83,12 +88,6 @@ module.exports = function (context, config, data, callback) {
sources[sourceName].logLines.push(logLine)
sources[sourceName].previousStreamFlag = 'P'

console.log('\n\n\n\n\n\n\n\n\n\n\n\n')
console.log('PARTIAL')
console.log(sourceName)
console.log(sources[sourceName])
console.log('\n\n\n\n\n\n\n\n\n\n\n\n')

return callback(null, null)
}

Expand All @@ -98,10 +97,6 @@ module.exports = function (context, config, data, callback) {
) {
sources[sourceName].logLines.push(logLine)
const joinedLogLine = sources[sourceName].logLines.join(' ')
console.log('\n\n\n\n\n\n\n\n\n\n\n\n')
console.log('FULL')
console.log(sources[sourceName])
console.log('\n\n\n\n\n\n\n\n\n\n\n\n')
delete sources[sourceName]

// a special property in context object to propagate fields to
Expand All @@ -111,9 +106,6 @@ module.exports = function (context, config, data, callback) {
}
}

console.log('\n\n\n\n\n\n\n\n\n\n\n\n\n')
console.log(logLine)
console.log('\n\n\n\n\n\n\n\n\n\n\n\n\n')
return callback(null, logLine)
}
return callback(null, data)
Expand Down
79 changes: 0 additions & 79 deletions lib/plugins/input-filter/kubernetesContainerdMultiline.js

This file was deleted.

0 comments on commit e68de73

Please sign in to comment.