@platformatic/watt-extra 0.1.7 → 0.1.8-alpha.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": "0.1.7",
3
+ "version": "0.1.8-alpha.0",
4
4
  "description": "The Platformatic runtime manager",
5
5
  "type": "module",
6
6
  "scripts": {
package/plugins/alerts.js CHANGED
@@ -4,10 +4,7 @@ async function alerts (app, _opts) {
4
4
  const healthCache = [] // It's OK to have this in memory, this is per-pod.
5
5
  const podHealthWindow =
6
6
  app.instanceConfig?.config?.scaler?.podHealthWindow || 60 * 1000
7
- const alertRetentionWindow =
8
- app.instanceConfig?.config?.scaler?.alertRetentionWindow || 30 * 1000
9
7
 
10
- let lastAlertTime = 0
11
8
  async function setupAlerts () {
12
9
  // Skip alerts setup if ICC is not configured
13
10
  if (!app.env.PLT_ICC_URL) {
@@ -65,13 +62,6 @@ async function alerts (app, _opts) {
65
62
  // }
66
63
 
67
64
  if (healthInfo.unhealthy) {
68
- const currentTime = Date.now()
69
- if (currentTime - lastAlertTime < alertRetentionWindow) {
70
- app.log.debug('Skipping alert, within retention window')
71
- return
72
- }
73
-
74
- lastAlertTime = currentTime
75
65
  delete healthInfo.healthConfig
76
66
 
77
67
  const authHeaders = await app.getAuthorizationHeader()
@@ -0,0 +1,2 @@
1
+ ignoredBuiltDependencies:
2
+ - better-sqlite3
@@ -327,90 +327,6 @@ test('should not fail when health info is missing', async (t) => {
327
327
  assert.strictEqual(alertReceived, null, 'No alert should have been received')
328
328
  })
329
329
 
330
- test('should respect alert retention window', async (t) => {
331
- const applicationName = 'test-app'
332
- const applicationId = randomUUID()
333
- const applicationPath = join(__dirname, 'fixtures', 'service-1')
334
-
335
- const alertsReceived = []
336
-
337
- const getAuthorizationHeader = async (headers) => {
338
- return { ...headers, authorization: 'Bearer test-token' }
339
- }
340
-
341
- const icc = await startICC(t, {
342
- applicationId,
343
- applicationName,
344
- iccConfig: {
345
- scaler: {
346
- alertRetentionWindow: 500
347
- }
348
- },
349
- processAlerts: (req) => {
350
- const alert = req.body
351
- assert.equal(req.headers.authorization, 'Bearer test-token')
352
- alertsReceived.push(alert)
353
- return { id: 'test-alert-id', ...alert }
354
- }
355
- })
356
-
357
- setUpEnvironment({
358
- PLT_APP_NAME: applicationName,
359
- PLT_APP_DIR: applicationPath,
360
- PLT_ICC_URL: 'http://127.0.0.1:3000'
361
- })
362
-
363
- const app = await start()
364
-
365
- app.getAuthorizationHeader = getAuthorizationHeader
366
-
367
- await app.setupAlerts()
368
-
369
- t.after(async () => {
370
- await app.close()
371
- await icc.close()
372
- })
373
-
374
- // Create a health info template
375
- const createHealthInfo = (unhealthy = true) => ({
376
- id: 'service-1',
377
- service: 'service-1',
378
- currentHealth: {
379
- elu: unhealthy ? 0.95 : 0.5,
380
- heapUsed: 76798040,
381
- heapTotal: 99721216
382
- },
383
- unhealthy,
384
- healthConfig: {
385
- enabled: true,
386
- interval: 1000,
387
- gracePeriod: 1000,
388
- maxUnhealthyChecks: 10,
389
- maxELU: 0.99,
390
- maxHeapUsed: 0.99,
391
- maxHeapTotal: 4294967296
392
- }
393
- })
394
-
395
- // Send first unhealthy event - should trigger alert
396
- app.watt.runtime.emit('application:worker:health', createHealthInfo(true))
397
- await sleep(100)
398
-
399
- // Send second unhealthy event immediately - should be ignored due to retention window
400
- app.watt.runtime.emit('application:worker:health', createHealthInfo(true))
401
- await sleep(100)
402
-
403
- assert.strictEqual(alertsReceived.length, 1, 'Only one alert should be sent within retention window')
404
-
405
- await sleep(500)
406
-
407
- // Send third unhealthy event - should trigger second alert
408
- app.watt.runtime.emit('application:worker:health', createHealthInfo(true))
409
- await sleep(100)
410
-
411
- assert.strictEqual(alertsReceived.length, 2, 'Second alert should be sent after retention window expires')
412
- })
413
-
414
330
  test('should not set up alerts when scaler URL is missing', async (t) => {
415
331
  const applicationName = 'test-app'
416
332
  const applicationId = randomUUID()