Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 48dcef4975 | |||
| b5a36f37ab | |||
| a31920b785 | |||
| 846c50b8bf | |||
| 5204faeb66 |
@ -171,7 +171,18 @@ a|`function` - Takes a `Connection` and returns `true` if it can be sent a reque
|
||||
_Default:_
|
||||
[source,js]
|
||||
----
|
||||
() => true
|
||||
function defaultNodeFilter (conn) {
|
||||
if (conn.roles != null) {
|
||||
if (
|
||||
// avoid master-only nodes
|
||||
conn.roles.master &&
|
||||
!conn.roles.data &&
|
||||
!conn.roles.ingest &&
|
||||
!conn.roles.ml
|
||||
) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
----
|
||||
|
||||
|`nodeSelector`
|
||||
|
||||
@ -1,6 +1,18 @@
|
||||
[[changelog-client]]
|
||||
== Release notes
|
||||
|
||||
[discrete]
|
||||
=== 8.18.1
|
||||
|
||||
[discrete]
|
||||
==== Fixes
|
||||
|
||||
[discrete]
|
||||
===== Fix broken node roles and node filter
|
||||
|
||||
The docs note a `nodeFilter` option on the client that will, by default, filter the nodes based on any `roles` values that are set at instantition. At some point, this functionality was partially disabled. This brings the feature back, ensuring that it matches what the documentation has said it does all along.
|
||||
|
||||
[discrete]
|
||||
=== 8.18.0
|
||||
|
||||
[discrete]
|
||||
|
||||
@ -97,7 +97,7 @@ client.diagnostic.on('request', (err, result) => {
|
||||
----
|
||||
|
||||
|`deserialization`
|
||||
a|Emitted before starting deserialization and decompression. If you want to measure this phase duration, you should measure the time elapsed between this event and `response`. _(This event might not be emitted in certain situations)_.
|
||||
a|Emitted before starting deserialization and decompression. If you want to measure this phase duration, you should measure the time elapsed between this event and `response`. This event might not be emitted in certain situations, like: when `asStream` is set to true; a response is terminated early due to content length being too large; or a response is terminated early by an `AbortController`.
|
||||
[source,js]
|
||||
----
|
||||
client.diagnostic.on('deserialization', (err, result) => {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@elastic/elasticsearch",
|
||||
"version": "8.18.0",
|
||||
"versionCanary": "8.18.0-canary.0",
|
||||
"version": "8.18.1",
|
||||
"versionCanary": "8.18.1-canary.0",
|
||||
"description": "The official Elasticsearch client for Node.js",
|
||||
"main": "./index.js",
|
||||
"types": "index.d.ts",
|
||||
@ -89,7 +89,7 @@
|
||||
"zx": "7.2.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@elastic/transport": "^8.9.1",
|
||||
"@elastic/transport": "^8.9.6",
|
||||
"apache-arrow": "^18.0.0",
|
||||
"tslib": "^2.4.0"
|
||||
},
|
||||
|
||||
@ -78,6 +78,13 @@ export interface NodeOptions {
|
||||
ssl?: TlsConnectionOptions
|
||||
/** @property headers Custom HTTP headers that should be sent with each request */
|
||||
headers?: Record<string, any>
|
||||
/** @property roles Common Elasticsearch roles that can be assigned to this node. Can be helpful when writing custom nodeFilter or nodeSelector functions. */
|
||||
roles?: {
|
||||
master: boolean
|
||||
data: boolean
|
||||
ingest: boolean
|
||||
ml: boolean
|
||||
}
|
||||
}
|
||||
|
||||
export interface ClientOptions {
|
||||
@ -135,7 +142,7 @@ export interface ClientOptions {
|
||||
* @defaultValue null */
|
||||
agent?: HttpAgentOptions | UndiciAgentOptions | agentFn | false
|
||||
/** @property nodeFilter A custom function used by the connection pool to determine which nodes are qualified to receive a request
|
||||
* @defaultValue () => true */
|
||||
* @defaultValue A function that uses the Connection `roles` property to avoid master-only nodes */
|
||||
nodeFilter?: nodeFilterFn
|
||||
/** @property nodeSelector A custom function used by the connection pool to determine which node should receive the next request
|
||||
* @defaultValue A "round robin" function that loops sequentially through each node in the pool. */
|
||||
|
||||
@ -77,6 +77,31 @@ test('Missing node(s)', t => {
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('multi nodes with roles, using default node filter', async t => {
|
||||
const client = new Client({
|
||||
nodes: [
|
||||
{
|
||||
url: new URL('http://node1:9200'),
|
||||
roles: { master: true, data: false, ingest: false, ml: false }
|
||||
},
|
||||
{
|
||||
url: new URL('http://node2:9200'),
|
||||
roles: { master: true, data: true, ingest: false, ml: false }
|
||||
},
|
||||
]
|
||||
})
|
||||
const conn = client.connectionPool.getConnection({
|
||||
now: Date.now() + 1000 * 60 * 3,
|
||||
requestId: 1,
|
||||
name: 'elasticsearch-js',
|
||||
context: null
|
||||
})
|
||||
|
||||
t.equal(conn?.url.hostname, 'node2')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('Custom headers', t => {
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
|
||||
Reference in New Issue
Block a user