-
-
Couldn't load subscription status.
- Fork 672
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
Conversation
lib/core/symbols.js
Outdated
| kHttpProxyAgent: Symbol('http proxy agent'), | ||
| kHttpsProxyAgent: Symbol('https proxy agent') | ||
| kHttpsProxyAgent: Symbol('https proxy agent'), | ||
| kStats: Symbol('stats') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used now by Pool and Client. Hence it should be shared in my opinion.
lib/dispatcher/client-stats.js
Outdated
| @@ -0,0 +1,28 @@ | |||
| 'use strict' | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follows implementation of PoolStats. Clients however expose a subset of stats. Hence the separate class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll put this class in utils or so, as the files within the dispatcher/ dir are mostly mean for classes that shares dispatcher interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Same for the PoolStats then which prior to this change lived here too, right?
lib/dispatcher/client.js
Outdated
| this[kResume] = (sync) => resume(this, sync) | ||
| this[kOnError] = (err) => onError(this, err) | ||
|
|
||
| this[kStats] = new ClientStats(this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as with Pools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add testing for it?
lib/dispatcher/client-stats.js
Outdated
| @@ -0,0 +1,28 @@ | |||
| 'use strict' | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll put this class in utils or so, as the files within the dispatcher/ dir are mostly mean for classes that shares dispatcher interface.
Yip. I followed the Pool Stats addition PR in terms of depth of testing on only existing through tsd. |
|
Hi @metcoder95! In ab942e4 I've moved the pool stats both of pool and client into a Should we also add docs and maybe an example? |
|
👋🏼 @metcoder95 in 15bc63b I started adding some documentation where I thought it would help. |
|
Anything else you see should be improved @metcoder95? Thanks! |
|
@metcoder95 can you approve the workflows again. There was a type issue on the |
|
@metcoder95 I can't see that tests fail due to my changes with Error: Cannot find module '../../deps/undici/src/index.js'
Require stack:
- /home/runner/work/undici/undici/node-v23.11.0/test/parallel/test-inspector-network-fetch.js
at Function._resolveFilename (node:internal/modules/cjs/loader:1405:15)
at defaultResolveImpl (node:internal/modules/cjs/loader:1061:19)
at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1066:22)
at Function._load (node:internal/modules/cjs/loader:1215:37)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
at Module.require (node:internal/modules/cjs/loader:1491:12)
at require (node:internal/modules/helpers:135:16)
at Object.<anonymous> (/home/runner/work/undici/undici/node-v23.11.0/test/parallel/test-inspector-network-fetch.js:15:16)
at Module._compile (node:internal/modules/cjs/loader:1734:14) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/runner/work/undici/undici/node-v23.11.0/test/parallel/test-inspector-network-fetch.js'
]
}or is that something you can help with? I've little to no experience with the CI setup of this repository. |
| get size () { | ||
| return this[kPool][kSize] | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. From what I understand 7ac13ff is what you had in mind?
55566bb to
7ac13ff
Compare
lib/core/symbols.js
Outdated
| kNoProxyAgent: Symbol('no proxy agent'), | ||
| kHttpProxyAgent: Symbol('http proxy agent'), | ||
| kHttpsProxyAgent: Symbol('https proxy agent'), | ||
| kStats: Symbol('stats') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed anymore. Not assigned as property any longer.
|
|
||
| get stats () { | ||
| return this[kStats] | ||
| return new ClientStats(this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New class every time accessed.
lib/util/stats.js
Outdated
| this[kClient] = client | ||
| } | ||
|
|
||
| get connected () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not getters just instance properties.
|
@metcoder95 the failing tests appear to be unrelated. ✔ SqliteCacheStore (16.3615ms)
✖ SqliteCacheStore works nicely with multiple stores (19.9884ms)
✔ SqliteCacheStore maxEntries (4.9747ms)
✔ SqliteCacheStore two writes (0.8221ms)
✔ SqliteCacheStore write & read (1.2954ms)
Error: [Error [ERR_TEST_FAILURE]: failed running after hook] { code: 'ERR_TEST_FAILURE', failureType: 'hookFailed', cause: [Error: EBUSY: resource busy or locked, unlink 'D:\a\undici\undici\cache-interceptor.sqlite'] { errno: -4082, code: 'EBUSY', syscall: 'unlink', path: 'D:\\a\\undici\\undici\\cache-interceptor.sqlite' } }Is this a known issue. Something I have to or you could have a look into? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
|
PTAL @ronag @metcoder95 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
|
@metcoder95 I need some help with the failing tests. I can't see them as relating to the proposed changes. Can you provide some guidance? |
|
Feel free them, they are not related to your changes as you suggests; I'm starting to dig deeper into it to see if can sort it out. |
|
@metcoder95 sorry to nudge but did you end up anywhere? I tried to understand what's going on but can not find the root cause. |
|
They are not a blocker for your PR but rather due to other reasons; feel free to ignore them |
@metcoder95 Does that mean you would merge the PR or is something else missing to land this? |
|
LGTM, waiting for @ronag review |
|
Whooop. Thanks all. All approvals are there. I am excited. /cc @metcoder95 |
|
Thanks for the support and release. The next version of |
|
Was it intentional to omit stats from |
|
Lol please ignore me. I didn't realize I was using undici v6 and this was added in v7. 🤦♂️ |
This relates to:
This relates to the issue #4149
Rationale
Integrating existing and exposed Pool stats into a telemetry system is a bit cumbersome. Right now we can hook into the
factoryfunction and observe the created pool there. It would be beneficial if a Pool's and Client's stats would be exposed by the Agent owning the Pool or Client respectively.Changes
Exposing stats through the Agent makes it easier to integrate telemetry systems as we do not have to "hook" into the
factoryto receive the Pool or Client used by an Agent.Features
Exposes a new getter called
statson an Agent. The method returns an Array of Arrays with stats by origin.Additionally, the Client now also exposes available stats similar to a Pool. The initial implementation of Pool stats happened in this PR while the implementation for a Client here follows the Pool's implementation pattenr.
Bug Fixes
Breaking Changes and Deprecations
Status