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 e1e7cc7d..b026e24d 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,16 @@ 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 c2d7247c..2d2ba5b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ project adheres to [Semantic Versioning](http://semver.org/). - remove unnecessary loop from `osMemoryHeapLinux` - Improve performance of `hashObject` by using pre-sorted array of label names - Fix type of `collectDefaultMetrics.metricsList` +- Allow running in Bun by skipping incompatible default metrics. ### Added diff --git a/lib/metrics/gc.js b/lib/metrics/gc.js index f26818ab..a2cea657 100644 --- a/lib/metrics/gc.js +++ b/lib/metrics/gc.js @@ -6,8 +6,10 @@ let perf_hooks; try { // eslint-disable-next-line perf_hooks = require('perf_hooks'); + new perf_hooks.PerformanceObserver(); } catch { - // node version is too old + // node version is too old, or Bun + perf_hooks = false; } const NODEJS_GC_DURATION_SECONDS = 'nodejs_gc_duration_seconds'; diff --git a/lib/metrics/heapSpacesSizeAndUsed.js b/lib/metrics/heapSpacesSizeAndUsed.js index 472be21c..9786126a 100644 --- a/lib/metrics/heapSpacesSizeAndUsed.js +++ b/lib/metrics/heapSpacesSizeAndUsed.js @@ -11,6 +11,12 @@ METRICS.forEach(metricType => { }); module.exports = (registry, config = {}) => { + try { + v8.getHeapSpaceStatistics(); + } catch { + return; // Bun + } + const registers = registry ? [registry] : undefined; const namePrefix = config.prefix ? config.prefix : ''; diff --git a/test/metrics/gcTest.js b/test/metrics/gcTest.js index 81253cfb..0edba1a8 100644 --- a/test/metrics/gcTest.js +++ b/test/metrics/gcTest.js @@ -33,8 +33,10 @@ describe.each([ try { // eslint-disable-next-line perf_hooks = require('perf_hooks'); + new perf_hooks.PerformanceObserver(); } catch { - // node version is too old + // node version is too old, or Bun + perf_hooks = false; } if (perf_hooks) {