@platformatic/service 3.33.0 → 3.34.1-alpha.3

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 CHANGED
@@ -423,6 +423,10 @@ export interface PlatformaticServiceConfig {
423
423
  gracefulShutdown?: {
424
424
  runtime: number | string;
425
425
  application: number | string;
426
+ /**
427
+ * Add Connection: close header to HTTP responses during graceful shutdown
428
+ */
429
+ closeConnections?: boolean;
426
430
  };
427
431
  health?: {
428
432
  enabled?: boolean | string;
@@ -586,6 +590,23 @@ export interface PlatformaticServiceConfig {
586
590
  */
587
591
  serviceVersion?: string;
588
592
  };
593
+ /**
594
+ * Custom labels to add to HTTP metrics (http_request_all_duration_seconds). Each label extracts its value from an HTTP request header.
595
+ */
596
+ httpCustomLabels?: {
597
+ /**
598
+ * The label name to use in metrics
599
+ */
600
+ name: string;
601
+ /**
602
+ * The HTTP request header to extract the value from
603
+ */
604
+ header: string;
605
+ /**
606
+ * Default value when header is missing (defaults to "unknown")
607
+ */
608
+ default?: string;
609
+ }[];
589
610
  };
590
611
  telemetry?: {
591
612
  enabled?: boolean | string;
package/lib/capability.js CHANGED
@@ -39,6 +39,23 @@ export class ServiceCapability extends BaseCapability {
39
39
  }
40
40
  })
41
41
 
42
+ // Add hook to set Connection: close during graceful shutdown.
43
+ // This must be added BEFORE plugins are registered, because if a plugin
44
+ // calls app.ready() during registration and we add hooks afterwards,
45
+ // it can cause issues with Fastify's internal promise handling.
46
+ const closeConnections = this.runtimeConfig?.gracefulShutdown?.closeConnections !== false
47
+ if (closeConnections) {
48
+ this.#app.addHook('onRequest', (request, reply, done) => {
49
+ if (this.closing) {
50
+ // For HTTP/1.x, set Connection: close
51
+ if (request.raw.httpVersionMajor !== 2) {
52
+ reply.header('Connection', 'close')
53
+ }
54
+ }
55
+ done()
56
+ })
57
+ }
58
+
42
59
  // This must be done before loading the plugins, so they can inspect if the
43
60
  // openTelemetry decorator exists and then configure accordingly.
44
61
  // Skip manual telemetry plugin if automatic instrumentation is already active
@@ -93,6 +110,15 @@ export class ServiceCapability extends BaseCapability {
93
110
  await this.#app?.close()
94
111
  }
95
112
 
113
+ setClosing () {
114
+ super.setClosing()
115
+
116
+ // For HTTP/2, send GOAWAY frames immediately
117
+ if (this.#app?.server?.closeHttp2Sessions) {
118
+ this.#app.server.closeHttp2Sessions()
119
+ }
120
+ }
121
+
96
122
  async inject (injectParams, onInject) {
97
123
  const response = await this.#app.inject(injectParams, onInject)
98
124
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "3.33.0",
3
+ "version": "3.34.1-alpha.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -67,12 +67,12 @@
67
67
  "rfdc": "^1.3.1",
68
68
  "semgrator": "^0.3.0",
69
69
  "undici": "^7.0.0",
70
- "@platformatic/basic": "3.33.0",
71
- "@platformatic/foundation": "3.33.0",
72
- "@platformatic/generators": "3.33.0",
73
- "@platformatic/metrics": "3.33.0",
74
- "@platformatic/scalar-theme": "3.33.0",
75
- "@platformatic/telemetry": "3.33.0"
70
+ "@platformatic/basic": "3.34.1-alpha.3",
71
+ "@platformatic/foundation": "3.34.1-alpha.3",
72
+ "@platformatic/generators": "3.34.1-alpha.3",
73
+ "@platformatic/telemetry": "3.34.1-alpha.3",
74
+ "@platformatic/metrics": "3.34.1-alpha.3",
75
+ "@platformatic/scalar-theme": "3.34.1-alpha.3"
76
76
  },
77
77
  "engines": {
78
78
  "node": ">=22.19.0"
package/schema.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/service/3.33.0.json",
3
- "version": "3.33.0",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/service/3.34.1-alpha.3.json",
3
+ "version": "3.34.1-alpha.3",
4
4
  "title": "Platformatic Service Config",
5
5
  "type": "object",
6
6
  "properties": {
@@ -1735,6 +1735,11 @@
1735
1735
  }
1736
1736
  ],
1737
1737
  "default": 10000
1738
+ },
1739
+ "closeConnections": {
1740
+ "type": "boolean",
1741
+ "default": true,
1742
+ "description": "Add Connection: close header to HTTP responses during graceful shutdown"
1738
1743
  }
1739
1744
  },
1740
1745
  "default": {},
@@ -2275,6 +2280,32 @@
2275
2280
  "endpoint"
2276
2281
  ],
2277
2282
  "additionalProperties": false
2283
+ },
2284
+ "httpCustomLabels": {
2285
+ "type": "array",
2286
+ "description": "Custom labels to add to HTTP metrics (http_request_all_duration_seconds). Each label extracts its value from an HTTP request header.",
2287
+ "items": {
2288
+ "type": "object",
2289
+ "properties": {
2290
+ "name": {
2291
+ "type": "string",
2292
+ "description": "The label name to use in metrics"
2293
+ },
2294
+ "header": {
2295
+ "type": "string",
2296
+ "description": "The HTTP request header to extract the value from"
2297
+ },
2298
+ "default": {
2299
+ "type": "string",
2300
+ "description": "Default value when header is missing (defaults to \"unknown\")"
2301
+ }
2302
+ },
2303
+ "required": [
2304
+ "name",
2305
+ "header"
2306
+ ],
2307
+ "additionalProperties": false
2308
+ }
2278
2309
  }
2279
2310
  },
2280
2311
  "additionalProperties": false