-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
54 lines (46 loc) · 2.08 KB
/
Copy pathtest.js
File metadata and controls
54 lines (46 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const test = require('brittle')
const Hyperswarm = require('hyperswarm')
const setupTestnet = require('hyperdht/testnet')
const tmpDir = require('test-tmp')
const Corestore = require('corestore')
const b4a = require('b4a')
const promClient = require('bare-prom-client')
const HypercoreInstrument = require('.')
const DEBUG = false
test('basic happy path', async (t) => {
const testnet = await setupTestnet()
const { bootstrap } = testnet
const swarm = new Hyperswarm({ bootstrap })
const corestore = new Corestore(await tmpDir(t))
const key = b4a.alloc(32)
const client = new HypercoreInstrument({
swarm,
corestore,
scraperPublicKey: key,
prometheusAlias: 'alias',
scraperSecret: key,
prometheusServiceName: 'name',
version: '1.0.0'
})
const txt = await promClient.register.metrics()
t.ok(txt.includes('hypercore_version'), 'hypercore version metric')
t.ok(txt.includes('udx_native_version'), 'udx_native_version')
t.ok(txt.includes('dht_rpc_version'), 'dht_rpc_version')
t.ok(txt.includes('hyperdht_version'), 'hyperdht_version')
t.ok(txt.includes('hyperswarm_version'), 'hyperswarm_version')
t.ok(txt.includes('corestore_version'), 'corestore_version')
t.ok(txt.includes('hyperbee_version'), 'hyperbee_version')
t.ok(txt.includes('process_pid', 'process pid included'))
t.ok(txt.includes('package_version{version="1.0.0"}', 'package version included'))
t.absent(txt.includes('autobase_version'), 'autobase not included if not available')
t.ok(txt.includes('corestore_tree_cache_hits 0'), 'hypercore version metric')
t.ok(txt.includes('corestore_tree_cache_misses 0'), 'corestore_tree_cache_misses')
t.ok(txt.includes('corestore_tree_cache_parallel 0'), 'corestore_tree_cache_parallel')
t.ok(txt.includes('corestore_tree_cache_skips 0'), 'corestore_tree_cache_skips')
t.ok(txt.includes('corestore_tree_cache_max_size'), 'corestore_tree_cache_max_size')
t.ok(txt.includes('corestore_tree_cache_entries'), 'corestore_tree_cache_entries')
if (DEBUG) console.log(txt)
await client.close()
await corestore.close()
await testnet.destroy()
})