Skip to content

Commit

Permalink
Remove minimum constraint on opensearch hosts
Browse files Browse the repository at this point in the history
Signed-off-by: Bandini Bhopi <[email protected]>
  • Loading branch information
bandinib-amzn committed Aug 14, 2023
1 parent b038322 commit ab5b588
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 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
9 changes: 0 additions & 9 deletions src/core/server/saved_objects/saved_objects_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,6 @@ export class SavedObjectsService
'Waiting until all OpenSearch nodes are compatible with OpenSearch Dashboards before starting saved objects migrations...'
);

// TODO: Move to Status Service https://github.com/elastic/kibana/issues/41983
this.setupDeps!.opensearch.opensearchNodesCompatibility$.subscribe(
({ isCompatible, message }) => {
if (!isCompatible && message) {
this.logger.error(message);
}
}
);

await this.setupDeps!.opensearch.opensearchNodesCompatibility$.pipe(
filter((nodes) => nodes.isCompatible),
take(1)
Expand Down
21 changes: 18 additions & 3 deletions src/core/server/status/status_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,34 @@ import { of, BehaviorSubject } from 'rxjs';
import { ServiceStatus, ServiceStatusLevels, CoreStatus } from './types';
import { StatusService } from './status_service';
import { first } from 'rxjs/operators';
import { mockCoreContext } from '../core_context.mock';
import { ServiceStatusLevelSnapshotSerializer } from './test_utils';
import { environmentServiceMock } from '../environment/environment_service.mock';
import { httpServiceMock } from '../http/http_service.mock';
import { metricsServiceMock } from '../metrics/metrics_service.mock';
import { CoreContext } from '../core_context';
import { configServiceMock, loggingSystemMock } from '../mocks';
import { Env } from '../config';
import { REPO_ROOT } from '@osd/dev-utils';
import { getEnvOptions } from '../config/mocks';

expect.addSnapshotSerializer(ServiceStatusLevelSnapshotSerializer);

const configService = configServiceMock.create();
configService.atPath.mockReturnValue(
new BehaviorSubject({
hosts: ['http://1.2.3.4'],
} as any)
);
let env: Env;
let coreContext: CoreContext;
const logger = loggingSystemMock.create();
describe('StatusService', () => {
let service: StatusService;
env = Env.createDefault(REPO_ROOT, getEnvOptions());

coreContext = { coreId: Symbol(), env, logger, configService: configService as any };

beforeEach(() => {
service = new StatusService(mockCoreContext.create());
service = new StatusService(coreContext);
});

const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
Expand Down
31 changes: 22 additions & 9 deletions src/core/server/status/status_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { config, StatusConfigType } from './status_config';
import { ServiceStatus, CoreStatus, InternalStatusServiceSetup } from './types';
import { getSummaryStatus } from './get_summary_status';
import { PluginsStatusService } from './plugins_status';
import { OpenSearchConfigType } from '../opensearch/opensearch_config';

interface SetupDeps {
opensearch: Pick<InternalOpenSearchServiceSetup, 'status$'>;
Expand All @@ -60,13 +61,15 @@ interface SetupDeps {
export class StatusService implements CoreService<InternalStatusServiceSetup> {
private readonly logger: Logger;
private readonly config$: Observable<StatusConfigType>;
private readonly openSearchConfig$: Observable<OpenSearchConfigType>;

private pluginsStatus?: PluginsStatusService;
private overallSubscription?: Subscription;

constructor(private readonly coreContext: CoreContext) {
this.logger = coreContext.logger.get('status');
this.config$ = coreContext.configService.atPath<StatusConfigType>(config.path);
this.openSearchConfig$ = coreContext.configService.atPath<OpenSearchConfigType>('opensearch');
}

public async setup({
Expand All @@ -78,7 +81,9 @@ export class StatusService implements CoreService<InternalStatusServiceSetup> {
environment,
}: SetupDeps) {
const statusConfig = await this.config$.pipe(take(1)).toPromise();
const core$ = this.setupCoreStatus({ opensearch, savedObjects });
const openSearchConfig = await this.openSearchConfig$.pipe(take(1)).toPromise();
const isOpenSearchEnabled = openSearchConfig.hosts.length > 0;
const core$ = this.setupCoreStatus({ opensearch, savedObjects }, isOpenSearchEnabled);
this.pluginsStatus = new PluginsStatusService({ core$, pluginDependencies });

const overall$: Observable<ServiceStatus> = combineLatest([
Expand Down Expand Up @@ -140,15 +145,23 @@ export class StatusService implements CoreService<InternalStatusServiceSetup> {
}
}

private setupCoreStatus({
opensearch,
savedObjects,
}: Pick<SetupDeps, 'opensearch' | 'savedObjects'>): Observable<CoreStatus> {
private setupCoreStatus(
{ opensearch, savedObjects }: Pick<SetupDeps, 'opensearch' | 'savedObjects'>,
isOpenSearchEnabled: boolean = true
): Observable<CoreStatus> {
return combineLatest([opensearch.status$, savedObjects.status$]).pipe(
map(([opensearchStatus, savedObjectsStatus]) => ({
opensearch: opensearchStatus,
savedObjects: savedObjectsStatus,
})),
map(([opensearchStatus, savedObjectsStatus]) => {
if (isOpenSearchEnabled) {
return {
opensearch: opensearchStatus,
savedObjects: savedObjectsStatus,
};
} else {
return {
savedObjects: savedObjectsStatus,
};
}
}),
distinctUntilChanged<CoreStatus>(isDeepStrictEqual),
shareReplay(1)
);
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/status/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export type ServiceStatusLevel = typeof ServiceStatusLevels[keyof typeof Service
* @public
*/
export interface CoreStatus {
opensearch: ServiceStatus;
opensearch?: ServiceStatus;
savedObjects: ServiceStatus;
}

Expand Down

0 comments on commit ab5b588

Please sign in to comment.