blind-peer 2.7.4 → 2.7.5

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.
Files changed (4) hide show
  1. package/bin.js +2 -7
  2. package/index.js +40 -1
  3. package/lib/db.js +6 -0
  4. package/package.json +1 -1
package/bin.js CHANGED
@@ -43,13 +43,8 @@ const cmd = command('blind-peer',
43
43
 
44
44
  const blindPeer = new BlindPeer(storage, { trustedPubKeys, maxBytes, port })
45
45
 
46
- blindPeer.on('post-to-mailbox', req => {
47
- try {
48
- logger.info(`post-to-mailbox request received for mailbox: ${idEnc.normalize(req.mailbox)} with message ${idEnc.normalize(req.message)})`)
49
- } catch {
50
- logger.info('Invalid post-to-mailbox request received')
51
- logger.info(req)
52
- }
46
+ blindPeer.on('flush-error', e => {
47
+ logger.warn(`Error while flushing the db: ${e.stack}`)
53
48
  })
54
49
 
55
50
  blindPeer.on('add-core', record => {
package/index.js CHANGED
@@ -174,7 +174,9 @@ class BlindPeer extends ReadyResource {
174
174
 
175
175
  this.stats = {
176
176
  bytesGcd: 0,
177
- coresAdded: 0
177
+ coresAdded: 0,
178
+ activations: 0,
179
+ wakeups: 0
178
180
  }
179
181
  }
180
182
 
@@ -224,6 +226,8 @@ class BlindPeer extends ReadyResource {
224
226
  }
225
227
 
226
228
  async _onwakeup (discoveryKey, muxer) {
229
+ this.stats.wakeups++
230
+
227
231
  const auth = await this.store.storage.getAuth(discoveryKey)
228
232
  if (!auth) return
229
233
 
@@ -331,6 +335,7 @@ class BlindPeer extends ReadyResource {
331
335
  if (this.enableGc && this.needsGc()) await this._gc()
332
336
  if (this.db.updated()) await this.db.flush()
333
337
  } catch (e) {
338
+ this.emit('flush-error', e)
334
339
  safetyCatch(e)
335
340
  } finally {
336
341
  this.lock.unlock()
@@ -355,6 +360,8 @@ class BlindPeer extends ReadyResource {
355
360
  }
356
361
 
357
362
  async _activateCore (stream, record) {
363
+ this.stats.activations++
364
+
358
365
  const core = this.store.get({ key: record.key })
359
366
  await core.ready()
360
367
 
@@ -454,6 +461,14 @@ class BlindPeer extends ReadyResource {
454
461
  }
455
462
  })
456
463
 
464
+ new promClient.Gauge({ // eslint-disable-line no-new
465
+ name: 'blind_peer_cores',
466
+ help: 'The amount of cores (as reported in its digest)',
467
+ collect () {
468
+ this.set(self.digest.cores)
469
+ }
470
+ })
471
+
457
472
  new promClient.Gauge({ // eslint-disable-line no-new
458
473
  name: 'blind_peer_cores_added',
459
474
  help: 'The total amount of add-core RPC requests that have been processed',
@@ -469,6 +484,30 @@ class BlindPeer extends ReadyResource {
469
484
  this.set(self.stats.bytesGcd)
470
485
  }
471
486
  })
487
+
488
+ new promClient.Gauge({ // eslint-disable-line no-new
489
+ name: 'blind_peer_core_activations',
490
+ help: 'The total amount of hypercore activations since the process started',
491
+ collect () {
492
+ this.set(self.stats.activations)
493
+ }
494
+ })
495
+
496
+ new promClient.Gauge({ // eslint-disable-line no-new
497
+ name: 'blind_peer_wakeups',
498
+ help: 'The total amount of hypercore wakeups since the process started',
499
+ collect () {
500
+ this.set(self.stats.wakeups)
501
+ }
502
+ })
503
+
504
+ new promClient.Gauge({ // eslint-disable-line no-new
505
+ name: 'blind_peer_db_flushes',
506
+ help: 'The total amount of database flushes since the process started',
507
+ collect () {
508
+ this.set(self.db.stats.flushes)
509
+ }
510
+ })
472
511
  }
473
512
  }
474
513
 
package/lib/db.js CHANGED
@@ -20,6 +20,10 @@ module.exports = class BlindPeerDB extends ReadyResource {
20
20
  this.coresAdding = []
21
21
  this.coresUpdated = new Map()
22
22
 
23
+ this.stats = {
24
+ flushes: 0
25
+ }
26
+
23
27
  this.ready().catch(noop)
24
28
  }
25
29
 
@@ -125,6 +129,8 @@ module.exports = class BlindPeerDB extends ReadyResource {
125
129
  }
126
130
 
127
131
  if (addedCores || addedReferrers || bytesAllocated || this.closing) {
132
+ this.stats.flushes++ // we only count those flushes where we update the db
133
+
128
134
  this.digest.cores += addedCores
129
135
  this.digest.referrers += addedReferrers
130
136
  this.digest.bytesAllocated += bytesAllocated
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blind-peer",
3
- "version": "2.7.4",
3
+ "version": "2.7.5",
4
4
  "description": "Blind peers help keep hypercores available",
5
5
  "main": "index.js",
6
6
  "bin": {