@contember/engine-http 2.1.0-alpha.3 → 2.1.0-alpha.5
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/dist/development/src/application/application.cjs +21 -10
- package/dist/development/src/application/application.cjs.map +1 -1
- package/dist/development/src/application/application.js +21 -10
- package/dist/development/src/application/application.js.map +1 -1
- package/dist/production/src/application/application.cjs +21 -10
- package/dist/production/src/application/application.cjs.map +1 -1
- package/dist/production/src/application/application.js +21 -10
- package/dist/production/src/application/application.js.map +1 -1
- package/dist/types/application/application.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -15
- package/src/application/application.ts +21 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-http",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.5",
|
|
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.
|
|
30
|
-
"@contember/database": "2.1.0-alpha.
|
|
31
|
-
"@contember/database-migrations": "2.1.0-alpha.
|
|
32
|
-
"@contember/dic": "2.1.0-alpha.
|
|
33
|
-
"@contember/engine-common": "2.1.0-alpha.
|
|
34
|
-
"@contember/engine-content-api": "2.1.0-alpha.
|
|
35
|
-
"@contember/engine-system-api": "2.1.0-alpha.
|
|
36
|
-
"@contember/engine-tenant-api": "2.1.0-alpha.
|
|
37
|
-
"@contember/graphql-utils": "2.1.0-alpha.
|
|
38
|
-
"@contember/logger": "2.1.0-alpha.
|
|
39
|
-
"@contember/schema": "2.1.0-alpha.
|
|
40
|
-
"@contember/schema-migrations": "2.1.0-alpha.
|
|
41
|
-
"@contember/schema-utils": "2.1.0-alpha.
|
|
42
|
-
"@contember/typesafe": "2.1.0-alpha.
|
|
29
|
+
"@contember/config-loader": "2.1.0-alpha.5",
|
|
30
|
+
"@contember/database": "2.1.0-alpha.5",
|
|
31
|
+
"@contember/database-migrations": "2.1.0-alpha.5",
|
|
32
|
+
"@contember/dic": "2.1.0-alpha.5",
|
|
33
|
+
"@contember/engine-common": "2.1.0-alpha.5",
|
|
34
|
+
"@contember/engine-content-api": "2.1.0-alpha.5",
|
|
35
|
+
"@contember/engine-system-api": "2.1.0-alpha.5",
|
|
36
|
+
"@contember/engine-tenant-api": "2.1.0-alpha.5",
|
|
37
|
+
"@contember/graphql-utils": "2.1.0-alpha.5",
|
|
38
|
+
"@contember/logger": "2.1.0-alpha.5",
|
|
39
|
+
"@contember/schema": "2.1.0-alpha.5",
|
|
40
|
+
"@contember/schema-migrations": "2.1.0-alpha.5",
|
|
41
|
+
"@contember/schema-utils": "2.1.0-alpha.5",
|
|
42
|
+
"@contember/typesafe": "2.1.0-alpha.5",
|
|
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 =
|
|
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:
|
|
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:
|
|
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 =
|
|
336
|
+
const globalStart = performance.now()
|
|
337
|
+
const cpuUsageStart = cpuUsage()
|
|
338
|
+
const memoryUsageStart = memoryUsage()
|
|
335
339
|
const timer: Timer = (name: string, cb) => {
|
|
336
|
-
const start =
|
|
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 =
|
|
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 =
|
|
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
|
|