Inspect Connection (#784)
Handles `console.log` and `utils.inspect` invocations for a better debugging experience. `agent` and `ssl` are hidden since they made the logs very hard to read. The user can still access them with `instance.agent` and `instance.ssl`.
This commit is contained in:
committed by
delvedor
parent
358474bca8
commit
1d61cba014
@ -20,6 +20,7 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const { inspect } = require('util')
|
||||
const http = require('http')
|
||||
const https = require('https')
|
||||
const debug = require('debug')('elasticsearch')
|
||||
@ -54,7 +55,7 @@ class Connection {
|
||||
maxSockets: keepAliveFalse ? Infinity : 256,
|
||||
maxFreeSockets: 256
|
||||
}, opts.agent)
|
||||
this._agent = this.url.protocol === 'http:'
|
||||
this.agent = this.url.protocol === 'http:'
|
||||
? new http.Agent(agentOptions)
|
||||
: new https.Agent(Object.assign({}, agentOptions, this.ssl))
|
||||
|
||||
@ -146,7 +147,7 @@ class Connection {
|
||||
if (this._openRequests > 0) {
|
||||
setTimeout(() => this.close(callback), 1000)
|
||||
} else {
|
||||
this._agent.destroy()
|
||||
this.agent.destroy()
|
||||
callback()
|
||||
}
|
||||
}
|
||||
@ -193,7 +194,7 @@ class Connection {
|
||||
auth: !!url.username === true || !!url.password === true
|
||||
? `${url.username}:${url.password}`
|
||||
: undefined,
|
||||
agent: this._agent
|
||||
agent: this.agent
|
||||
}
|
||||
|
||||
const paramsKeys = Object.keys(params)
|
||||
@ -218,6 +219,23 @@ class Connection {
|
||||
|
||||
return request
|
||||
}
|
||||
|
||||
// Handles console.log and utils.inspect invocations.
|
||||
// We want to hide `agent` and `ssl` since they made
|
||||
// the logs very hard to read. The user can still
|
||||
// access them with `instance.agent` and `instance.ssl`.
|
||||
[inspect.custom] (depth, options) {
|
||||
return {
|
||||
url: this.url,
|
||||
id: this.id,
|
||||
headers: this.headers,
|
||||
deadCount: this.deadCount,
|
||||
resurrectTimeout: this.resurrectTimeout,
|
||||
_openRequests: this._openRequests,
|
||||
status: this.status,
|
||||
roles: this.roles
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connection.statuses = {
|
||||
|
||||
Reference in New Issue
Block a user