Skip to content

Add StatsControl support#68

Open
mayankkumar12345 wants to merge 10 commits into
mainfrom
statscontrol-port
Open

Add StatsControl support#68
mayankkumar12345 wants to merge 10 commits into
mainfrom
statscontrol-port

Conversation

@mayankkumar12345

@mayankkumar12345 mayankkumar12345 commented Jun 22, 2026

Copy link
Copy Markdown
Member

Adds Java SDK parity StatsControl support to the Node.js SDK.

Includes:

  • StatsControl public API
  • stats profile, interval, pretty print, enable log, handler, start/stop
  • request, retry, latency, request size, result size, connection stats
  • query stats under ALL profile
  • p95/p99 latency support
  • HttpClient.execute() stats integration
  • stats examples and load-check helper
  • unit and functional test coverage
  • README documentation

Validation:

  • npm run test:mocha -- --no-config --reporter dot test/unit/stats.js test/unit/stats_control.js
  • npm run test:stats-functional:cloudsim
  • npm run test:tsc
  • npm pack --dry-run

Notes:

  • CloudSim stats load check should use:
    node examples/javascript/stats_load_check.js --config examples/config/cloudsim.json --operation fullFlow --table Users --profile ALL --total 1 --concurrency 1

  • KV proxy/KVLite stats load check should use:
    node examples/javascript/stats_load_check.js --config examples/config/kvlite.json --operation fullFlow --table Users --profile ALL --total 1 --concurrency 1

  • ALL profile can include query text and query plans, matching Java SDK behaviour.

@oracle-contributor-agreement

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Jun 22, 2026
@oracle-contributor-agreement oracle-contributor-agreement Bot added OCA Verified All contributors have signed the Oracle Contributor Agreement. and removed OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. labels Jun 22, 2026
@mayankkumar12345

Copy link
Copy Markdown
Member Author

I updated the PR based on the Java parity review.

Main changes:

  • Cleaned up the public client API so stats are accessed through getStatsControl(), instead of exposing extra stats helper methods directly on NoSQLClient.
  • Restored Java-style chaining for StatsControl setters: setProfile(), setPrettyPrint(), and setStatsHandler().
  • Kept start() and stop() as void methods, matching Java.
  • Moved logical query stats collection so it happens only after query defaults and validation succeed.
  • Fixed interval behavior so setProfile() alone does not start interval logging; start() is what activates it, like Java.
  • Added regression tests for the query validation case and interval-start behavior.

Validation:
npm run test:mocha -- --no-config --reporter dot test/unit/stats.js test/unit/stats_control.js
npm run test:tsc

@connelly38

Copy link
Copy Markdown
Member

@mayankkumar12345 @Akshay-Sundarraj I recommend you add @cezarfx as a reviewer.

Comment thread src/types/nosql_client.d.ts Outdated
* or the statistics were last cleared.
* @returns {object} Statistics object
*/
getStats(): object;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Java user register StatsHandler and get a call-back periodically. How it works in nodejs? Why client has methods to expose stats?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now client is exposed to the statscontrol only.

Comment thread src/types/stats_control.d.ts
Comment thread examples/javascript/stats_check.js Outdated
console.error(err);
} finally {
if (client != null) {
const stats = client.getStats();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In java and python client does not expose stats directly. Also, do we have a way to start and stop collection like in statsControl.start(); and statsControl.stop();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now client is exposed to the statscontrol only so the client.getstats() is removed.Yes there is the way to start and stop the collections using start() and stop() functions.

Comment thread lib/types/config.js
Comment thread lib/types/config.js Outdated
* log output should be pretty-printed.
* @property {boolean} [statsEnableLog=true] Whether interval statistics
* should be logged.
* @property {function|object} [statsHandler] Handler called with a statistics

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can statsHandler be concrete class instead of object?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can but this implementation supports a function callback or an object with accept(stats), matching Java’s handler.accept(stats) style that's why I kept it like this.

I updated the JSDoc to document this as StatsHandler instead of generic function|object, so its clear that plain objects are not valid unless they implement accept(stats).

Comment thread lib/stats.js
Comment thread lib/stats.js
Comment thread lib/stats_control.js
Comment thread lib/stats_control.js
Comment thread test/unit/stats.js
Mayank Kumar added 2 commits June 30, 2026 13:49
… recording logical query stats.

- Updated examples/docs to prefer StatsControl.Profile constants instead of raw profile strings.
- Added JSDoc for StatsHandler to show it accepts either a callback function or an object with accept(stats).
- Added short comments in stats.js and stats_control.js to explain the main stats classes and flow.
- Added top-level comments in stats-related test files.

@mayankkumar12345 mayankkumar12345 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed review comments and added replies for the remaining points.

Comment thread lib/query/common.js
Comment thread lib/types/config.js
Comment thread lib/config.js
throw new NoSQLArgumentError(
`Invalid statsEnableLog value: ${cfg.statsEnableLog}`, cfg);
}
if (cfg.statsHandler != null &&

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but user can pass anything in stats handler so this check would be necessary.

Comment thread lib/types/config.js Outdated
* log output should be pretty-printed.
* @property {boolean} [statsEnableLog=true] Whether interval statistics
* should be logged.
* @property {function|object} [statsHandler] Handler called with a statistics

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can but this implementation supports a function callback or an object with accept(stats), matching Java’s handler.accept(stats) style that's why I kept it like this.

I updated the JSDoc to document this as StatsHandler instead of generic function|object, so its clear that plain objects are not valid unless they implement accept(stats).

Comment thread lib/stats.js
Comment thread lib/stats_control.js
Comment thread src/types/stats_control.d.ts
Comment thread test/unit/stats.js
Comment thread src/types/nosql_client.d.ts Outdated
* or the statistics were last cleared.
* @returns {object} Statistics object
*/
getStats(): object;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now client is exposed to the statscontrol only.

Comment thread examples/javascript/stats_check.js Outdated
console.error(err);
} finally {
if (client != null) {
const stats = client.getStats();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now client is exposed to the statscontrol only so the client.getstats() is removed.Yes there is the way to start and stop the collections using start() and stop() functions.

@Akshay-Sundarraj Akshay-Sundarraj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked basic flow and formatting. Looks fine to me. Get approval from @cezarfx and merge

@Akshay-Sundarraj

Copy link
Copy Markdown
Member

Please check with cezar on git commit. Ideally we should have only 1 commit log for this entire PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants