Should Agent could expose "clients" property? #1996
Answered
by
ronag
StefanCenusa
asked this question in
Q&A
Replies: 3 comments 5 replies
-
What do you need the pool stats for? Wouldn't diagnostic channels be a solution? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I don't know what "diagnostic channels" are, but I need the PoolStats (or stats) for the clients created by the agent. There can be multiple reasons for this requirement. Monitoring can be one (exposing stats for each origin to a prometheus endpoint), but in my current use-case I need those stats to make a client-side circuit breaking:
|
Beta Was this translation helpful? Give feedback.
4 replies
-
class MyPool extends Pool {
#full = false
constructor () {
super()
this.on('drain', () => { this.#full = false })
}
dispatch(...args) {
const ret = super.dispatch(...args)
this.#full = !ret
return ret
}
}
const dispatcher = new MyPool()
undici.request(url, { dispatcher }) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
StefanCenusa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
Recently I've tried switching from NodeJS keep-alive agent to undici and one thing that I was unable to do without hacking undici was to access the clients created by an Agent instance. (this property)
My Agent talks to many origins and I need to see the PoolStats on each of those Pools that it creates.
My current solution was to replicate the code of the Agent (the initialisation and handling of clients), something like this:
however, if I had acces to the clients map (or client stats) I could have avoided this hacky approach.
I think my topic relates a bit to this one.
What do you think it's the right approach here?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions