diff --git a/.editorconfig b/.editorconfig index 648cc36e..1ef11c63 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,3 +8,7 @@ end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/nodejs.yml b/.github/workflows/ci.yml similarity index 77% rename from .github/workflows/nodejs.yml rename to .github/workflows/ci.yml index c1f8182b..4d7736c2 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Node.js CI +name: CI on: push: @@ -11,7 +11,7 @@ on: - '**' jobs: - build: + nodejs: name: Test on Node.js v${{ matrix.node-version }} and OS ${{ matrix.os }} strategy: fail-fast: false @@ -40,3 +40,15 @@ jobs: run: npm i - name: Test run: npm run test + bun: + name: Test on Bun + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + - name: Install Dependencies + run: bun install + - name: Test + run: bun test-unit diff --git a/CHANGELOG.md b/CHANGELOG.md index 83d0a70c..bbb8a624 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Changed +- Enable `bun.js` by catching `NotImplemented` error (Fixes [#570](https://github.com/siimon/prom-client/issues/570)) + ### Added [unreleased]: https://github.com/siimon/prom-client/compare/v15.1.0...HEAD diff --git a/lib/metrics/eventLoopLag.js b/lib/metrics/eventLoopLag.js index 45d5c33d..86f73d71 100644 --- a/lib/metrics/eventLoopLag.js +++ b/lib/metrics/eventLoopLag.js @@ -37,32 +37,39 @@ module.exports = (registry, config = {}) => { const labelNames = Object.keys(labels); const registers = registry ? [registry] : undefined; - let collect; - if (!perf_hooks || !perf_hooks.monitorEventLoopDelay) { - collect = () => { - const start = process.hrtime(); - setImmediate(reportEventloopLag, start, lag, labels); - }; - } else { - const histogram = perf_hooks.monitorEventLoopDelay({ - resolution: config.eventLoopMonitoringPrecision, - }); - histogram.enable(); + let collect = () => { + const start = process.hrtime(); + setImmediate(reportEventloopLag, start, lag, labels); + }; - collect = () => { - const start = process.hrtime(); - setImmediate(reportEventloopLag, start, lag, labels); + if (perf_hooks && perf_hooks.monitorEventLoopDelay) { + try { + const histogram = perf_hooks.monitorEventLoopDelay({ + resolution: config.eventLoopMonitoringPrecision, + }); + histogram.enable(); - lagMin.set(labels, histogram.min / 1e9); - lagMax.set(labels, histogram.max / 1e9); - lagMean.set(labels, histogram.mean / 1e9); - lagStddev.set(labels, histogram.stddev / 1e9); - lagP50.set(labels, histogram.percentile(50) / 1e9); - lagP90.set(labels, histogram.percentile(90) / 1e9); - lagP99.set(labels, histogram.percentile(99) / 1e9); + collect = () => { + const start = process.hrtime(); + setImmediate(reportEventloopLag, start, lag, labels); - histogram.reset(); - }; + lagMin.set(labels, histogram.min / 1e9); + lagMax.set(labels, histogram.max / 1e9); + lagMean.set(labels, histogram.mean / 1e9); + lagStddev.set(labels, histogram.stddev / 1e9); + lagP50.set(labels, histogram.percentile(50) / 1e9); + lagP90.set(labels, histogram.percentile(90) / 1e9); + lagP99.set(labels, histogram.percentile(99) / 1e9); + + histogram.reset(); + }; + } catch (e) { + if (e.code === 'ERR_NOT_IMPLEMENTED') { + return; // Bun + } + + throw e; + } } const lag = new Gauge({ diff --git a/lib/metrics/heapSpacesSizeAndUsed.js b/lib/metrics/heapSpacesSizeAndUsed.js index 472be21c..9519a3b2 100644 --- a/lib/metrics/heapSpacesSizeAndUsed.js +++ b/lib/metrics/heapSpacesSizeAndUsed.js @@ -11,6 +11,14 @@ METRICS.forEach(metricType => { }); module.exports = (registry, config = {}) => { + try { + v8.getHeapSpaceStatistics(); + } catch (e) { + if (e.code === 'ERR_NOT_IMPLEMENTED') { + return; // Bun + } + throw e; + } const registers = registry ? [registry] : undefined; const namePrefix = config.prefix ? config.prefix : '';