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

Remove minimum constraint on OpenSearch hosts to allow empty host and refactor status API to not include OpenSearch status when host is empty #4701

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Add resource ID filtering in fetch `augment-vis` obj queries ([#4608](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4608))
- Reduce the amount of comments in compiled CSS ([#4648](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4648))
- [Saved Object Service] Customize saved objects service status ([#4696](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4696))
- Remove minimum constraint on opensearch hosts to allow empty host ([#4701](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4701))
- [Discover] Update styles to compatible with OUI `next` theme ([#4644](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4644))
- Remove visualization editor sidebar background ([#4719](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4719))
- [Vis Colors] Remove customized colors from sample visualizations and dashboards ([#4741](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4741))
Expand Down
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