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

Typescriptify search source #47644

Merged
merged 88 commits into from
Nov 26, 2019

Conversation

lukasolson
Copy link
Member

@lukasolson lukasolson commented Oct 8, 2019

Summary

Typescriptify & jestify courier/search source.

Closes #46315.

Closes #49661

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@lukasolson lukasolson requested a review from ppisljar November 20, 2019 23:54
@lukeelmers lukeelmers self-requested a review November 21, 2019 15:18
@lukasolson
Copy link
Member Author

@elastic/ml-ui Could I get a quick review on the ML files changed here?

Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 left a comment

Choose a reason for hiding this comment

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

Gave this a test and LGTM for ML 👍

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.

code LGTM

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

Overall code LGTM! I added a handful of comments, most very minor items that aren't critical to merging this. I also had a few questions on areas I'm not familiar with.

getRequestInspectorStats,
getResponseInspectorStats,
} from '../../courier/utils/courier_inspector_utils';
import { getRequestInspectorStats, getResponseInspectorStats } from '../../courier';
Copy link
Member

Choose a reason for hiding this comment

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

nit: Could combine these imports from ../../courier

public resp: any;
constructor(err: any, resp?: any) {
public resp: SearchResponse;
constructor(err: any, resp?: SearchResponse) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if err could/should be typed more strictly? Should this be SearchError?

* under the License.
*/

import { IndexPattern } from '../../../../core_plugins/data/public';
Copy link
Member

Choose a reason for hiding this comment

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

Probably better to use the interface exposed from the new platform plugin for this:

Suggested change
import { IndexPattern } from '../../../../core_plugins/data/public';
import { IIndexPattern } from '../../../../../plugins/data/public';

(Same probably applies to a handful of other places in this PR, I added comments wherever I saw them)

function normalize(
sortable: EsQuerySortValue,
indexPattern: IndexPattern | string | undefined,
defaultSortOptions: any
Copy link
Member

Choose a reason for hiding this comment

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

should this be defaultSortOptions: SortOptions?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, defaultSortOptions comes from an advanced UI setting. We could probably type it but it really should come from Elasticsearch since it represents additional parameters you can send in your sort portion of a search request.

*/

import { SearchSource } from '../search_source';
import { IndexPattern } from '../../../../core_plugins/data/public/index_patterns';
Copy link
Member

Choose a reason for hiding this comment

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

IIndexPattern from the NP plugin is preferred if it works here

this.filtersSearchSource = searchSource.create();
this.filtersSearchSource.setParent(timeRangeSearchSource);
this.filtersSearchSource = searchSource.create()!;
this.filtersSearchSource!.setParent(timeRangeSearchSource);
Copy link
Member

Choose a reason for hiding this comment

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

I think tsc will still work without the ! on these two lines

@@ -39,15 +48,20 @@ export function callClient(searchRequests, requestsOptions = [], { es, config, e
Object.keys(searchStrategyMap).forEach(searchStrategyId => {
const searchStrategy = getSearchStrategyById(searchStrategyId);
const requests = searchStrategyMap[searchStrategyId];
const { searching, abort } = searchStrategy.search({ searchRequests: requests, es, config, esShardTimeout });

const { searching, abort } = searchStrategy!.search({
Copy link
Member

Choose a reason for hiding this comment

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

If getSearchStrategyById could possibly return undefined, then maybe we should be adding an if (searchStrategy) {} check here, so that TS doesn't need the !

Copy link
Member Author

Choose a reason for hiding this comment

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

Updating getSearchStrategyById to never return undefined.

options: FetchOptions,
{ es, config, esShardTimeout }: FetchHandlers
) {
const msToDelay = config!.get('courier:batchSearches') ? 50 : 0;
Copy link
Member

Choose a reason for hiding this comment

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

I think the ! can be removed here

request={request.body}
response={response}
request={request.body as Request}
response={response as ResponseWithShardFailure}
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe casting is necessary here

Comment on lines +106 to +107
export type SearchRequest = any;
export type SearchResponse = any;
Copy link
Member

Choose a reason for hiding this comment

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

Would Record<string, any> or Record<string, unknown> work here?

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@lukasolson lukasolson merged commit e3a97dd into elastic:master Nov 26, 2019
lukasolson added a commit to lukasolson/kibana that referenced this pull request Nov 26, 2019
@lukasolson
Copy link
Member Author

7.x (7.6.0): #51682

lukasolson added a commit that referenced this pull request Nov 26, 2019
@lukasolson lukasolson deleted the typescriptifySearchSource branch December 2, 2019 22:37
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 release_note:skip Skip the PR/issue when compiling release notes review v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lens error message appears in the preview Typescriptify search source
8 participants