@platformatic/watt-extra 1.5.0-alpha.0 → 1.5.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/lib/watt.js CHANGED
@@ -98,6 +98,11 @@ class Watt {
98
98
  await this.runtime?.updateSharedContext?.({ context })
99
99
  }
100
100
 
101
+ getRuntimeVersion () {
102
+ const { version } = this.#require('@platformatic/runtime/package.json')
103
+ return version
104
+ }
105
+
101
106
  async #createRuntime () {
102
107
  this.#logger.info('Creating runtime')
103
108
  const { create, transform } = this.#require('@platformatic/runtime')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/watt-extra",
3
- "version": "1.5.0-alpha.0",
3
+ "version": "1.5.0",
4
4
  "description": "The Platformatic runtime manager",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -37,18 +37,19 @@
37
37
  "dependencies": {
38
38
  "@datadog/pprof": "^5.9.0",
39
39
  "@fastify/error": "^4.2.0",
40
- "@platformatic/runtime": "^3.14.0",
41
40
  "@platformatic/foundation": "^3.14.0",
41
+ "@platformatic/runtime": "^3.14.0",
42
42
  "@platformatic/wattpm-pprof-capture": "^3.14.0",
43
43
  "avvio": "^9.1.0",
44
44
  "chalk": "^4.1.2",
45
45
  "commist": "^3.2.0",
46
- "env-schema": "^6.0.1",
46
+ "env-schema": "^7.0.0",
47
47
  "execa": "^9.6.0",
48
48
  "help-me": "^5.0.0",
49
49
  "minimist": "^1.2.8",
50
50
  "pino": "^10.0.0",
51
51
  "pino-pretty": "^13.0.0",
52
+ "semver": "^7.7.3",
52
53
  "undici": "^7.11.0",
53
54
  "undici-cache-redis": "^1.0.0",
54
55
  "undici-slicer-interceptor": "^0.4.1",
package/plugins/alerts.js CHANGED
@@ -10,7 +10,7 @@ async function alerts (app, _opts) {
10
10
  const lastServicesAlertTime = {}
11
11
 
12
12
  async function setupAlerts () {
13
- const scalerAlgorithmVersion = app.env.PLT_SCALER_ALGORITHM_VERSION
13
+ const scalerAlgorithmVersion = app.instanceConfig?.scaler?.version ?? 'v1'
14
14
  if (scalerAlgorithmVersion !== 'v1') return
15
15
 
16
16
  // Skip alerts setup if ICC is not configured
package/plugins/env.js CHANGED
@@ -23,7 +23,6 @@ const schema = {
23
23
  PLT_FLAMEGRAPHS_GRACE_PERIOD: { type: 'number', default: 3000 },
24
24
  PLT_JWT_EXPIRATION_OFFSET_SEC: { type: 'number', default: 60 },
25
25
  PLT_UPDATES_RECONNECT_INTERVAL_SEC: { type: 'number', default: 1 },
26
- PLT_SCALER_ALGORITHM_VERSION: { type: 'string', default: 'v1', enum: ['v1', 'v2'] },
27
26
  PLT_ELU_HEALTH_SIGNAL_THRESHOLD: { type: 'number', default: 0.9 },
28
27
  PLT_HEAP_HEALTH_SIGNAL_THRESHOLD: { type: ['number', 'string'], default: '4GB' }
29
28
  }
@@ -1,4 +1,5 @@
1
1
  import { request } from 'undici'
2
+ import semver from 'semver'
2
3
  import { parseMemorySize } from '@platformatic/foundation'
3
4
 
4
5
  class HealthSignalsCache {
@@ -34,9 +35,18 @@ async function healthSignals (app, _opts) {
34
35
  const servicesMetrics = {}
35
36
 
36
37
  async function setupHealthSignals () {
37
- const scalerAlgorithmVersion = app.env.PLT_SCALER_ALGORITHM_VERSION
38
+ const scalerAlgorithmVersion = app.instanceConfig?.scaler?.version ?? 'v1'
38
39
  if (scalerAlgorithmVersion !== 'v2') return
39
40
 
41
+ const runtimeVersion = app.watt.getRuntimeVersion()
42
+ if (semver.lt(runtimeVersion, '1.4.0')) {
43
+ app.log.warn(
44
+ `Watt version "${runtimeVersion}" does not support health signals for the Signal Scaler Algorithm.` +
45
+ 'Please update your watt-extra to version 1.4.0 or higher.'
46
+ )
47
+ return
48
+ }
49
+
40
50
  const eluThreshold = app.env.PLT_ELU_HEALTH_SIGNAL_THRESHOLD
41
51
 
42
52
  let heapThreshold = app.env.PLT_HEAP_HEALTH_SIGNAL_THRESHOLD
package/plugins/init.js CHANGED
@@ -40,6 +40,8 @@ async function initPlugin (app) {
40
40
  const instanceConfig = await initApplicationInstance(instanceId, applicationName)
41
41
  app.log.info({ applicationId: instanceConfig.applicationId }, 'Got application info')
42
42
 
43
+ instanceConfig.scaler ??= { version: 'v1' }
44
+
43
45
  // Use the application name from the ICC response if not provided
44
46
  applicationName = applicationName || instanceConfig.applicationName
45
47
  app.log.info({ applicationName }, 'Application name resolved')
@@ -27,6 +27,7 @@ test('should send health signals when service becomes unhealthy', async (t) => {
27
27
  const icc = await startICC(t, {
28
28
  applicationId,
29
29
  applicationName,
30
+ scaler: { version: 'v2' },
30
31
  processSignals: (req) => {
31
32
  assert.equal(req.headers.authorization, 'Bearer test-token')
32
33
  receivedSignalReqs.push(req.body)
@@ -46,8 +47,7 @@ test('should send health signals when service becomes unhealthy', async (t) => {
46
47
  PLT_ICC_URL: 'http://127.0.0.1:3000',
47
48
  PLT_DISABLE_FLAMEGRAPHS: false,
48
49
  PLT_FLAMEGRAPHS_INTERVAL_SEC: 2,
49
- PLT_FLAMEGRAPHS_ELU_THRESHOLD: 0,
50
- PLT_SCALER_ALGORITHM_VERSION: 'v2'
50
+ PLT_FLAMEGRAPHS_ELU_THRESHOLD: 0
51
51
  })
52
52
 
53
53
  const app = await start()
package/test/helper.js CHANGED
@@ -35,6 +35,7 @@ async function startICC (t, opts = {}) {
35
35
  applicationId,
36
36
  applicationName,
37
37
  applicationMetricsLabel,
38
+ scaler,
38
39
  iccServices,
39
40
  iccConfig = {},
40
41
  enableOpenTelemetry = false,
@@ -111,6 +112,7 @@ async function startICC (t, opts = {}) {
111
112
  applicationName,
112
113
  applicationMetricsLabel,
113
114
  iccServices,
115
+ scaler,
114
116
  config: iccConfig,
115
117
  enableOpenTelemetry,
116
118
  enableSlicerInterceptor,