@@ -6,6 +6,7 @@ const logger = require('pelias-logger').get('api');
66const Debug = require ( '../helper/debug' ) ;
77const debugLog = new Debug ( 'controller:place' ) ;
88
9+ // @todo : remove this and replace with the predicate
910function requestHasErrors ( request ) {
1011 return _ . get ( request , 'errors' , [ ] ) . length > 0 ;
1112}
@@ -34,20 +35,19 @@ function setup( apiConfig, esclient ){
3435 const operation = retry . operation ( operationOptions ) ;
3536
3637 //generate Elasticsearch mget entries based on GID
37- const cmd = req . clean . ids . map ( function ( id ) {
38+ const cmd = req . clean . ids . map ( ( id ) => {
3839 return {
3940 _index : apiConfig . indexName ,
4041 _id : `${ id . source } :${ id . layer } :${ id . id } `
4142 } ;
4243 } ) ;
4344
44- logger . debug ( '[ES req]' , cmd ) ;
45- debugLog . push ( req , { ES_req : cmd } ) ;
45+ logger . debug ( '[ES req]' , cmd ) ;
4646
4747 operation . attempt ( ( currentAttempt ) => {
48- const initialTime = debugLog . beginTimer ( req ) ;
48+ const start = Date . now ( ) ;
4949
50- mgetService ( esclient , cmd , function ( err , docs , data ) {
50+ mgetService ( esclient , cmd , ( err , docs , data ) => {
5151 const message = {
5252 controller : 'place' ,
5353 queryType : 'place' ,
@@ -62,7 +62,10 @@ function setup( apiConfig, esclient ){
6262 // (handles bookkeeping of maxRetries)
6363 // only consider for status 408 (request timeout)
6464 if ( isRequestTimeout ( err ) && operation . retry ( err ) ) {
65- debugLog . stopTimer ( req , initialTime , `request timed out on attempt ${ currentAttempt } , retrying` ) ;
65+ debugLog . push ( req , {
66+ error : `request timed out on attempt ${ currentAttempt } , retrying` ,
67+ duration : Date . now ( ) - start
68+ } ) ;
6669 return ;
6770 }
6871
@@ -88,7 +91,10 @@ function setup( apiConfig, esclient ){
8891
8992 next ( ) ;
9093 } ) ;
91- debugLog . stopTimer ( req , initialTime ) ;
94+ debugLog . push ( req , {
95+ ES_req : cmd ,
96+ duration : Date . now ( ) - start
97+ } ) ;
9298 } ) ;
9399
94100 }
0 commit comments