Skip to content

Commit 6a7f44e

Browse files
committed
separated LOGS_RECEIVER_URL and LOGS_RECEIVER_URLS in the config; use singular for only one URL or the plural when configuring multiple endpoints
1 parent 2389bfc commit 6a7f44e

3 files changed

Lines changed: 37 additions & 17 deletions

File tree

lib/plugins/input/docker/dockerInspect.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,34 @@ function getLogseneEnabled (info) {
169169
info.LOGSENE_TOKEN = token || process.env.LOGS_TOKEN || process.env.LOGSENE_TOKEN
170170

171171
// get optional log receiver URLs
172-
let logsReceiver = null
173-
if (info.Config && info.Config.Labels && info.Config.Labels.LOGS_RECEIVER_URL) {
174-
logsReceiver = info.Config.Labels.LOGS_RECEIVER_URL
172+
let logsReceivers = null
173+
if (info.Config && info.Config.Labels && info.Config.Labels.LOGS_RECEIVER_URLS) {
174+
logsReceivers = info.Config.Labels.LOGS_RECEIVER_URLS
175175
} else {
176-
logsReceiver = getEnvVar('LOGS_RECEIVER_URL', info.Config.Env)
176+
logsReceivers = getEnvVar('LOGS_RECEIVER_URLS', info.Config.Env)
177+
}
178+
if (logsReceivers) {
179+
info.LOGS_RECEIVER_URLS = parser.parseReceiverList(logsReceivers)
177180
}
178-
if (logsReceiver) {
179-
info.logsReceiver = parser.parseReceiverList(logsReceiver)
181+
182+
// get optional log receiver
183+
if (info.Config && info.Config.Labels && info.Config.Labels.LOGS_RECEIVER_URL) {
184+
info.LOGS_RECEIVER_URL = info.Config.Labels.LOGS_RECEIVER_URL
185+
} else {
186+
info.LOGS_RECEIVER_URL = getEnvVar('LOGS_RECEIVER_URL', info.Config.Env)
180187
}
188+
181189
// get optional logs target name
182190
if (info.Config && info.Config.Labels && info.Config.Labels.LOGS_DESTINATION) {
183191
info.LOGS_DESTINATION = info.Config.Labels.LOGS_DESTINATION
184192
} else {
185193
info.LOGS_DESTINATION = getEnvVar('LOGS_DESTINATION', info.Config.Env)
186194
}
195+
196+
console.log('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n')
197+
console.log(info)
198+
console.log('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n')
199+
187200
return info
188201
}
189202

lib/plugins/output-filter/docker-log-enrichment.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,19 @@ module.exports = function enrichDockerLogs (context, config, eventEmitter, data,
9393
data.swarm = swarmInfo
9494
}
9595
}
96-
// set logs receiver url for output plugins
97-
if (context.dockerInspect && context.dockerInspect.logsReceiver) {
98-
context.logsReceiver = context.dockerInspect.logsReceiver
96+
// set logs receiver urls for output plugins when you have multiple URLS
97+
if (context.dockerInspect && context.dockerInspect.logsReceivers) {
98+
context.logsReceivers = context.dockerInspect.LOGS_RECEIVER_URLS
99+
}
100+
// set logs receiver urls for output plugins when you have one URL
101+
if (context.dockerInspect && context.dockerInspect.LOGS_RECEIVER_URL) {
102+
context.logsReceiver = context.dockerInspect.LOGS_RECEIVER_URL
99103
}
100104
// set logs destination / name of ES output module
101105
if (context.dockerInspect && context.dockerInspect.LOGS_DESTINATION) {
102106
context.logsDestination = context.dockerInspect.LOGS_DESTINATION
103107
}
108+
104109
var logObject = data
105110
// make sure that top level message field is a String
106111
var messageString = logObject.message || logObject.msg || logObject.MESSAGE

lib/plugins/output/elasticsearch.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ OutputElasticsearch.prototype.eventHandler = function (data, context) {
106106
if (context.logsDestination && this.config.configName && this.config.configName.indexOf(context.logsDestination) === -1) {
107107
return
108108
}
109-
var config = reduceConfig(context, data, this.config)
110-
var index = data._index || context.index || config.index || process.env.LOGSENE_TOKEN || process.env.LOGS_TOKEN
109+
const config = reduceConfig(context, data, this.config)
110+
let index = data._index || context.index || config.index || process.env.LOGSENE_TOKEN || process.env.LOGS_TOKEN
111+
const logsReceiverUrl = context.logsReceiver || process.env.LOGS_RECEIVER_URL
111112

112113
if (config.tokenMapper) {
113114
if (config.dropLogsForUnmatchedIndices === true) {
@@ -116,16 +117,17 @@ OutputElasticsearch.prototype.eventHandler = function (data, context) {
116117
index = config.tokenMapper.findToken(data.logSource || context.sourceName) || index
117118
}
118119
}
120+
119121
if (index) {
120-
// support for time-based index patterns
121122
index = applyDateFormatToIndex(index, data)
122-
this.indexData(index, data._type || 'logs', data, config, context.logsReceiverUrl)
123+
this.indexData(index, data._type || 'logs', data, config, logsReceiverUrl)
123124
}
124-
if (context.logsReceiver && context.logsReceiver.length > 0) {
125-
for (let i = 0; i < context.logsReceiver.length; i++) {
125+
126+
if (context.logsReceivers && context.logsReceivers.length > 0) {
127+
for (let i = 0; i < context.logsReceivers.length; i++) {
126128
this.indexData(
127-
applyDateFormatToIndex(context.logsReceiver[i].index, data),
128-
data._type || 'logs', data, config, context.logsReceiver[i].url)
129+
applyDateFormatToIndex(context.logsReceivers[i].index, data),
130+
data._type || 'logs', data, config, context.logsReceivers[i].url)
129131
}
130132
}
131133
}

0 commit comments

Comments
 (0)