@contember/engine-http 2.1.0-alpha.3 → 2.1.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/engine-http",
3
- "version": "2.1.0-alpha.3",
3
+ "version": "2.1.0-alpha.4",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/production/index.js",
6
6
  "typings": "./dist/types/index.d.ts",
@@ -26,20 +26,20 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@contember/config-loader": "2.1.0-alpha.3",
30
- "@contember/database": "2.1.0-alpha.3",
31
- "@contember/database-migrations": "2.1.0-alpha.3",
32
- "@contember/dic": "2.1.0-alpha.3",
33
- "@contember/engine-common": "2.1.0-alpha.3",
34
- "@contember/engine-content-api": "2.1.0-alpha.3",
35
- "@contember/engine-system-api": "2.1.0-alpha.3",
36
- "@contember/engine-tenant-api": "2.1.0-alpha.3",
37
- "@contember/graphql-utils": "2.1.0-alpha.3",
38
- "@contember/logger": "2.1.0-alpha.3",
39
- "@contember/schema": "2.1.0-alpha.3",
40
- "@contember/schema-migrations": "2.1.0-alpha.3",
41
- "@contember/schema-utils": "2.1.0-alpha.3",
42
- "@contember/typesafe": "2.1.0-alpha.3",
29
+ "@contember/config-loader": "2.1.0-alpha.4",
30
+ "@contember/database": "2.1.0-alpha.4",
31
+ "@contember/database-migrations": "2.1.0-alpha.4",
32
+ "@contember/dic": "2.1.0-alpha.4",
33
+ "@contember/engine-common": "2.1.0-alpha.4",
34
+ "@contember/engine-content-api": "2.1.0-alpha.4",
35
+ "@contember/engine-system-api": "2.1.0-alpha.4",
36
+ "@contember/engine-tenant-api": "2.1.0-alpha.4",
37
+ "@contember/graphql-utils": "2.1.0-alpha.4",
38
+ "@contember/logger": "2.1.0-alpha.4",
39
+ "@contember/schema": "2.1.0-alpha.4",
40
+ "@contember/schema-migrations": "2.1.0-alpha.4",
41
+ "@contember/schema-utils": "2.1.0-alpha.4",
42
+ "@contember/typesafe": "2.1.0-alpha.4",
43
43
  "@graphql-tools/merge": "^9.0.8",
44
44
  "@graphql-tools/schema": "^10.0.7",
45
45
  "@koa/cors": "^5.0.0",
@@ -14,6 +14,8 @@ import stream, { Duplex, Readable } from 'node:stream'
14
14
  import { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver'
15
15
  import { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer'
16
16
  import { URL } from 'node:url'
17
+ import { cpuUsage, memoryUsage } from 'node:process'
18
+ import { performance } from 'node:perf_hooks'
17
19
 
18
20
  type Route<C> = { match: RequestMatcher; controller: C; module: string }
19
21
  export class Application {
@@ -139,7 +141,7 @@ export class Application {
139
141
  const ws = await new Promise<WebSocket>(resolve => wss.handleUpgrade(req, socket, head, (ws, request) => {
140
142
  resolve(ws)
141
143
  }))
142
- const wsEstablished = new Date().getTime()
144
+ const wsEstablished = performance.now()
143
145
  webSocketContext = {
144
146
  ws,
145
147
  abortSignal,
@@ -155,14 +157,14 @@ export class Application {
155
157
  requestLogger.debug('Websocket connection established')
156
158
  ws.on('error', e => {
157
159
  requestLogger.error(e, {
158
- websocketOpenMs: new Date().getTime() - wsEstablished,
160
+ websocketOpenMs: performance.now() - wsEstablished,
159
161
  })
160
162
  })
161
163
 
162
164
  return new Promise<void>(resolve => {
163
165
  ws.on('close', () => {
164
166
  requestLogger.debug('Websocket connection closed', {
165
- websocketOpenMs: new Date().getTime() - wsEstablished,
167
+ websocketOpenMs: performance.now() - wsEstablished,
166
168
  })
167
169
  resolve()
168
170
  })
@@ -331,10 +333,12 @@ export class Application {
331
333
 
332
334
  private createTimer() {
333
335
  const times: EventTime[] = []
334
- const globalStart = new Date().getTime()
336
+ const globalStart = performance.now()
337
+ const cpuUsageStart = cpuUsage()
338
+ const memoryUsageStart = memoryUsage()
335
339
  const timer: Timer = (name: string, cb) => {
336
- const start = new Date().getTime()
337
- const time: EventTime = { label: name, start: start - globalStart }
340
+ const start = performance.now()
341
+ const time: EventTime = { label: name, start: Math.round(start - globalStart) }
338
342
  times.push(time)
339
343
  const res = cb()
340
344
 
@@ -344,7 +348,7 @@ export class Application {
344
348
  await res
345
349
  } catch {
346
350
  } finally {
347
- time.duration = new Date().getTime() - start
351
+ time.duration = Math.round(performance.now() - start)
348
352
  }
349
353
  })()
350
354
  }
@@ -357,16 +361,24 @@ export class Application {
357
361
  }
358
362
 
359
363
  const emit = () => {
360
- const total = new Date().getTime() - globalStart
364
+ const total = performance.now() - globalStart
361
365
  const timeLabel = total > 500 ? 'TIME_SLOW' : 'TIME_OK'
362
366
  const shouldSuppress = this.suppressAccessLog === true || !ctx.req.url || (this.suppressAccessLog !== false && this.suppressAccessLog.test(ctx.req.url))
363
367
 
368
+ const cpuUsageEnd = cpuUsage()
369
+ const memoryUsageEnd = memoryUsage()
370
+
371
+ const cpuUsageDiffMs = (cpuUsageEnd.user - cpuUsageStart.user) / 1000
372
+ const memoryUsageDiff = memoryUsageEnd.heapUsed - memoryUsageStart.heapUsed
364
373
  const level = shouldSuppress ? 'debug' : 'info'
365
374
  ctx.logger.log(level, !ctx.response ? 'Connection established' : ctx.response.statusCode < 400 ? `Request successful` : 'Request failed', {
366
375
  status: ctx.response?.statusCode,
367
376
  timeLabel: timeLabel,
368
- totalTimeMs: total,
377
+ totalTimeMs: Math.round(total),
369
378
  events: times,
379
+ cpuUsageDiffMs,
380
+ memoryUsageDiff,
381
+ responseBodySize: ctx.body && typeof ctx.body === 'string' ? ctx.body.length : undefined,
370
382
  })
371
383
  }
372
384