From 5dd8ac4805aa98deb78f615be9f98f47d3fd35ff Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Thu, 8 Sep 2022 00:36:06 +0000 Subject: [PATCH] [Tests] add more tests for optimized healthcheck Add more tests to verify logic added here: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2277 That makes a request for nodes info with a list of node ids. Issue: n/a Signed-off-by: Kawika Avilla --- .../ensure_opensearch_version.test.ts | 162 +++++++++++++++++- 1 file changed, 160 insertions(+), 2 deletions(-) diff --git a/src/core/server/opensearch/version_check/ensure_opensearch_version.test.ts b/src/core/server/opensearch/version_check/ensure_opensearch_version.test.ts index 709e5c4309f2..e00117dfb9f5 100644 --- a/src/core/server/opensearch/version_check/ensure_opensearch_version.test.ts +++ b/src/core/server/opensearch/version_check/ensure_opensearch_version.test.ts @@ -251,7 +251,7 @@ describe('pollOpenSearchNodesVersion', () => { }); it('returns compatibility results and isCompatible=true with filters', (done) => { - expect.assertions(2); + expect.assertions(3); const target = { cluster_id: '0', attribute: 'foo', @@ -293,6 +293,11 @@ describe('pollOpenSearchNodesVersion', () => { .pipe(take(1)) .subscribe({ next: (result) => { + expect(internalClient.nodes.info).toBeCalledWith({ + node_id: '_local', + metric: 'process', + filter_path: ['nodes.*.version', 'nodes.*.http.publish_address', 'nodes.*.ip'], + }); expect(result).toEqual( mapNodesVersionCompatibility(filteredNodes, OPENSEARCH_DASHBOARDS_VERSION, false) ); @@ -304,7 +309,7 @@ describe('pollOpenSearchNodesVersion', () => { }); it('returns compatibility results and isCompatible=false with filters', (done) => { - expect.assertions(2); + expect.assertions(3); const target = { cluster_id: '0', attribute: 'foo', @@ -346,6 +351,11 @@ describe('pollOpenSearchNodesVersion', () => { .pipe(take(1)) .subscribe({ next: (result) => { + expect(internalClient.nodes.info).toBeCalledWith({ + node_id: '_local', + metric: 'process', + filter_path: ['nodes.*.version', 'nodes.*.http.publish_address', 'nodes.*.ip'], + }); expect(result).toEqual( mapNodesVersionCompatibility(filteredNodes, OPENSEARCH_DASHBOARDS_VERSION, false) ); @@ -356,6 +366,154 @@ describe('pollOpenSearchNodesVersion', () => { }); }); + it('returns compatibility results and isCompatible=true with filters and multiple cluster ids', (done) => { + expect.assertions(3); + const nodes = {} as any; + nodes['node-0'] = { + version: '5.1.0', + http: { + publish_address: 'http_address', + }, + ip: 'ip', + attributes: { + cluster_id: '0', + custom_attribute: 'foo', + }, + }; + nodes['node-1'] = { + version: '5.1.0', + http: { + publish_address: 'http_address', + }, + ip: 'ip', + attributes: { + cluster_id: '1', + custom_attribute: 'foo', + }, + }; + nodes['node-2'] = { + version: '6.2.0', + http: { + publish_address: 'http_address', + }, + ip: 'ip', + attributes: { + cluster_id: '2', + custom_attribute: 'bar', + }, + }; + const filteredNodes = nodes; + delete filteredNodes['node-2']; + + // @ts-expect-error we need to return an incompatible type to use the testScheduler here + internalClient.cluster.state.mockReturnValueOnce({ body: { nodes } }); + + nodeInfosSuccessOnce({ nodes: filteredNodes }); + + pollOpenSearchNodesVersion({ + internalClient, + optimizedHealthcheck: { id: 'cluster_id', filters: { custom_attribute: 'bar' } }, + opensearchVersionCheckInterval: 1, + ignoreVersionMismatch: false, + opensearchDashboardsVersion: OPENSEARCH_DASHBOARDS_VERSION, + log: mockLogger, + }) + .pipe(take(1)) + .subscribe({ + next: (result) => { + expect(internalClient.nodes.info).toBeCalledWith({ + node_id: ['node-0', 'node-1'], + metric: 'process', + filter_path: ['nodes.*.version', 'nodes.*.http.publish_address', 'nodes.*.ip'], + }); + expect(result).toEqual( + mapNodesVersionCompatibility( + { nodes: filteredNodes }, + OPENSEARCH_DASHBOARDS_VERSION, + false + ) + ); + expect(result.isCompatible).toBe(true); + }, + complete: done, + error: done, + }); + }); + + it('returns compatibility results and isCompatible=false with filters and multiple cluster ids', (done) => { + expect.assertions(3); + const nodes = {} as any; + nodes['node-0'] = { + version: '5.1.0', + http: { + publish_address: 'http_address', + }, + ip: 'ip', + attributes: { + cluster_id: '0', + custom_attribute: 'foo', + }, + }; + nodes['node-1'] = { + version: '6.2.0', + http: { + publish_address: 'http_address', + }, + ip: 'ip', + attributes: { + cluster_id: '1', + custom_attribute: 'foo', + }, + }; + nodes['node-2'] = { + version: '6.2.0', + http: { + publish_address: 'http_address', + }, + ip: 'ip', + attributes: { + cluster_id: '2', + custom_attribute: 'bar', + }, + }; + const filteredNodes = nodes; + delete filteredNodes['node-2']; + + // @ts-expect-error we need to return an incompatible type to use the testScheduler here + internalClient.cluster.state.mockReturnValueOnce({ body: { nodes } }); + + nodeInfosSuccessOnce({ nodes: filteredNodes }); + + pollOpenSearchNodesVersion({ + internalClient, + optimizedHealthcheck: { id: 'cluster_id', filters: { custom_attribute: 'bar' } }, + opensearchVersionCheckInterval: 1, + ignoreVersionMismatch: false, + opensearchDashboardsVersion: OPENSEARCH_DASHBOARDS_VERSION, + log: mockLogger, + }) + .pipe(take(1)) + .subscribe({ + next: (result) => { + expect(internalClient.nodes.info).toBeCalledWith({ + node_id: ['node-0', 'node-1'], + metric: 'process', + filter_path: ['nodes.*.version', 'nodes.*.http.publish_address', 'nodes.*.ip'], + }); + expect(result).toEqual( + mapNodesVersionCompatibility( + { nodes: filteredNodes }, + OPENSEARCH_DASHBOARDS_VERSION, + false + ) + ); + expect(result.isCompatible).toBe(false); + }, + complete: done, + error: done, + }); + }); + it('only emits if the node versions changed since the previous poll', (done) => { expect.assertions(4); nodeInfosSuccessOnce(createNodes('5.1.0', '5.2.0', '5.0.0')); // emit