@platformatic/watt-extra 1.19.1-alpha.2 → 1.21.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/watt-extra",
3
- "version": "1.19.1-alpha.2",
3
+ "version": "1.21.0",
4
4
  "description": "The Platformatic runtime manager",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -19,10 +19,10 @@
19
19
  },
20
20
  "devDependencies": {
21
21
  "@fastify/websocket": "^11.1.0",
22
- "@platformatic/composer": "^3.73.0-alpha.0",
23
- "@platformatic/next": "^3.73.0-alpha.0",
24
- "@platformatic/node": "^3.73.0-alpha.0",
25
- "@platformatic/service": "^3.73.0-alpha.0",
22
+ "@platformatic/composer": "^3.73.0",
23
+ "@platformatic/next": "^3.73.0",
24
+ "@platformatic/node": "^3.73.0",
25
+ "@platformatic/service": "^3.73.0",
26
26
  "atomic-sleep": "^1.0.0",
27
27
  "borp": "^1.0.0",
28
28
  "eslint": "10",
@@ -31,16 +31,16 @@
31
31
  "iovalkey": "^0.4.0",
32
32
  "neostandard": "0.14.0-next.1",
33
33
  "next": "^16.2.10",
34
- "platformatic": "^3.73.0-alpha.0",
34
+ "platformatic": "^3.73.0",
35
35
  "pprof-format": "^2.1.0",
36
36
  "why-is-node-running": "^2.3.0"
37
37
  },
38
38
  "dependencies": {
39
39
  "@datadog/pprof": "^5.9.0",
40
40
  "@fastify/error": "^4.2.0",
41
- "@platformatic/foundation": "^3.73.0-alpha.0",
42
- "@platformatic/runtime": "^3.73.0-alpha.0",
43
- "@platformatic/wattpm-pprof-capture": "^3.73.0-alpha.0",
41
+ "@platformatic/foundation": "^3.73.0",
42
+ "@platformatic/runtime": "^3.73.0",
43
+ "@platformatic/wattpm-pprof-capture": "^3.73.0",
44
44
  "avvio": "^9.1.0",
45
45
  "commist": "^3.2.0",
46
46
  "env-schema": "^8.0.0",
package/plugins/alerts.js CHANGED
@@ -130,29 +130,37 @@ async function alerts (app, _opts) {
130
130
  lastServicesAlertTime[serviceId] = currentTime
131
131
  delete healthInfo.healthConfig
132
132
 
133
- const authHeaders = await app.getAuthorizationHeaders()
134
-
135
- const { statusCode, body } = await request(`${scalerUrl}/alerts`, {
136
- method: 'POST',
137
- headers: {
138
- 'Content-Type': 'application/json',
139
- ...authHeaders
140
- },
141
- body: JSON.stringify({
142
- applicationId: app.instanceConfig?.applicationId,
143
- alert: healthInfo,
144
- healthHistory: healthCache
133
+ // This runs in a runtime event listener, where an error would be an unhandled rejection
134
+ // that stops the runtime
135
+ let alert
136
+ try {
137
+ const authHeaders = await app.getAuthorizationHeaders()
138
+
139
+ const { statusCode, body } = await request(`${scalerUrl}/alerts`, {
140
+ method: 'POST',
141
+ headers: {
142
+ 'Content-Type': 'application/json',
143
+ ...authHeaders
144
+ },
145
+ body: JSON.stringify({
146
+ applicationId: app.instanceConfig?.applicationId,
147
+ alert: healthInfo,
148
+ healthHistory: healthCache
149
+ })
145
150
  })
146
- })
147
151
 
148
- if (statusCode !== 200) {
149
- const error = await body.text()
150
- app.log.error({ error }, 'Failed to send alert to scaler')
152
+ if (statusCode !== 200) {
153
+ const error = await body.text()
154
+ app.log.error({ error }, 'Failed to send alert to scaler')
155
+ return
156
+ }
157
+
158
+ alert = await body.json()
159
+ } catch (err) {
160
+ app.log.error({ err }, 'Failed to send alert to scaler')
151
161
  return
152
162
  }
153
163
 
154
- const alert = await body.json()
155
-
156
164
  app.sendFlamegraphs({
157
165
  workerIds: [workerId],
158
166
  alertId: alert.id
@@ -364,6 +364,54 @@ test('should not fail when health info is missing', async (t) => {
364
364
  assert.strictEqual(alertReceived, null, 'No alert should have been received')
365
365
  })
366
366
 
367
+ test('should not fail when the scaler sends an invalid alert response', async (t) => {
368
+ const applicationName = 'test-app'
369
+ const applicationId = randomUUID()
370
+ const applicationPath = join(__dirname, 'fixtures', 'service-1')
371
+
372
+ let alertsReceived = 0
373
+
374
+ const icc = await startICC(t, {
375
+ applicationId,
376
+ applicationName,
377
+ // An empty response, which is not valid JSON
378
+ processAlerts: () => {
379
+ alertsReceived++
380
+ }
381
+ })
382
+
383
+ setUpEnvironment({
384
+ PLT_APP_NAME: applicationName,
385
+ PLT_APP_DIR: applicationPath,
386
+ PLT_ICC_URL: 'http://127.0.0.1:3000'
387
+ })
388
+
389
+ const app = await start()
390
+
391
+ t.after(async () => {
392
+ await app.close()
393
+ await icc.close()
394
+ })
395
+
396
+ const unhandledRejections = []
397
+ const onUnhandledRejection = (err) => unhandledRejections.push(err)
398
+ process.on('unhandledRejection', onUnhandledRejection)
399
+ t.after(() => process.removeListener('unhandledRejection', onUnhandledRejection))
400
+
401
+ emitHealthEvent(app, {
402
+ id: 'main:0',
403
+ application: 'main',
404
+ currentHealth: { elu: 0.95, heapUsed: 76798040, heapTotal: 99721216 },
405
+ unhealthy: true,
406
+ healthConfig: { enabled: true, maxELU: 0.85, maxHeapUsed: 0.99 }
407
+ })
408
+
409
+ await sleep(500)
410
+
411
+ assert.strictEqual(alertsReceived, 1)
412
+ assert.deepStrictEqual(unhandledRejections, [])
413
+ })
414
+
367
415
  test('should respect alert retention window', async (t) => {
368
416
  const applicationName = 'test-app'
369
417
  const applicationId = randomUUID()