@platformatic/next 2.24.0 → 2.26.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/index.js CHANGED
@@ -104,7 +104,7 @@ export class NextStackable extends BaseStackable {
104
104
  command = ['node', pathResolve(this.#next, './dist/bin/next'), 'build', this.root]
105
105
  }
106
106
 
107
- return this.buildWithCommand(command, this.#basePath, loader, this.#getChildManagerScripts())
107
+ return this.buildWithCommand(command, this.#basePath, { loader, scripts: [this.#getChildManagerScripts()] })
108
108
  }
109
109
 
110
110
  /* c8 ignore next 5 */
@@ -143,21 +143,14 @@ export class NextStackable extends BaseStackable {
143
143
  port: port || 0
144
144
  }
145
145
 
146
+ const context = await this.getChildManagerContext(this.#basePath)
147
+
146
148
  this.childManager = new ChildManager({
147
149
  loader: loaderUrl,
148
150
  context: {
149
- config: this.configManager.current,
150
- serviceId: this.serviceId,
151
- workerId: this.workerId,
152
- // Always use URL to avoid serialization problem in Windows
153
- root: pathToFileURL(this.root).toString(),
154
- basePath: this.#basePath,
155
- logLevel: this.logger.level,
151
+ ...context,
156
152
  port: false,
157
- isEntrypoint: this.isEntrypoint,
158
- runtimeBasePath: this.runtimeConfig.basePath,
159
- wantsAbsoluteUrls: true,
160
- telemetryConfig: this.telemetryConfig
153
+ wantsAbsoluteUrls: true
161
154
  },
162
155
  scripts: this.#getChildManagerScripts()
163
156
  })
@@ -7,6 +7,11 @@ import { resolve } from 'node:path'
7
7
  import { fileURLToPath } from 'node:url'
8
8
  import { pino } from 'pino'
9
9
 
10
+ const CACHE_HIT_METRIC = { name: 'next_cache_valkey_hit_count', help: 'Next.js Cache (Valkey) Hit Count' }
11
+ const CACHE_MISS_METRIC = { name: 'next_cache_valkey_miss_count', help: 'Next.js Cache (Valkey) Miss Count' }
12
+
13
+ const clients = new Map()
14
+
10
15
  export const MAX_BATCH_SIZE = 100
11
16
 
12
17
  export const sections = {
@@ -14,8 +19,6 @@ export const sections = {
14
19
  tags: 'tags'
15
20
  }
16
21
 
17
- const clients = new Map()
18
-
19
22
  export function keyFor (prefix, subprefix, section, key) {
20
23
  return [prefix, 'cache:next', subprefix, section, key ? Buffer.from(key).toString('base64url') : undefined]
21
24
  .filter(c => c)
@@ -46,6 +49,8 @@ export class CacheHandler {
46
49
  #subprefix
47
50
  #meta
48
51
  #maxTTL
52
+ #cacheHitMetric
53
+ #cacheMissMetric
49
54
 
50
55
  constructor (options) {
51
56
  options ??= {}
@@ -86,6 +91,10 @@ export class CacheHandler {
86
91
  if (!this.#store) {
87
92
  throw new Error('Please provide a the "store" option.')
88
93
  }
94
+
95
+ if (globalThis.platformatic) {
96
+ this.#registerMetrics()
97
+ }
89
98
  }
90
99
 
91
100
  async get (cacheKey, _, isRedisKey) {
@@ -98,9 +107,11 @@ export class CacheHandler {
98
107
  rawValue = await this.#store.get(key)
99
108
 
100
109
  if (!rawValue) {
110
+ this.#cacheMissMetric?.inc()
101
111
  return
102
112
  }
103
113
  } catch (e) {
114
+ this.#cacheMissMetric?.inc()
104
115
  this.#logger.error({ err: ensureLoggableError(e) }, 'Cannot read cache value from Valkey')
105
116
  throw new Error('Cannot read cache value from Valkey', { cause: e })
106
117
  }
@@ -109,6 +120,7 @@ export class CacheHandler {
109
120
  try {
110
121
  value = this.#deserialize(rawValue)
111
122
  } catch (e) {
123
+ this.#cacheMissMetric?.inc()
112
124
  this.#logger.error({ err: ensureLoggableError(e) }, 'Cannot deserialize cache value from Valkey')
113
125
 
114
126
  // Avoid useless reads the next time
@@ -129,6 +141,7 @@ export class CacheHandler {
129
141
  }
130
142
  }
131
143
 
144
+ this.#cacheHitMetric?.inc()
132
145
  return value
133
146
  }
134
147
 
@@ -325,6 +338,26 @@ export class CacheHandler {
325
338
  #deserialize (data) {
326
339
  return unpack(Buffer.from(data, 'base64url'))
327
340
  }
341
+
342
+ #registerMetrics () {
343
+ const { client, registry } = globalThis.platformatic.prometheus
344
+
345
+ this.#cacheHitMetric =
346
+ registry.getSingleMetric(CACHE_HIT_METRIC.name) ??
347
+ new client.Counter({
348
+ name: CACHE_HIT_METRIC.name,
349
+ help: CACHE_HIT_METRIC.help,
350
+ registers: [registry]
351
+ })
352
+
353
+ this.#cacheMissMetric =
354
+ registry.getSingleMetric(CACHE_MISS_METRIC.name) ??
355
+ new client.Counter({
356
+ name: CACHE_MISS_METRIC.name,
357
+ help: CACHE_MISS_METRIC.help,
358
+ registers: [registry]
359
+ })
360
+ }
328
361
  }
329
362
 
330
363
  export default CacheHandler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/next",
3
- "version": "2.24.0",
3
+ "version": "2.26.0-alpha.1",
4
4
  "description": "Platformatic Next.js Stackable",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -23,9 +23,9 @@
23
23
  "iovalkey": "^0.2.1",
24
24
  "msgpackr": "^1.11.2",
25
25
  "semver": "^7.6.3",
26
- "@platformatic/basic": "2.24.0",
27
- "@platformatic/utils": "2.24.0",
28
- "@platformatic/config": "2.24.0"
26
+ "@platformatic/basic": "2.26.0-alpha.1",
27
+ "@platformatic/utils": "2.26.0-alpha.1",
28
+ "@platformatic/config": "2.26.0-alpha.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@fastify/reply-from": "^11.0.0",
@@ -41,8 +41,8 @@
41
41
  "react-dom": "^18.3.1",
42
42
  "typescript": "^5.5.4",
43
43
  "ws": "^8.18.0",
44
- "@platformatic/composer": "2.24.0",
45
- "@platformatic/service": "2.24.0"
44
+ "@platformatic/service": "2.26.0-alpha.1",
45
+ "@platformatic/composer": "2.26.0-alpha.1"
46
46
  },
47
47
  "scripts": {
48
48
  "test": "npm run lint && borp --concurrency=1 --no-timeout",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/next/2.24.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/next/2.26.0-alpha.1.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Next.js Stackable",
5
5
  "type": "object",