@platformatic/service 1.30.0 → 1.31.1
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 +1 -1
- package/lib/plugins/metrics.js +40 -28
- package/lib/schema.js +1 -1
- package/package.json +8 -8
- package/schema.json +4 -3
package/config.d.ts
CHANGED
package/lib/plugins/metrics.js
CHANGED
|
@@ -104,16 +104,25 @@ const metricsPlugin = fp(async function (app, opts = {}) {
|
|
|
104
104
|
})
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
function cleanMetrics () {
|
|
108
|
+
const metrics = app.metrics.client.register._metrics
|
|
109
|
+
for (const metricName in metrics) {
|
|
110
|
+
if (defaultMetrics.enabled || metricName.startsWith(prefix)) {
|
|
111
|
+
delete metrics[metricName]
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
107
116
|
let isRestarting = false
|
|
108
117
|
app.addHook('onReady', async () => {
|
|
109
118
|
app.addPreRestartHook(async () => {
|
|
110
119
|
isRestarting = true
|
|
111
|
-
|
|
120
|
+
cleanMetrics()
|
|
112
121
|
})
|
|
113
122
|
})
|
|
114
123
|
app.addHook('onClose', async () => {
|
|
115
124
|
if (!isRestarting) {
|
|
116
|
-
|
|
125
|
+
cleanMetrics()
|
|
117
126
|
}
|
|
118
127
|
})
|
|
119
128
|
}, {
|
|
@@ -177,38 +186,41 @@ module.exports = fp(async function (app, opts) {
|
|
|
177
186
|
await closeMetricsServer()
|
|
178
187
|
}
|
|
179
188
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
189
|
+
if (server !== 'hide') {
|
|
190
|
+
let onRequestHook
|
|
191
|
+
if (auth) {
|
|
192
|
+
const { username, password } = auth
|
|
193
|
+
|
|
194
|
+
await metricsServer.register(require('@fastify/basic-auth'), {
|
|
195
|
+
validate: function (user, pass, req, reply, done) {
|
|
196
|
+
if (username !== user || password !== pass) {
|
|
197
|
+
return reply.code(401).send({ message: 'Unauthorized' })
|
|
198
|
+
}
|
|
199
|
+
return done()
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
onRequestHook = metricsServer.basicAuth
|
|
203
|
+
}
|
|
183
204
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
205
|
+
metricsServer.register(require('@fastify/accepts'))
|
|
206
|
+
|
|
207
|
+
metricsServer.route({
|
|
208
|
+
url: metricsEndpoint,
|
|
209
|
+
method: 'GET',
|
|
210
|
+
logLevel: 'warn',
|
|
211
|
+
onRequest: onRequestHook,
|
|
212
|
+
handler: async (req, reply) => {
|
|
213
|
+
const promRegistry = app.metrics.client.register
|
|
214
|
+
const accepts = req.accepts()
|
|
215
|
+
if (!accepts.type('text/plain') && accepts.type('application/json')) {
|
|
216
|
+
return promRegistry.getMetricsAsJSON()
|
|
188
217
|
}
|
|
189
|
-
|
|
218
|
+
reply.type('text/plain')
|
|
219
|
+
return promRegistry.metrics()
|
|
190
220
|
}
|
|
191
221
|
})
|
|
192
|
-
onRequestHook = metricsServer.basicAuth
|
|
193
222
|
}
|
|
194
223
|
|
|
195
|
-
metricsServer.register(require('@fastify/accepts'))
|
|
196
|
-
metricsServer.route({
|
|
197
|
-
url: metricsEndpoint,
|
|
198
|
-
method: 'GET',
|
|
199
|
-
logLevel: 'warn',
|
|
200
|
-
onRequest: onRequestHook,
|
|
201
|
-
handler: async (req, reply) => {
|
|
202
|
-
const promRegistry = app.metrics.client.register
|
|
203
|
-
const accepts = req.accepts()
|
|
204
|
-
if (!accepts.type('text/plain') && accepts.type('application/json')) {
|
|
205
|
-
return promRegistry.getMetricsAsJSON()
|
|
206
|
-
}
|
|
207
|
-
reply.type('text/plain')
|
|
208
|
-
return promRegistry.metrics()
|
|
209
|
-
}
|
|
210
|
-
})
|
|
211
|
-
|
|
212
224
|
if (server === 'own') {
|
|
213
225
|
await metricsServer.ready()
|
|
214
226
|
}
|
package/lib/schema.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -78,13 +78,13 @@
|
|
|
78
78
|
"semgrator": "^0.3.0",
|
|
79
79
|
"ua-parser-js": "^1.0.37",
|
|
80
80
|
"undici": "^6.9.0",
|
|
81
|
-
"@platformatic/
|
|
82
|
-
"@platformatic/
|
|
83
|
-
"@platformatic/
|
|
84
|
-
"@platformatic/generators": "1.
|
|
85
|
-
"@platformatic/scalar-theme": "1.
|
|
86
|
-
"@platformatic/telemetry": "1.
|
|
87
|
-
"@platformatic/utils": "1.
|
|
81
|
+
"@platformatic/client": "1.31.1",
|
|
82
|
+
"@platformatic/authenticate": "1.31.1",
|
|
83
|
+
"@platformatic/config": "1.31.1",
|
|
84
|
+
"@platformatic/generators": "1.31.1",
|
|
85
|
+
"@platformatic/scalar-theme": "1.31.1",
|
|
86
|
+
"@platformatic/telemetry": "1.31.1",
|
|
87
|
+
"@platformatic/utils": "1.31.1"
|
|
88
88
|
},
|
|
89
89
|
"standard": {
|
|
90
90
|
"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.31.1/service",
|
|
3
|
+
"version": "1.31.1",
|
|
4
4
|
"title": "Platformatic Service",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"properties": {
|
|
@@ -613,7 +613,8 @@
|
|
|
613
613
|
"type": "string",
|
|
614
614
|
"enum": [
|
|
615
615
|
"own",
|
|
616
|
-
"parent"
|
|
616
|
+
"parent",
|
|
617
|
+
"hide"
|
|
617
618
|
]
|
|
618
619
|
},
|
|
619
620
|
"defaultMetrics": {
|