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

[Proposal] Customize Saved Objects Service Status #4655

Closed
bandinib-amzn opened this issue Aug 1, 2023 · 1 comment
Closed

[Proposal] Customize Saved Objects Service Status #4655

bandinib-amzn opened this issue Aug 1, 2023 · 1 comment
Labels
enhancement New feature or request v2.10.0

Comments

@bandinib-amzn
Copy link
Member

bandinib-amzn commented Aug 1, 2023

Overview

By default, saved objects service evaluates it’s current status based on the migration and OpenSearch node compatibility.
Using custom repository interface user is now able to register repository with non-opensearch storage options. In such cases, saved object service status should evaluate based on storage option which user chooses. The goal of this project is to provide more flexible interface so that user can customize saved object service status based on their chosen storage option. With the integration of this interface, repository factory provider and non-opensearch storage option, we can decouple saved objects service from OpenSearch.

Requirements

  • Should have the ability to set the saved object service status based on external storage options.

Architecture

For this feature following changes will be made to saved object service:

  1. SavedObjectsServiceSetup Interface: New function will be added named setStatus in SavedObjectsServiceSetup interface. This function accepts Observable of type ServiceStatus<SavedObjectStatusMeta>. Storage plugin which registers custom repository may customize the saved object service status calculation by calling this function with an Observable. Within this Observable, a plugin may choose to make the status depend on storage connection and any other factors on which their storage depend upon.

  2. SavedObjectsServiceSetup implementation: Instead of returning saved object service status evaluated based on migrator and OpenSearch by default, return following BehaviorSubject as default.

private savedObjectServiceStatus$ = new BehaviorSubject<ServiceStatus<SavedObjectStatusMeta>>({
    level: ServiceStatusLevels.unavailable,
    summary: `waiting`,
  });
  
  public async setup(setupDeps: SavedObjectsSetupDeps): Promise<InternalSavedObjectsServiceSetup> {
    .
    .
    .
    return {
        status$: this.savedObjectServiceStatus$.asObservable(),
        .
        .
        .
    }
  }
  1. SavedObjectsServiceStart : When saved object service starts, it will check if custom status has been set by plugin. If service founds custom status not null, it will update savedObjectServiceStatus$ with next() otherwise existing status evaluation will be executed.
 if (this.savedObjectServiceCustomStatus$) {
      this.savedObjectServiceCustomStatus$
        .pipe(
          map((savedObjectServiceCustomStatus) => {
            return savedObjectServiceCustomStatus;
          }),
        )
        .subscribe((value) => this.savedObjectServiceStatus$.next(value));
    } else {
      calculateStatus$(
        this.migrator$.pipe(switchMap((migrator) => migrator.getStatus$())),
        this.setupDeps.opensearch.status$
      )
        .pipe(
          map((defaultstatus) => {
            return defaultstatus;
          })
        )
        .subscribe((value) => this.savedObjectServiceStatus$.next(value));
    }

savedObjectServiceStatus$ is an observable that represents the status of a saved object service. When next() is called on this observable, it indicates that there is a new status for the saved object service, and any components or services that have subscribed to this observable will be notified of the change and can react to it. And that’s how OpenSearch-Dashboards status service will be updated.

Use case by storage plugin

const externalStatus$ = interval(1000).pipe(
    switchMap(() => {
    // Check Storage health and return status
    // e.g. const storageHealth = await this.metaStorageService.checkStorageHealth();
    return of({
        level: ServiceStatusLevels.available,
        summary: 'Saved Object Service is using Postgres and it is up',
    });
    })
);

core.savedObjects.setStatus(
    externalStatus$.pipe(
    map((externalStatus) => {
        return externalStatus;
    })
    )
);

POC : bandinib-amzn@96cc898

Partially fixes: #1441

@bandinib-amzn bandinib-amzn added the enhancement New feature or request label Aug 1, 2023
@ashwin-pc ashwin-pc pinned this issue Aug 3, 2023
@bandinib-amzn
Copy link
Member Author

PR has been merged.

@ashwin-pc ashwin-pc unpinned this issue Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v2.10.0
Projects
None yet
Development

No branches or pull requests

2 participants