Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Remove minimum constraint on OpenSearch hosts to allow empty host and refactor status API to not include OpenSearch status when host is empty #4802

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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