@@ -4,9 +4,13 @@ const promiseRetry = require('promise-retry');
4
4
const logger = require ( 'cf-logs' ) . Logger ( 'codefresh:containerLogger' ) ;
5
5
const CFError = require ( 'cf-errors' ) ;
6
6
const { Transform } = require ( 'stream' ) ;
7
+
7
8
const _ = require ( 'lodash' ) ;
8
9
const { LoggerStrategy } = require ( './enums' ) ;
9
10
11
+ // eslint-disable-next-line import/no-unresolved
12
+ const { DeprecatedImagesInterceptorStream } = require ( './metric/deprecated-images/deprecated-images-interceptor.stream' ) ;
13
+
10
14
const CONTAINER_START_RETRY_TIMEOUT_SECONDS = 1 ;
11
15
const CONTAINER_START_RETRY_LIMIT = 10 ;
12
16
const BUFFER_SIZE = 2 * 1024 * 1024 ; // 2 MiB
@@ -131,6 +135,7 @@ class ContainerLogger extends EventEmitter {
131
135
// { end = false } on the stepLoggerWritableStream because there is only one instance of it for all the steps.
132
136
this . handledStreams ++ ;
133
137
let stdoutStream = stdout
138
+ . pipe ( new DeprecatedImagesInterceptorStream ( ) )
134
139
. pipe ( this . _logSizeLimitStream ( ) )
135
140
. pipe ( this . stepLogger . createMaskingStream ( ) ) ;
136
141
@@ -148,6 +153,7 @@ class ContainerLogger extends EventEmitter {
148
153
149
154
this . handledStreams ++ ;
150
155
let stderrStream = stderr
156
+ . pipe ( new DeprecatedImagesInterceptorStream ( ) )
151
157
. pipe ( this . _logSizeLimitStream ( ) )
152
158
. pipe ( this . _errorTransformerStream ( ) )
153
159
. pipe ( this . stepLogger . createMaskingStream ( ) ) ;
@@ -180,27 +186,38 @@ class ContainerLogger extends EventEmitter {
180
186
181
187
_handleTtyStream ( stream , isError ) {
182
188
this . handledStreams ++ ;
183
- stream . on ( 'end' , this . _handleFinished . bind ( this ) ) ;
189
+ const deprecatedImagesInterceptor = new DeprecatedImagesInterceptorStream ( true ) ;
190
+ stream . on ( 'end' , ( ) => {
191
+ this . _handleFinished ( ) ;
192
+ deprecatedImagesInterceptor . end ( ) ;
193
+ } ) ;
184
194
stream . on ( 'data' , ( chunk ) => {
195
+ deprecatedImagesInterceptor . write ( chunk ) ;
185
196
this . _logMessage ( Buffer . from ( chunk ) . toString ( 'utf-8' ) , isError ) ;
186
197
} ) ;
187
198
logger . info ( `Listening on stream 'data' event for container: ${ this . containerId } ` ) ;
188
199
}
189
200
190
201
_handleNonTtyStream ( stream , isError ) {
191
202
this . handledStreams ++ ;
203
+ const deprecatedImagesInterceptor = new DeprecatedImagesInterceptorStream ( true ) ;
192
204
stream . on ( 'readable' , ( ) => {
193
205
let header = stream . read ( 8 ) ;
194
206
while ( header !== null ) {
207
+ deprecatedImagesInterceptor . write ( header ) ;
195
208
const payload = stream . read ( header . readUInt32BE ( 4 ) ) ;
196
209
if ( payload === null ) {
197
210
break ;
198
211
}
212
+ deprecatedImagesInterceptor . write ( payload ) ;
199
213
this . _logMessage ( Buffer . from ( payload ) . toString ( 'utf8' ) , isError ) ;
200
214
header = stream . read ( 8 ) ;
201
215
}
202
216
} ) ;
203
- stream . on ( 'end' , this . _handleFinished . bind ( this ) ) ;
217
+ stream . on ( 'end' , ( ) => {
218
+ this . _handleFinished ( ) ;
219
+ deprecatedImagesInterceptor . end ( ) ;
220
+ } ) ;
204
221
logger . info ( `Listening on stream 'readable' event for container: ${ this . containerId } ` ) ;
205
222
}
206
223
0 commit comments