@platformatic/service 1.47.0 → 1.49.0
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/config.d.ts +3 -0
- package/lib/plugins/metrics.js +31 -6
- package/lib/schema.js +4 -0
- package/lib/start.js +2 -1
- package/package.json +12 -10
- package/schema.json +8 -2
package/config.d.ts
CHANGED
package/lib/plugins/metrics.js
CHANGED
|
@@ -7,22 +7,43 @@ const fastify = require('fastify')
|
|
|
7
7
|
const fp = require('fastify-plugin')
|
|
8
8
|
|
|
9
9
|
const metricsPlugin = fp(async function (app, opts = {}) {
|
|
10
|
+
const promClient = require('prom-client')
|
|
11
|
+
|
|
12
|
+
const register = new promClient.Registry()
|
|
13
|
+
|
|
10
14
|
const defaultMetrics = opts.defaultMetrics ?? { enabled: true }
|
|
11
15
|
const prefix = opts.prefix ?? ''
|
|
12
16
|
|
|
17
|
+
if (opts.labels) {
|
|
18
|
+
const labels = opts.labels ?? {}
|
|
19
|
+
register.setDefaultLabels(labels)
|
|
20
|
+
}
|
|
21
|
+
|
|
13
22
|
app.register(require('fastify-metrics'), {
|
|
14
|
-
defaultMetrics:
|
|
23
|
+
defaultMetrics: {
|
|
24
|
+
...defaultMetrics,
|
|
25
|
+
register
|
|
26
|
+
},
|
|
15
27
|
endpoint: null,
|
|
16
28
|
name: 'metrics',
|
|
17
29
|
clearRegisterOnInit: false,
|
|
30
|
+
promClient: {
|
|
31
|
+
...promClient,
|
|
32
|
+
register
|
|
33
|
+
},
|
|
18
34
|
routeMetrics: {
|
|
19
35
|
enabled: true,
|
|
36
|
+
customLabels: {
|
|
37
|
+
telemetry_id: (req) => req.headers['x-telemetry-id'] ?? 'unknown'
|
|
38
|
+
},
|
|
20
39
|
overrides: {
|
|
21
40
|
histogram: {
|
|
22
|
-
name: prefix + 'http_request_duration_seconds'
|
|
41
|
+
name: prefix + 'http_request_duration_seconds',
|
|
42
|
+
registers: [register]
|
|
23
43
|
},
|
|
24
44
|
summary: {
|
|
25
|
-
name: prefix + 'http_request_summary_seconds'
|
|
45
|
+
name: prefix + 'http_request_summary_seconds',
|
|
46
|
+
registers: [register]
|
|
26
47
|
}
|
|
27
48
|
}
|
|
28
49
|
}
|
|
@@ -34,8 +55,10 @@ const metricsPlugin = fp(async function (app, opts = {}) {
|
|
|
34
55
|
help: 'request duration in seconds summary for all requests',
|
|
35
56
|
collect: () => {
|
|
36
57
|
process.nextTick(() => httpLatencyMetric.reset())
|
|
37
|
-
}
|
|
58
|
+
},
|
|
59
|
+
registers: [register]
|
|
38
60
|
})
|
|
61
|
+
|
|
39
62
|
const ignoredMethods = ['HEAD', 'OPTIONS', 'TRACE', 'CONNECT']
|
|
40
63
|
const timers = new WeakMap()
|
|
41
64
|
app.addHook('onRequest', async (req) => {
|
|
@@ -66,7 +89,8 @@ const metricsPlugin = fp(async function (app, opts = {}) {
|
|
|
66
89
|
const result = eventLoopUtilization(endELU, startELU).utilization
|
|
67
90
|
eluMetric.set(result)
|
|
68
91
|
startELU = endELU
|
|
69
|
-
}
|
|
92
|
+
},
|
|
93
|
+
registers: [register]
|
|
70
94
|
})
|
|
71
95
|
app.metrics.client.register.registerMetric(eluMetric)
|
|
72
96
|
|
|
@@ -98,7 +122,8 @@ const metricsPlugin = fp(async function (app, opts = {}) {
|
|
|
98
122
|
|
|
99
123
|
previousIdleTime = idleTime
|
|
100
124
|
previousTotalTime = totalTime
|
|
101
|
-
}
|
|
125
|
+
},
|
|
126
|
+
registers: [register]
|
|
102
127
|
})
|
|
103
128
|
app.metrics.client.register.registerMetric(cpuMetric)
|
|
104
129
|
})
|
package/lib/schema.js
CHANGED
package/lib/start.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { readFile } = require('fs/promises')
|
|
4
4
|
const close = require('close-with-grace')
|
|
5
|
+
const { Bus } = require('@platformatic/bus')
|
|
5
6
|
const { loadConfig, ConfigManager, printConfigValidationErrors, printAndExitLoadConfigError } = require('@platformatic/config')
|
|
6
7
|
const { addLoggerToTheConfig, isDocker } = require('./utils.js')
|
|
7
8
|
const { restartable } = require('@fastify/restartable')
|
|
@@ -60,7 +61,7 @@ async function buildServer (options, app) {
|
|
|
60
61
|
}
|
|
61
62
|
fastifyOptions.genReqId = function (req) { return randomUUID() }
|
|
62
63
|
const root = fastify(fastifyOptions)
|
|
63
|
-
root.decorate('platformatic', { configManager, config })
|
|
64
|
+
root.decorate('platformatic', { configManager, config, bus: new Bus(options.id) })
|
|
64
65
|
await root.register(app)
|
|
65
66
|
if (!root.hasRoute({ url: '/', method: 'GET' })) {
|
|
66
67
|
await root.register(require('./root-endpoint'), {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.49.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@fastify/cors": "^9.0.1",
|
|
45
45
|
"@fastify/deepmerge": "^1.3.0",
|
|
46
46
|
"@fastify/error": "^3.4.1",
|
|
47
|
-
"@fastify/restartable": "^2.
|
|
47
|
+
"@fastify/restartable": "^2.3.1",
|
|
48
48
|
"@fastify/static": "^7.0.1",
|
|
49
49
|
"@fastify/swagger": "^8.14.0",
|
|
50
50
|
"@fastify/under-pressure": "^8.3.0",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"env-schema": "^5.2.1",
|
|
63
63
|
"es-main": "^1.3.0",
|
|
64
64
|
"execa": "^8.0.1",
|
|
65
|
-
"fastify": "^4.
|
|
65
|
+
"fastify": "^4.28.1",
|
|
66
66
|
"fastify-metrics": "^11.0.0",
|
|
67
67
|
"fastify-openapi-glue": "^4.4.3",
|
|
68
68
|
"fastify-plugin": "^4.5.1",
|
|
@@ -75,16 +75,18 @@
|
|
|
75
75
|
"ora": "^6.3.1",
|
|
76
76
|
"pino": "^8.19.0",
|
|
77
77
|
"pino-pretty": "^11.0.0",
|
|
78
|
+
"prom-client": "^15.1.2",
|
|
78
79
|
"rfdc": "^1.3.1",
|
|
79
80
|
"semgrator": "^0.3.0",
|
|
80
81
|
"undici": "^6.9.0",
|
|
81
|
-
"@platformatic/
|
|
82
|
-
"@platformatic/
|
|
83
|
-
"@platformatic/config": "1.
|
|
84
|
-
"@platformatic/
|
|
85
|
-
"@platformatic/
|
|
86
|
-
"@platformatic/
|
|
87
|
-
"@platformatic/
|
|
82
|
+
"@platformatic/authenticate": "1.49.0",
|
|
83
|
+
"@platformatic/client": "1.49.0",
|
|
84
|
+
"@platformatic/config": "1.49.0",
|
|
85
|
+
"@platformatic/bus": "1.49.0",
|
|
86
|
+
"@platformatic/generators": "1.49.0",
|
|
87
|
+
"@platformatic/scalar-theme": "1.49.0",
|
|
88
|
+
"@platformatic/telemetry": "1.49.0",
|
|
89
|
+
"@platformatic/utils": "1.49.0"
|
|
88
90
|
},
|
|
89
91
|
"standard": {
|
|
90
92
|
"ignore": [
|
package/schema.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://platformatic.dev/schemas/v1.
|
|
3
|
-
"version": "1.
|
|
2
|
+
"$id": "https://platformatic.dev/schemas/v1.49.0/service",
|
|
3
|
+
"version": "1.49.0",
|
|
4
4
|
"title": "Platformatic Service",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"properties": {
|
|
@@ -653,6 +653,12 @@
|
|
|
653
653
|
"username",
|
|
654
654
|
"password"
|
|
655
655
|
]
|
|
656
|
+
},
|
|
657
|
+
"labels": {
|
|
658
|
+
"type": "object",
|
|
659
|
+
"additionalProperties": {
|
|
660
|
+
"type": "string"
|
|
661
|
+
}
|
|
656
662
|
}
|
|
657
663
|
},
|
|
658
664
|
"additionalProperties": false
|