-
-
Couldn't load subscription status.
- Fork 674
Add stats of client and pool to be accessible through agent #4157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2661544
28ec198
df86d9b
4370e3d
2947cba
39c7617
651eb86
0c22ba5
8855ecb
ab942e4
f2452c4
15bc63b
5a93529
435acc8
373736e
52e7d94
7ac13ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Class: ClientStats | ||
|
|
||
| Stats for a [Client](/docs/docs/api/Client.md). | ||
|
|
||
| ## `new ClientStats(client)` | ||
|
|
||
| Arguments: | ||
|
|
||
| * **client** `Client` - Client from which to return stats. | ||
|
|
||
| ## Instance Properties | ||
|
|
||
| ### `ClientStats.connected` | ||
|
|
||
| Boolean if socket as open connection by this client. | ||
|
|
||
| ### `ClientStats.pending` | ||
|
|
||
| Number of pending requests of this client. | ||
|
|
||
| ### `ClientStats.running` | ||
|
|
||
| Number of currently active requests across this client. | ||
|
|
||
| ### `ClientStats.size` | ||
|
|
||
| Number of active, pending, or queued requests of this clients. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ const assert = require('node:assert') | |
| const net = require('node:net') | ||
| const http = require('node:http') | ||
| const util = require('../core/util.js') | ||
| const { ClientStats } = require('../util/stats.js') | ||
| const { channels } = require('../core/diagnostics.js') | ||
| const Request = require('../core/request.js') | ||
| const DispatcherBase = require('./dispatcher-base') | ||
|
|
@@ -260,6 +261,10 @@ class Client extends DispatcherBase { | |
| this[kResume](true) | ||
| } | ||
|
|
||
| get stats () { | ||
| return new ClientStats(this) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New class every time accessed. |
||
| } | ||
|
|
||
| get [kPending] () { | ||
| return this[kQueue].length - this[kPendingIdx] | ||
| } | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| 'use strict' | ||
|
|
||
| const { | ||
| kConnected, | ||
| kPending, | ||
| kRunning, | ||
| kSize, | ||
| kFree, | ||
| kQueued | ||
| } = require('../core/symbols') | ||
|
|
||
| class ClientStats { | ||
| constructor (client) { | ||
| this.connected = client[kConnected] | ||
| this.pending = client[kPending] | ||
| this.running = client[kRunning] | ||
| this.size = client[kSize] | ||
| } | ||
| } | ||
|
|
||
| class PoolStats { | ||
| constructor (pool) { | ||
| this.connected = pool[kConnected] | ||
| this.free = pool[kFree] | ||
| this.pending = pool[kPending] | ||
| this.queued = pool[kQueued] | ||
| this.running = pool[kRunning] | ||
| this.size = pool[kSize] | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand this design. Instead of using getters, I would allocate new objects. This ensures that data is stable in time without having to copy them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be fair I also didn't but this it the current implementation and I am following it assuming it has reasoning. In that this code is just moved from elsewhere as requested by @metcoder95. Do you wish to have this changed here or as a follow up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👋🏼 What's the implicit agreement here? Refactor as a follow-up, not at all or here? I understand the issue that the using getters can cause inconsistent as a whole with single values. I assume we would return an object of a "stats bag" in the pool and agent. Just not sure when/where to implement it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @metcoder95 what's missing on this PR to land this? Anything expected from my side? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just applying the suggested refactor from getters to a plain object (it can also come from a class, but avoiding the getters/setters). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. From what I understand 7ac13ff is what you had in mind? |
||
|
|
||
| module.exports = { ClientStats, PoolStats } | ||
Uh oh!
There was an error while loading. Please reload this page.