@platformatic/service 2.7.0 → 2.8.0-alpha.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/lib/stackable.js CHANGED
@@ -1,6 +1,8 @@
1
1
  'use strict'
2
2
 
3
+ const { hostname } = require('node:os')
3
4
  const { dirname } = require('node:path')
5
+ const { pathToFileURL } = require('node:url')
4
6
  const { printSchema } = require('graphql')
5
7
  const pino = require('pino')
6
8
  const { collectMetrics } = require('@platformatic/metrics')
@@ -20,6 +22,10 @@ class ServiceStackable {
20
22
  this.context = options.context ?? {}
21
23
  this.context.stackable = this
22
24
 
25
+ this.serviceId = this.context.serviceId
26
+ this.context.worker ??= { count: 1, index: 0 }
27
+ this.workerId = this.context.worker.count > 1 ? this.context.worker.index : undefined
28
+
23
29
  this.configManager.on('error', err => {
24
30
  /* c8 ignore next */
25
31
  this.stackable.log({
@@ -32,6 +38,10 @@ class ServiceStackable {
32
38
 
33
39
  // Setup globals
34
40
  this.registerGlobals({
41
+ serviceId: this.serviceId,
42
+ workerId: this.workerId,
43
+ // Always use URL to avoid serialization problem in Windows
44
+ root: this.context.directory ? pathToFileURL(this.context.directory).toString() : undefined,
35
45
  setOpenapiSchema: this.setOpenapiSchema.bind(this),
36
46
  setGraphqlSchema: this.setGraphqlSchema.bind(this),
37
47
  setBasePath: this.setBasePath.bind(this)
@@ -157,15 +167,13 @@ class ServiceStackable {
157
167
  // fastify metrics before the server is started.
158
168
  async #collectMetrics () {
159
169
  const metricsConfig = this.context.metricsConfig
170
+
160
171
  if (metricsConfig !== false) {
161
- const { registry } = await collectMetrics(
162
- this.context.serviceId,
163
- {
164
- defaultMetrics: true,
165
- httpMetrics: false,
166
- ...metricsConfig
167
- }
168
- )
172
+ const { registry } = await collectMetrics(this.context.serviceId, this.context.worker.index, {
173
+ defaultMetrics: true,
174
+ httpMetrics: false,
175
+ ...metricsConfig
176
+ })
169
177
  this.metricsRegistry = registry
170
178
  this.#setHttpMetrics()
171
179
  }
@@ -174,9 +182,7 @@ class ServiceStackable {
174
182
  async getMetrics ({ format }) {
175
183
  if (!this.metricsRegistry) return null
176
184
 
177
- return format === 'json'
178
- ? await this.metricsRegistry.getMetricsAsJSON()
179
- : await this.metricsRegistry.metrics()
185
+ return format === 'json' ? await this.metricsRegistry.getMetricsAsJSON() : await this.metricsRegistry.metrics()
180
186
  }
181
187
 
182
188
  async inject (injectParams) {
@@ -308,10 +314,18 @@ class ServiceStackable {
308
314
  level: this.loggerConfig?.level ?? 'trace'
309
315
  }
310
316
 
317
+ this.registerGlobals({
318
+ logLevel: pinoOptions.level
319
+ })
320
+
311
321
  if (this.context?.serviceId) {
312
322
  pinoOptions.name = this.context.serviceId
313
323
  }
314
324
 
325
+ if (typeof this.context?.worker?.index !== 'undefined') {
326
+ pinoOptions.base = { pid: process.pid, hostname: hostname(), worker: this.context.worker.index }
327
+ }
328
+
315
329
  this.logger = pino(pinoOptions)
316
330
 
317
331
  // Only one of logger and loggerInstance should be set
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "2.7.0",
3
+ "version": "2.8.0-alpha.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -76,18 +76,18 @@
76
76
  "rfdc": "^1.3.1",
77
77
  "semgrator": "^0.3.0",
78
78
  "undici": "^6.9.0",
79
- "@platformatic/client": "2.7.0",
80
- "@platformatic/metrics": "2.7.0",
81
- "@platformatic/scalar-theme": "2.7.0",
82
- "@platformatic/generators": "2.7.0",
83
- "@platformatic/telemetry": "2.7.0",
84
- "@platformatic/ts-compiler": "2.7.0",
85
- "@platformatic/utils": "2.7.0",
86
- "@platformatic/config": "2.7.0"
79
+ "@platformatic/client": "2.8.0-alpha.1",
80
+ "@platformatic/config": "2.8.0-alpha.1",
81
+ "@platformatic/metrics": "2.8.0-alpha.1",
82
+ "@platformatic/generators": "2.8.0-alpha.1",
83
+ "@platformatic/ts-compiler": "2.8.0-alpha.1",
84
+ "@platformatic/scalar-theme": "2.8.0-alpha.1",
85
+ "@platformatic/telemetry": "2.8.0-alpha.1",
86
+ "@platformatic/utils": "2.8.0-alpha.1"
87
87
  },
88
88
  "scripts": {
89
- "test": "pnpm run lint && borp -T --concurrency=1 --timeout=180000 && tsd",
90
- "unit": "borp --pattern 'test/**/*.test.{js,mjs}' --ignore 'fixtures/**/*' --concurrency=1 --timeout=180000 --no-typescript",
89
+ "test": "pnpm run lint && borp -T --concurrency=1 --timeout=300000 && tsd",
90
+ "unit": "borp --pattern 'test/**/*.test.{js,mjs}' --ignore 'fixtures/**/*' --concurrency=1 --timeout=300000 --no-typescript",
91
91
  "gen-schema": "node lib/schema.js > schema.json",
92
92
  "gen-types": "json2ts > config.d.ts < schema.json",
93
93
  "build": "pnpm run gen-schema && pnpm run gen-types",
package/schema.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/service/2.7.0.json",
3
- "version": "2.7.0",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/service/2.8.0-alpha.1.json",
3
+ "version": "2.8.0-alpha.1",
4
4
  "title": "Platformatic Service",
5
5
  "type": "object",
6
6
  "properties": {