@@ -257,19 +257,25 @@ class ApiGateway {
257
257
return new SubscriptionServer ( this , sendMessage , this . subscriptionStore ) ;
258
258
}
259
259
260
+ duration ( requestStarted ) {
261
+ return new Date ( ) . getTime ( ) - requestStarted . getTime ( ) ;
262
+ }
263
+
260
264
async meta ( { context, res } ) {
265
+ const requestStarted = new Date ( ) ;
261
266
try {
262
267
const metaConfig = await this . getCompilerApi ( context ) . metaConfig ( ) ;
263
268
const cubes = metaConfig . map ( c => c . config ) ;
264
269
res ( { cubes } ) ;
265
270
} catch ( e ) {
266
271
this . handleError ( {
267
- e, context, res
272
+ e, context, res, requestStarted
268
273
} ) ;
269
274
}
270
275
}
271
276
272
277
async sql ( { query, context, res } ) {
278
+ const requestStarted = new Date ( ) ;
273
279
try {
274
280
query = this . parseQueryParam ( query ) ;
275
281
const normalizedQuery = await this . queryTransformer ( normalizeQuery ( query ) , context ) ;
@@ -282,12 +288,13 @@ class ApiGateway {
282
288
} ) ;
283
289
} catch ( e ) {
284
290
this . handleError ( {
285
- e, context, query, res
291
+ e, context, query, res, requestStarted
286
292
} ) ;
287
293
}
288
294
}
289
295
290
296
async load ( { query, context, res } ) {
297
+ const requestStarted = new Date ( ) ;
291
298
try {
292
299
query = this . parseQueryParam ( query ) ;
293
300
this . log ( context , {
@@ -300,6 +307,11 @@ class ApiGateway {
300
307
this . getCompilerApi ( context ) . metaConfig ( )
301
308
] ) ;
302
309
const sqlQuery = compilerSqlResult ;
310
+ this . log ( context , {
311
+ type : 'Load Request SQL' ,
312
+ query,
313
+ sqlQuery
314
+ } ) ;
303
315
const annotation = prepareAnnotation ( metaConfigResult , normalizedQuery ) ;
304
316
const aliasToMemberNameMap = sqlQuery . aliasNameToMember ;
305
317
const toExecute = {
@@ -315,6 +327,7 @@ class ApiGateway {
315
327
this . log ( context , {
316
328
type : 'Load Request Success' ,
317
329
query,
330
+ duration : this . duration ( requestStarted )
318
331
} ) ;
319
332
const flattenAnnotation = {
320
333
...annotation . measures ,
@@ -333,14 +346,15 @@ class ApiGateway {
333
346
} ) ;
334
347
} catch ( e ) {
335
348
this . handleError ( {
336
- e, context, query, res
349
+ e, context, query, res, requestStarted
337
350
} ) ;
338
351
}
339
352
}
340
353
341
354
async subscribe ( {
342
355
query, context, res, subscribe, subscriptionState
343
356
} ) {
357
+ const requestStarted = new Date ( ) ;
344
358
try {
345
359
this . log ( context , {
346
360
type : 'Subscribe' ,
@@ -358,24 +372,24 @@ class ApiGateway {
358
372
await this . load ( {
359
373
query,
360
374
context,
361
- res : ( message ) => {
375
+ res : ( message , opts ) => {
362
376
if ( message . error ) {
363
- error = message ;
377
+ error = { message, opts } ;
364
378
} else {
365
- result = message ;
379
+ result = { message, opts } ;
366
380
}
367
381
}
368
382
} ) ;
369
383
const state = await subscriptionState ( ) ;
370
384
if ( result && ( ! state || JSON . stringify ( state . result ) !== JSON . stringify ( result ) ) ) {
371
- res ( result ) ;
385
+ res ( result . message , result . opts ) ;
372
386
} else if ( error ) {
373
- res ( error ) ;
387
+ res ( error . message , error . opts ) ;
374
388
}
375
389
await subscribe ( { error, result } ) ;
376
390
} catch ( e ) {
377
391
this . handleError ( {
378
- e, context, query, res
392
+ e, context, query, res, requestStarted
379
393
} ) ;
380
394
}
381
395
}
@@ -413,34 +427,38 @@ class ApiGateway {
413
427
}
414
428
415
429
handleError ( {
416
- e, context, query, res
430
+ e, context, query, res, requestStarted
417
431
} ) {
418
432
if ( e instanceof UserError ) {
419
433
this . log ( context , {
420
434
type : 'User Error' ,
421
435
query,
422
- error : e . message
436
+ error : e . message ,
437
+ duration : this . duration ( requestStarted )
423
438
} ) ;
424
439
res ( { error : e . message } , { status : 400 } ) ;
425
440
} else if ( e . error === 'Continue wait' ) {
426
441
this . log ( context , {
427
442
type : 'Continue wait' ,
428
443
query,
429
- error : e . message
444
+ error : e . message ,
445
+ duration : this . duration ( requestStarted )
430
446
} ) ;
431
447
res ( e , { status : 200 } ) ;
432
448
} else if ( e . error ) {
433
449
this . log ( context , {
434
450
type : 'Orchestrator error' ,
435
451
query,
436
- error : e . error
452
+ error : e . error ,
453
+ duration : this . duration ( requestStarted )
437
454
} ) ;
438
455
res ( e , { status : 400 } ) ;
439
456
} else {
440
457
this . log ( context , {
441
458
type : 'Internal Server Error' ,
442
459
query,
443
- error : e . stack || e . toString ( )
460
+ error : e . stack || e . toString ( ) ,
461
+ duration : this . duration ( requestStarted )
444
462
} ) ;
445
463
res ( { error : e . toString ( ) } , { status : 500 } ) ;
446
464
}
0 commit comments