35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
import test from 'brittle'
|
|
import { EbpfCollector, isEbpfEnabled } from '../server/services/collectors/ebpf.js'
|
|
import { hasEmbeddedHelper } from '../server/native/extract-helper.js'
|
|
import { EMBEDDED_HELPERS } from '../server/native/embedded-helpers.js'
|
|
|
|
test('ebpf enablement is boolean', (t) => {
|
|
t.ok(typeof isEbpfEnabled() === 'boolean')
|
|
t.ok(typeof EMBEDDED_HELPERS === 'object')
|
|
t.ok(typeof hasEmbeddedHelper('peardata-ebpf') === 'boolean')
|
|
})
|
|
|
|
test('ebpf JS fallback emits family charts', async (t) => {
|
|
const prev = process.env.PEARDATA_EBPF
|
|
process.env.PEARDATA_EBPF = '1'
|
|
const c = new EbpfCollector({ intervalMs: 40 })
|
|
/** @type {any[]} */
|
|
let batch = []
|
|
c.on('samples', (b) => {
|
|
batch = b
|
|
})
|
|
// Force JS path
|
|
c.mode = 'js'
|
|
c.running = true
|
|
c._tickJs()
|
|
await new Promise((r) => setTimeout(r, 60))
|
|
c._tickJs()
|
|
c.stop()
|
|
if (prev === undefined) delete process.env.PEARDATA_EBPF
|
|
else process.env.PEARDATA_EBPF = prev
|
|
|
|
t.ok(batch.length >= 1)
|
|
const charts = new Set(batch.map((s) => s.chart))
|
|
t.ok(charts.has('ebpf.cachestat') || charts.has('ebpf.fd'))
|
|
})
|