Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
3 changes: 2 additions & 1 deletion lib/core/symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ module.exports = {
kMaxConcurrentStreams: Symbol('max concurrent streams'),
kNoProxyAgent: Symbol('no proxy agent'),
kHttpProxyAgent: Symbol('http proxy agent'),
kHttpsProxyAgent: Symbol('https proxy agent')
kHttpsProxyAgent: Symbol('https proxy agent'),
kStats: Symbol('stats')
Copy link
Contributor Author

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.

}
13 changes: 12 additions & 1 deletion lib/dispatcher/agent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { InvalidArgumentError } = require('../core/errors')
const { kClients, kRunning, kClose, kDestroy, kDispatch } = require('../core/symbols')
const { kClients, kRunning, kClose, kDestroy, kDispatch, kUrl } = require('../core/symbols')
const DispatcherBase = require('./dispatcher-base')
const Pool = require('./pool')
const Client = require('./client')
Expand Down Expand Up @@ -110,6 +110,17 @@ class Agent extends DispatcherBase {

await Promise.all(destroyPromises)
}

get stats () {
const stats = []
for (const client of this[kClients].values()) {
const stats = client.stats
if (stats) {
stats.push([client[kUrl], stats])
}
}
return stats
}
}

module.exports = Agent
28 changes: 28 additions & 0 deletions lib/dispatcher/client-stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?


const { kConnected, kPending, kRunning, kSize } = require('../core/symbols')
const kClient = Symbol('client')

class ClientStats {
constructor (client) {
this[kClient] = client
}

get connected () {
return this[kClient][kConnected]
}

get pending () {
return this[kClient][kPending]
}

get running () {
return this[kClient][kRunning]
}

get size () {
return this[kClient][kSize]
}
}

module.exports = ClientStats
6 changes: 5 additions & 1 deletion lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const util = require('../core/util.js')
const { channels } = require('../core/diagnostics.js')
const Request = require('../core/request.js')
const DispatcherBase = require('./dispatcher-base')
const ClientStats = require('./client-stats')
const {
InvalidArgumentError,
InformationalError,
Expand Down Expand Up @@ -51,7 +52,8 @@ const {
kOnError,
kHTTPContext,
kMaxConcurrentStreams,
kResume
kResume,
kStats
} = require('../core/symbols.js')
const connectH1 = require('./client-h1.js')
const connectH2 = require('./client-h2.js')
Expand Down Expand Up @@ -249,6 +251,8 @@ class Client extends DispatcherBase {

this[kResume] = (sync) => resume(this, sync)
this[kOnError] = (err) => onError(this, err)

this[kStats] = new ClientStats(this)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as with Pools.

}

get pipelining () {
Expand Down
3 changes: 1 addition & 2 deletions lib/dispatcher/pool-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const DispatcherBase = require('./dispatcher-base')
const FixedQueue = require('./fixed-queue')
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch } = require('../core/symbols')
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch, kStats } = require('../core/symbols')
const PoolStats = require('./pool-stats')

const kClients = Symbol('clients')
Expand All @@ -16,7 +16,6 @@ const kOnConnectionError = Symbol('onConnectionError')
const kGetDispatcher = Symbol('get dispatcher')
const kAddClient = Symbol('add client')
const kRemoveClient = Symbol('remove client')
const kStats = Symbol('stats')

class PoolBase extends DispatcherBase {
constructor () {
Expand Down
Loading