Compare commits

...

4 Commits

Author SHA1 Message Date
7733eec328 Prepare 7.17.14 (#2294)
* Prepare 7.17.14

* Tweaks to Github action
2024-07-02 11:33:33 -05:00
d614d95b8d Do not retry on timeout by default (#2293)
* Do not retry on timeout by default

* Stop testing on Node.js 12

No longer available on actions/setup-node

* Node.js 14.x is no longer available for testing either

* Fix linter issue

* Update acceptance tests

* Add retryOnTimeout to type defs

* Linter cleanup

* Drop code coverage step from Github action
2024-06-28 13:28:52 -05:00
af385f0bac Update changelog for 7.17.13 (#2020) 2023-09-26 11:11:58 -05:00
02c5b8664e Skip adding new nodes that aren't ready yet (#1994) 2023-08-31 12:23:49 -05:00
10 changed files with 181 additions and 143 deletions

View File

@ -9,36 +9,36 @@ jobs:
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [16.x, 18.x, 20.x]
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: |
npm install
- name: Install
run: |
npm install
- name: Lint
run: |
npm run lint
- name: Lint
run: |
npm run lint
- name: Unit test
run: |
npm run test:unit
- name: Unit test
run: |
npm run test:unit
- name: Acceptance test
run: |
npm run test:acceptance
- name: Acceptance test
run: |
npm run test:acceptance
- name: Type Definitions
run: |
npm run test:types
- name: Type Definitions
run: |
npm run test:types
helpers-integration-test:
name: Helpers integration test
@ -46,133 +46,99 @@ jobs:
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Runs Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 7.16-SNAPSHOT
- name: Runs Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 7.17-SNAPSHOT
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: |
npm install
- name: Install
run: |
npm install
- name: Integration test
run: |
npm run test:integration:helpers
- name: Integration test
run: |
npm run test:integration:helpers
bundler-support:
name: Bundler support
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Runs Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 7.16-SNAPSHOT
- name: Runs Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 7.17-SNAPSHOT
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Use Node.js 16.x
uses: actions/setup-node@v4
with:
node-version: 16.x
- name: Install
run: |
npm install
npm install --prefix test/bundlers/parcel-test
npm install --prefix test/bundlers/rollup-test
npm install --prefix test/bundlers/webpack-test
- name: Install
run: |
npm install
npm install --prefix test/bundlers/parcel-test
npm install --prefix test/bundlers/rollup-test
npm install --prefix test/bundlers/webpack-test
- name: Build
run: |
npm run build --prefix test/bundlers/parcel-test
npm run build --prefix test/bundlers/rollup-test
npm run build --prefix test/bundlers/webpack-test
- name: Build
run: |
npm run build --prefix test/bundlers/parcel-test
npm run build --prefix test/bundlers/rollup-test
npm run build --prefix test/bundlers/webpack-test
- name: Run bundle
run: |
npm start --prefix test/bundlers/parcel-test
npm start --prefix test/bundlers/rollup-test
npm start --prefix test/bundlers/webpack-test
- name: Run bundle
run: |
npm start --prefix test/bundlers/parcel-test
npm start --prefix test/bundlers/rollup-test
npm start --prefix test/bundlers/webpack-test
mock-support:
name: Mock support
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Use Node.js 14.x
uses: actions/setup-node@v4
with:
node-version: 14.x
- name: Install
run: |
npm install
npm install --prefix test/mock
- name: Install
run: |
npm install
npm install --prefix test/mock
- name: Run test
run: |
npm test --prefix test/mock
code-coverage:
name: Code coverage
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: |
npm install
- name: Code coverage report
run: |
npm run test:coverage-report
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.lcov
fail_ci_if_error: true
- name: Code coverage 100%
run: |
npm run test:coverage-100
- name: Run test
run: |
npm test --prefix test/mock
license:
name: License check
@ -183,17 +149,17 @@ jobs:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: |
npm install
- name: Install
run: |
npm install
- name: License checker
run: |
npm run license-checker
- name: License checker
run: |
npm run license-checker

View File

@ -1,6 +1,24 @@
[[changelog-client]]
== Release notes
[discrete]
=== 7.17.14
[discrete]
==== Fixes
Stops retrying timed-out requests by default.
Re-enabling the old behavior can be done by providing a `retryOnTimeout` option when instantiating the client.
https://github.com/elastic/elasticsearch-js/pull/2293[#2293]
[discrete]
=== 7.17.13
[discrete]
==== Fixes
Fixes a bug where newly-added nodes that don't have HTTP information yet should be skipped during sniffing, to prevent an unexpected `TypeError`. https://github.com/elastic/elasticsearch-js/issues/1230[#1230]
[discrete]
=== 7.17.12
@ -18,7 +36,7 @@ This is the first 7.x release where patch versions of the client will no longer
Fixes a type declaration bug that caused TypeScript builds to fail. https://github.com/elastic/elasticsearch-js/pull/1927[#1927]
[discrete]
===== Add TypeScript type declarations to exports
===== Add TypeScript type declarations to exports
Adds TypeScript type declarations file to package.json `exports` https://github.com/elastic/elasticsearch-js/pull/1930[#1930]

1
lib/Transport.d.ts vendored
View File

@ -49,6 +49,7 @@ interface TransportOptions {
serializer: Serializer;
maxRetries: number;
requestTimeout: number | string;
retryOnTimeout?: boolean;
suggestCompression?: boolean;
compression?: 'gzip';
sniffInterval?: number;

View File

@ -57,6 +57,7 @@ class Transport {
this.serializer = opts.serializer
this.maxRetries = opts.maxRetries
this.requestTimeout = toMs(opts.requestTimeout)
this.retryOnTimeout = opts.retryOnTimeout != null ? opts.retryOnTimeout : false
this.suggestCompression = opts.suggestCompression === true
this.compression = opts.compression || false
this.context = opts.context || null
@ -220,6 +221,13 @@ class Transport {
})
}
// do not retry timeout errors by default
if (err.name === 'TimeoutError' && this.retryOnTimeout !== true) {
err.meta = result
this.emit('response', err, result)
return callback(err, result)
}
// retry logic
if (meta.attempts < maxRetries) {
meta.attempts++

View File

@ -206,6 +206,10 @@ class BaseConnectionPool {
for (let i = 0, len = ids.length; i < len; i++) {
const node = nodes[ids[i]]
// newly-added nodes do not have http assigned yet, so skip
if (node.http === undefined) continue
// If there is no protocol in
// the `publish_address` new URL will throw
// the publish_address can have two forms:

View File

@ -12,8 +12,8 @@
"./*": "./*.js"
},
"homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html",
"version": "7.17.12",
"versionCanary": "7.17.12-canary.1",
"version": "7.17.14",
"versionCanary": "7.17.14-canary.0",
"keywords": [
"elasticsearch",
"elastic",

View File

@ -88,7 +88,8 @@ test('Connection error', t => {
const client = new Client({
node: 'http://localhost:9200',
Connection: MockConnectionError,
maxRetries: 1
maxRetries: 1,
retryOnTimeout: true
})
const order = [
@ -124,18 +125,18 @@ test('Connection error', t => {
})
test('TimeoutError error', t => {
t.plan(10)
t.plan(8)
const client = new Client({
node: 'http://localhost:9200',
Connection: MockConnectionTimeout,
maxRetries: 1
maxRetries: 1,
retryOnTimeout: true
})
const order = [
events.SERIALIZATION,
events.REQUEST,
events.REQUEST,
events.RESPONSE
]
@ -170,7 +171,8 @@ test('RequestAbortedError error', t => {
const client = new Client({
node: 'http://localhost:9200',
Connection: MockConnectionTimeout,
maxRetries: 1
maxRetries: 1,
retryOnTimeout: true
})
const order = [
@ -221,7 +223,8 @@ test('ResponseError error (no retry)', t => {
const client = new Client({
node: 'http://localhost:9200',
Connection: MockConnection,
maxRetries: 1
maxRetries: 1,
retryOnTimeout: true
})
const order = [
@ -373,7 +376,8 @@ test('Deserialization Error', t => {
const client = new Client({
node: 'http://localhost:9200',
Connection: MockConnection,
maxRetries: 1
maxRetries: 1,
retryOnTimeout: true
})
const order = [
@ -423,7 +427,11 @@ test('Socket destroyed while reading the body', t => {
}
buildServer(handler, ({ port }, server) => {
const client = new Client({ node: `http://localhost:${port}`, maxRetries: 1 })
const client = new Client({
node: `http://localhost:${port}`,
maxRetries: 1,
retryOnTimeout: true
})
const order = [
events.SERIALIZATION,

View File

@ -680,7 +680,8 @@ test('TimeoutError', t => {
const client = new Client({
node: 'http://localhost:9200',
Connection: MockConnectionTimeout,
maxRetries: 0
maxRetries: 0,
retryOnTimeout: true
})
client.on('request', (err, event) => {

View File

@ -313,6 +313,36 @@ test('API', t => {
t.end()
})
t.test('Should skip nodes that do not have an http property yet', t => {
const pool = new BaseConnectionPool({ Connection })
const nodes = {
a1: {
http: {
publish_address: '127.0.0.1:9200'
},
roles: ['master', 'data', 'ingest']
},
a2: {
roles: ['master', 'data', 'ingest']
}
}
t.same(pool.nodesToHost(nodes, 'http:'), [{
url: new URL('http://127.0.0.1:9200'),
id: 'a1',
roles: {
master: true,
data: true,
ingest: true,
ml: false
}
}])
t.equal(pool.nodesToHost(nodes, 'http:').length, 1)
t.equal(pool.nodesToHost(nodes, 'http:')[0].url.host, '127.0.0.1:9200')
t.end()
})
t.end()
})

View File

@ -1025,6 +1025,7 @@ test('Retry mechanism and abort', t => {
serializer: new Serializer(),
maxRetries: 2,
requestTimeout: 100,
retryOnTimeout: true,
sniffInterval: false,
sniffOnStart: false
})
@ -2203,6 +2204,7 @@ test('Compress request', t => {
serializer: new Serializer(),
maxRetries: 3,
requestTimeout: 250,
retryOnTimeout: true,
sniffInterval: false,
sniffOnStart: false
})