Skip to content

Commit

Permalink
Remove minimum constraint on opensearch hosts (#4701)
Browse files Browse the repository at this point in the history
Signed-off-by: Bandini Bhopi <[email protected]>
(cherry picked from commit 8e1ec99)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
github-actions[bot] committed Aug 23, 2023
1 parent 999c08a commit 1d9c043
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/core/server/opensearch/client/cluster_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class ClusterClient implements ICustomClusterClient {
return;
}
this.isClosed = true;
await Promise.all([this.asInternalUser.close(), this.rootScopedClient.close()]);
await Promise.all([this.asInternalUser.close(noop), this.rootScopedClient.close(noop)]);
}

private getScopedHeaders(request: ScopeableRequest): Headers {
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/opensearch/opensearch_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const configSchema = schema.object({
defaultValue: false,
}),
sniffOnConnectionFault: schema.boolean({ defaultValue: false }),
hosts: schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema, { minSize: 1 })], {
hosts: schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema)], {
defaultValue: 'http://localhost:9200',
}),
username: schema.maybe(
Expand Down
24 changes: 24 additions & 0 deletions src/core/server/opensearch/opensearch_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,30 @@ describe('#setup', () => {
expect(mockedClient.nodes.info).toHaveBeenCalledTimes(1);
});
});

it('opensearchNodeVersionCompatibility$ avoid polling when opensearch hosts is empty', async () => {
const mockedClient = mockClusterClientInstance.asInternalUser;
configService.atPath.mockReturnValueOnce(
new BehaviorSubject({
hosts: [],
healthCheck: {
delay: duration(2000),
},
ssl: {
verificationMode: 'none',
},
} as any)
);
opensearchService = new OpenSearchService(coreContext);
const setupContract = await opensearchService.setup(setupDeps);

// reset all mocks called during setup phase
MockLegacyClusterClient.mockClear();

setupContract.opensearchNodesCompatibility$.subscribe(async () => {
expect(mockedClient.nodes.info).toHaveBeenCalledTimes(0);
});
});
});

describe('#start', () => {
Expand Down
30 changes: 21 additions & 9 deletions src/core/server/opensearch/opensearch_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* under the License.
*/

import { Observable, Subject } from 'rxjs';
import { Observable, Subject, of } from 'rxjs';
import { first, map, shareReplay, takeUntil } from 'rxjs/operators';
import { merge } from '@osd/std';

Expand Down Expand Up @@ -91,14 +91,26 @@ export class OpenSearchService
this.legacyClient = this.createLegacyClusterClient('data', config);
this.client = this.createClusterClient('data', config);

const opensearchNodesCompatibility$ = pollOpenSearchNodesVersion({
internalClient: this.client.asInternalUser,
optimizedHealthcheck: config.optimizedHealthcheck,
log: this.log,
ignoreVersionMismatch: config.ignoreVersionMismatch,
opensearchVersionCheckInterval: config.healthCheckDelay.asMilliseconds(),
opensearchDashboardsVersion: this.opensearchDashboardsVersion,
}).pipe(takeUntil(this.stop$), shareReplay({ refCount: true, bufferSize: 1 }));
let opensearchNodesCompatibility$;
if (config.hosts.length > 0) {
opensearchNodesCompatibility$ = pollOpenSearchNodesVersion({
internalClient: this.client.asInternalUser,
optimizedHealthcheck: config.optimizedHealthcheck,
log: this.log,
ignoreVersionMismatch: config.ignoreVersionMismatch,
opensearchVersionCheckInterval: config.healthCheckDelay.asMilliseconds(),
opensearchDashboardsVersion: this.opensearchDashboardsVersion,
}).pipe(takeUntil(this.stop$), shareReplay({ refCount: true, bufferSize: 1 }));
} else {
this.log.debug(`Opensearch is not configured.`);
opensearchNodesCompatibility$ = of({
isCompatible: true,
message: 'Opensearch is not configured',
incompatibleNodes: [],
warningNodes: [],
opensearchDashboardsVersion: this.opensearchDashboardsVersion,
});
}

this.createLegacyCustomClient = (type, clientConfig = {}) => {
const finalConfig = merge({}, config, clientConfig);
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/opensearch/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const calculateStatus$ = (

return {
level: ServiceStatusLevels.available,
summary: `OpenSearch is available`,
summary: (message ?? `OpenSearch is available`) || `Unknown`,
meta: {
warningNodes: [],
incompatibleNodes: [],
Expand Down

0 comments on commit 1d9c043

Please sign in to comment.