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

[skip ci] Data access service #38737

Closed
wants to merge 11 commits into from

Conversation

lukasolson
Copy link
Member

@lukasolson lukasolson commented Jun 12, 2019

Summary

Relies on #37563.

This PR introduces the new data access service API. It's the first step towards #34022. Specifically, this PR introduces a new server endpoint (/api/search) which accepts raw Elasticsearch search DSL and sends it to Elasticsearch.

This PR also introduces both a client- and server-side tool for making such requests.

Client-side API

  // Simple example
  const index = 'twitter';
  const body = { query: { match_all: {} } };
  const results = await search({
    searchParams: { index, body }
  }).toPromise();

  // Example with aborting/handling multiple responses/progress
  const controller = new AbortController();
  window.addEventListener('unload', () => controller.abort());
  const index = 'twitter';
  const body = { query: { match_all: {} } };
  const results$ = search({
    searchParams: { index, body },
    signal
  });
  results$.subscribe({
    next: ({ _shards: { successful, failed, skipped, total }}),  => {
      console.log('percent complete: ' (successful + failed + skipped) / total);
    },
    complete: response => {
      console.log('got response: ', response);
    },
    error: error => {
      console.log('got error: ', error);
    }
  });

Server-side API

The same as the client-side API, except that the calls must also take the request that initiated the search, to forward credentials to Elasticsearch:

  const index = 'twitter';
  const body = { query: { match_all: {} } };
  const results = await search(request, {
    searchParams: { index, body }
  }).toPromise();

Eventually we intend this service/API to be a replacement for the existing Courier service.

Checklist

For maintainers

@lukasolson lukasolson added Feature:Search Querying infrastructure in Kibana :AppArch v7.3.0 labels Jun 12, 2019
@lukasolson lukasolson self-assigned this Jun 12, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch

@elasticmachine
Copy link
Contributor

💔 Build Failed

@lukasolson lukasolson changed the title Data access service [skip-ci] Data access service Jun 12, 2019
@lukasolson lukasolson changed the title [skip-ci] Data access service [skip ci] Data access service Jun 12, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

@ppisljar ppisljar added the non-issue Indicates to automation that a pull request should not appear in the release notes label Jun 13, 2019
@lukasolson lukasolson force-pushed the dataAccessService branch 2 times, most recently from fe78a07 to 116c40f Compare June 25, 2019 15:15
Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apart from some minor comments this looks good, needs test coverage still.

onProgress?: (shards: ShardProgress) => void;
signal?: AbortSignal;
strategy?: string;
sessionId?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we allow overriding any of the advanced settings here ?


export const searchStrategies: Map<string, SearchStrategy> = new Map<string, SearchStrategy>();

export function registerSearchStrategy(name: string, strategy: SearchStrategy) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a getter rather than exposing whole 'registry'

import { getEsSearchConfig } from './get_es_search_config';

export function registerDefaultSearchStrategy(server: Server) {
registerSearchStrategy('default', async function defaultSearchStrategy(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: i would prefer exporting searchStrategy function here and doing registration init

@lukasolson lukasolson added v7.5.0 and removed v7.4.0 labels Aug 29, 2019
@lukasolson lukasolson mentioned this pull request Sep 3, 2019
13 tasks
maxConcurrentShardRequests: searchParams.hasOwnProperty('maxConcurrentShardRequests')
? (searchParams as any).maxConcurrentShardRequests
: await getMaxConcurrentShardRequests(request),
ignoreThrottled: searchParams.hasOwnProperty('ignoreThrottled')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this can get moved to the x-pack search strategy. Maybe getSearchParams should be part of the search strategy? e.g.

export interface ISearchStrategy {
  search: (request: Request, searchArguments: SearchArguments) => Observable<SearchResponse<any>>;
  getSearchParams: (
    request: Request,
    searchParams: SearchParams,
    options: SearchOptions
  ) => SearchParams;
}

Then the x-pack implementation can use the default one plus incorporate some additional settings that are commercial only?

? searchParams.preference
: await getPreference(request, options),
maxConcurrentShardRequests: searchParams.hasOwnProperty('maxConcurrentShardRequests')
? (searchParams as any).maxConcurrentShardRequests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why maxConcurrentShardRequests isn't in the SearchParams type? Is it an oversight in the typing or is this a kibana specific param?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I see it's only part of msearch. I guess for search endpoint it's irrelevant.

}
}

export async function getMaxConcurrentShardRequests(request: Request) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is returning any type because of config.get. If we know the shape of return value, maybe it can be typed out explicitly here?

if (maxConcurrentShardRequests !== 0) return maxConcurrentShardRequests;
}

// TODO: Move to a plugin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see this comment now!

@lukasolson
Copy link
Member Author

Superseded by #43371.

@lukasolson lukasolson closed this Sep 18, 2019
@lukasolson lukasolson deleted the dataAccessService branch December 2, 2019 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Search Querying infrastructure in Kibana non-issue Indicates to automation that a pull request should not appear in the release notes v7.5.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants