Skip to content

Commit

Permalink
Skipping new nodes which do not have the http property present yet. (#…
Browse files Browse the repository at this point in the history
…985)

* Skipping new nodes which do not have the http property present yet.

Signed-off-by: Jaco Smit <[email protected]>

* Addressing comments related to changelog and unit test

Signed-off-by: Jaco Smit <[email protected]>

---------

Signed-off-by: Jaco Smit <[email protected]>
  • Loading branch information
jaco-smit authored Feb 26, 2025
1 parent 91d672b commit f76a349
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [3.3.0]
### Changed
- Updated API to match the OpenSearch spec from Feb 11, 2025
### Fixed
- Skip nodes that are not ready yet ([#984](https://github.com/opensearch-project/opensearch-js/issues/984))

## [3.2.0]
### Changed
Expand Down
6 changes: 6 additions & 0 deletions lib/pool/BaseConnectionPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ class BaseConnectionPool {

for (let i = 0, len = ids.length; i < len; i++) {
const node = nodes[ids[i]];

// New nodes do not have the http property populated yet. Skip this for now.
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:
Expand Down
29 changes: 29 additions & 0 deletions test/unit/base-connection-pool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,5 +628,34 @@ test('API', (t) => {
}
});

t.test('Should skip nodes when the http property is undefined', (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,
},
},
]);

t.end();
});

t.end();
});

0 comments on commit f76a349

Please sign in to comment.