@@ -180,7 +180,7 @@ class Logger {
180
180
* @param docker
181
181
* @param newContainer
182
182
*/
183
- async _handleContainer ( container ) { // jshint ignore:line
183
+ async _handleContainer ( container , loggerStrategy ) { // jshint ignore:line
184
184
const containerId = container . Id || container . id ;
185
185
const containerStatus = container . Status || container . status ;
186
186
const receivedLoggerId = _ . get ( container , 'Labels' , _ . get ( container , 'Actor.Attributes' ) ) [ 'io.codefresh.logger.id' ] ;
@@ -189,7 +189,13 @@ class Logger {
189
189
const receivedLogSizeLimit = _ . get ( container ,
190
190
'Labels' ,
191
191
_ . get ( container , 'Actor.Attributes' ) ) [ 'io.codefresh.logger.logSizeLimit' ] ;
192
- const loggerStrategy = _ . get ( container , 'Labels' , _ . get ( container , 'Actor.Attributes' ) ) [ 'io.codefresh.logger.strategy' ] ;
192
+ const maxRetryAttempts = 10 ;
193
+ const retryInterval = 1000 ;
194
+ var retryCount = 0 ;
195
+
196
+ if ( ! loggerStrategy ) {
197
+ loggerStrategy = _ . get ( container , 'Labels' , _ . get ( container , 'Actor.Attributes' ) ) [ 'io.codefresh.logger.strategy' ] ;
198
+ }
193
199
194
200
if ( ! containerId ) {
195
201
logger . error ( `Not handling container because id is missing` ) ;
@@ -256,16 +262,27 @@ class Logger {
256
262
containerLogger . once ( 'end' , this . _handleContainerStreamEnd . bind ( this ) ) ;
257
263
258
264
containerLogger . start ( )
259
- . done ( ( ) => {
260
- this . state . containers [ containerId ] = { status : ContainerHandlingStatus . LISTENING } ;
265
+ . then ( ( ) => {
266
+ this . state [ containerId ] = { status : ContainerHandlingStatus . LISTENING } ;
261
267
this . _writeNewState ( ) ;
262
- } , ( err ) => {
268
+ } )
269
+ . catch ( async ( err ) => {
263
270
const error = new CFError ( {
264
271
cause : err ,
265
272
message : `Failed to start logging for container:${ containerId } ` ,
266
273
containerId
267
274
} ) ;
268
275
logger . error ( error . toString ( ) ) ;
276
+
277
+ if ( retryCount !== maxRetryAttempts ) {
278
+ retryCount ++ ;
279
+ logger . warn ( `Making another attempt switching to the "${ LoggerStrategy . LOGS } " logging strategy` ) ;
280
+
281
+ await new Promise ( r => setTimeout ( r , retryInterval ) ) ;
282
+
283
+ delete this . state . containers [ containerId ] ;
284
+ await this . _handleContainer ( container , LoggerStrategy . LOGS ) ;
285
+ }
269
286
} ) ;
270
287
}
271
288
0 commit comments