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 10, 2023
1 parent 9253a37 commit 35d4ff9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
1 change: 0 additions & 1 deletion config/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,3 @@

# Set the value of this setting to true to enable plugin augmentation on Dashboard
# vis_augmenter.pluginAugmentationEnabled: true

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
35 changes: 26 additions & 9 deletions src/core/server/status/status_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ import { ServiceStatus, CoreStatus, InternalStatusServiceSetup } from './types';
import { getSummaryStatus } from './get_summary_status';
import { PluginsStatusService } from './plugins_status';

import { OpenSearchConfig } from '../../server/opensearch';
import { OpenSearchConfigType } from '../opensearch/opensearch_config';

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

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')
.pipe(map((rawConfig) => new OpenSearchConfig(rawConfig)));
}

public async setup({
Expand All @@ -78,7 +85,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 +149,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 35d4ff9

Please sign in to comment.