Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/metrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.init = _config => {
/**
* Depending on what kind of data the metric or snapshot attributes represents, a number of different payloads are
* valid. Ultimately, it depends on what the backend understands.
* @typedef {string|Object.<string, any>|Array.<string>} SnapshotOrMetricsPayload
* @typedef {Number|string|Object.<string, any>|Array.<string>} SnapshotOrMetricsPayload
*/

/**
Expand Down
19 changes: 0 additions & 19 deletions packages/shared-metrics/src/activeHandles.js

This file was deleted.

19 changes: 0 additions & 19 deletions packages/shared-metrics/src/activeRequests.js

This file was deleted.

13 changes: 13 additions & 0 deletions packages/shared-metrics/src/activeResources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* (c) Copyright IBM Corp. 2026
*/

'use strict';

exports.payloadPrefix = 'activeResources';

Object.defineProperty(exports, 'currentPayload', {
get: function () {
return process.getActiveResourcesInfo().length;
}
});
6 changes: 2 additions & 4 deletions packages/shared-metrics/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

'use strict';

const activeHandles = require('./activeHandles');
const activeRequests = require('./activeRequests');
const activeResources = require('./activeResources');
const args = require('./args');
const dependencies = require('./dependencies');
const directDependencies = require('./directDependencies');
Expand All @@ -25,8 +24,7 @@ const util = require('./util');

/** @type {Array.<import('@instana/core/src/metrics').InstanaMetricsModule>} */
const allMetrics = [
activeHandles,
activeRequests,
activeResources,
args,
dependencies,
directDependencies,
Expand Down
26 changes: 0 additions & 26 deletions packages/shared-metrics/test/activeRequests_test.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,40 @@

const expect = require('chai').expect;
const net = require('net');
const fs = require('fs');

const config = require('@instana/core/test/config');
const testUtils = require('@instana/core/test/test_util');
const activeHandles = require('../src/activeHandles');
const activeResources = require('../src/activeResources');

describe('metrics.activeHandles', function () {
describe('metrics.activeResources', function () {
this.timeout(config.getTestTimeout());

it('should export active handle count', () => {
// @ts-ignore
expect(activeHandles.currentPayload).to.equal(process._getActiveHandles().length);
it('should export active resource count', () => {
// [ 'TTYWrap', 'TTYWrap', 'TTYWrap', 'PipeWrap', 'ProcessWrap' ]
// Teletypewriter = stdin, stdout, stderr
// PipeWrap = internal pipe for process communication (test -> app)
// ProcessWrap = the child process itself
expect(activeResources.currentPayload).to.equal(5);
});

// This test is only compatible with Node.js versions lower than 11.
// The failure is due to changes introduced in commit:
// https://github.com/nodejs/node/commit/ccc3bb73db.
// We can reintroduce the test once we switch from the deprecated
// _getActiveHandles flag to getActiveResourcesInfo, which is more reliable.
// More details: https://nodejs.org/api/process.html#processgetactiveresourcesinfo
// For additional context, see: https://github.com/instana/nodejs/pull/1387

it.skip('should update handle count for a setTimeout', () => {
const previousCount = activeHandles.currentPayload;
it('should update resource count for a setTimeout', () => {
const timeoutHandle = setTimeout(() => {}, 100);

// TODO: getActiveResourcesInfo returns the correct value, but `_getActiveHandles` does not
// for v23.
expect(activeHandles.currentPayload).to.equal(previousCount + 1);
// [ 'TTYWrap', 'TTYWrap', 'TTYWrap', 'PipeWrap', 'ProcessWrap', 'Timeout' ]
expect(activeResources.currentPayload).to.equal(6);
clearTimeout(timeoutHandle);
});

it('should update requests count for a fs.open', () => {
const initialCount = activeResources.currentPayload;
const count = 13;
for (let i = 0; i < count; i++) {
fs.open(__filename, 'r', () => {});
}
expect(activeResources.currentPayload).to.equal(initialCount + count);
});

describe('with net client/server', () => {
/* eslint-disable max-len */
// Inspired by
Expand All @@ -50,19 +53,18 @@ describe('metrics.activeHandles', function () {
const connections = [];
/** @type {Array.<*>} */
const clients = [];
/** @type {*} */
let activeHandlesBefore;
let initialActiveResources = 0;

beforeEach(() => {
activeHandlesBefore = activeHandles.currentPayload;
before(() => {
initialActiveResources = activeResources.currentPayload;
server = net
.createServer(function listener(c) {
connections.push(c);
})
.listen(0, makeConnection);
});

afterEach(() => {
after(() => {
clients.forEach(client => {
client.destroy();
});
Expand All @@ -77,12 +79,11 @@ describe('metrics.activeHandles', function () {
() =>
new Promise((resolve, reject) => {
if (clients.length >= maxClients) {
// At least one handle should exist per client and one per connection, that's why we expect
// (2 * maxClients) more handles than we had initially. However, other things are happening in the Node.js
// runtime as well while this test is running, so it might actually happen that some of the unrelated
// handles that existed initially have since been removed, which is why we allow for a little wiggle room
// (-4 at the end). Without this wiggle room, this test is flaky.
expect(activeHandles.currentPayload).to.be.at.least(activeHandlesBefore + 2 * maxClients - 4);
// Initially is 5 with the test setup.
// 1 TCPServerWrap because of the server
// Max Clients is 8 (each 2 TCPSocketWrap because of client and server side)
// 1 timeoutWrap because of the makeConnection timeout
expect(activeResources.currentPayload).to.be.at.least(initialActiveResources + 1 * (maxClients * 2) + 1);
resolve();
} else {
reject(new Error('Still waiting for more clients to connect.'));
Expand Down