Skip to content

Commit cb2bc41

Browse files
committed
update cpu count collector | remove npm cache from tests
1 parent fdfdd1c commit cb2bc41

4 files changed

Lines changed: 5 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
uses: actions/setup-node@v4
2222
with:
2323
node-version: ${{ matrix.node-version }}
24-
cache: npm
2524

2625
- name: Install dependencies
2726
run: npm install

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,10 +854,12 @@ Main agent singleton instance.
854854

855855
## Changelog
856856

857-
### v1.0.17 (Bug Fixes)
857+
### v1.0.17 (Bug Fixes & Testing)
858858

859859
- **DDP queue unblock recursion fix** - Restructured `DDPQueueCollector.wrapUnblock()` to eliminate a remaining infinite recursion path. The catch block previously retried calling `originalUnblock()` after a failure, but `originalUnblock` can itself be a wrapper from another layer (e.g., `MethodTracer`). If that wrapper threw, the retry would re-enter it, creating unbounded mutual recursion and `RangeError: Maximum call stack size exceeded`. The fix sets the `unblocked` guard immediately on entry, isolates metrics collection in its own try/catch so failures are non-fatal, and calls `originalUnblock()` exactly once with no retry. (fixes [#7](https://github.com/SkySignalAPM/agent/issues/7))
860860
- **Console error object serialization** - `ErrorTracker` now properly serializes object arguments passed to `console.error()` using `JSON.stringify` instead of `String()`. Previously, `console.error('test', {a:1, b:2})` would be captured as `"test [object Object]"` — it now correctly captures `"test {"a":1,"b":2}"`. The same fix applies to `UnhandledRejection` events where the rejection reason is a plain object rather than an Error instance. Serialization is depth-limited (5 levels) and size-capped (5KB) to prevent oversized payloads from deeply nested objects. Circular references are detected and replaced with `"[Circular]"`. (fixes [#10](https://github.com/SkySignalAPM/agent/issues/10))
861+
- **Use `os.availableParallelism()` for CPU count** - Replaced `os.cpus().length` with `os.availableParallelism()` in `SystemMetricsCollector` and `EnvironmentCollector`. The Node.js docs advise against using `os.cpus().length` to determine available parallelism, as it can return an empty array on some systems. `os.availableParallelism()` (Node 18.14+) is the recommended API for this purpose.
862+
- **963 unit tests with GitHub Actions CI** - Added a comprehensive standalone test suite (Mocha + Chai + Sinon) covering all collectors, client modules, and library utilities. Includes regression tests for bugs #7 and #10. Tests run via `npm test` without requiring a Meteor environment. Added GitHub Actions workflow (`.github/workflows/test.yml`) to run tests on push/PR against Node.js 20 and 22.
861863

862864
### v1.0.16 (Bug Fixes)
863865

lib/collectors/EnvironmentCollector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export default class EnvironmentCollector {
145145
platform: os.platform(),
146146
release: os.release(),
147147
arch: os.arch(),
148-
cpuCount: os.cpus().length,
148+
cpuCount: os.availableParallelism(),
149149
cpuModel: os.cpus()[0]?.model || "unknown",
150150
totalMemory: os.totalmem(),
151151
freeMemory: os.freemem(),

lib/collectors/SystemMetricsCollector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export default class SystemMetricsCollector {
133133

134134
// CPU metrics
135135
const cpuUsage = this._getCpuUsage();
136-
const cpuCores = os.cpus().length;
136+
const cpuCores = os.availableParallelism();
137137
const loadAverage = os.loadavg();
138138

139139
// Memory metrics

0 commit comments

Comments
 (0)