Skip to content

Commit 18e294a

Browse files
committed
Open buff2String to everyone
fix all the stream stuff so we can start saving logs to s3
1 parent 338b7d7 commit 18e294a

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

lib/socket/common-stream.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ function pipeLogsToClient (clientStream, baseDataName, tags, containerId, opts)
152152
}
153153

154154
module.exports = {
155+
buff2StringTransform: buff2StringTransform,
155156
onValidateFailure: onValidateFailure,
156157
pipeLogsToClient: pipeLogsToClient,
157158
pipeAndEndOnError: pipeAndEndOnError,

lib/workers/container.logs.store.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Handle instance container died event
3-
* @module lib/workers/application.container.died
2+
* Handle instance container log store events
3+
* @module lib/workers/container.log.store
44
*/
55
'use strict'
66

@@ -10,13 +10,12 @@ const joi = require('utils/joi')
1010
const logger = require('logger')
1111
const WorkerStopError = require('error-cat/errors/worker-stop-error')
1212
const commonStream = require('socket/common-stream')
13-
const through2 = require('through2')
13+
const Through2 = require('through2')
1414
const aws = require('aws-sdk')
1515
const Docker = require('models/apis/docker')
1616

1717
const s3 = new aws.S3()
1818

19-
2019
module.exports.jobSchema = joi.object({
2120
containerId: joi.string().required()
2221
}).unknown().required()
@@ -34,26 +33,13 @@ module.exports.task = (job) => {
3433
bucket: `${process.env.NODE_ENV}.container-logs`,
3534
key: job.containerId
3635
}, 'Began piping logs')
37-
38-
const cleanedStream = new through2({objectMode:true})
39-
40-
cleanedStream.on('error', (err) => {
41-
log.error({err}, 'Stream error')
42-
})
43-
cleanedStream.on('end', () => {
44-
log.trace('Cleaned stream ended')
45-
})
46-
cleanedStream.on('data', (data) => {
47-
log.trace({data: data.toString()}, 'Got actual stream data')
48-
})
49-
36+
const cleanedStream = new Through2({}, commonStream.buff2StringTransform)
5037
commonStream.connectStream(dockerLogStream, cleanedStream, log)
5138

5239
dockerLogStream.on('end', () => {
5340
log.trace('Dockerlog stream ended')
5441
cleanedStream.end()
5542
})
56-
5743
// Send stream to s3
5844
return s3.upload({
5945
Bucket: `${process.env.NODE_ENV}.container-logs`,

0 commit comments

Comments
 (0)