-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Typescriptify search source #47644
Conversation
💔 Build Failed |
💚 Build Succeeded |
@elastic/ml-ui Could I get a quick review on the ML files changed here? |
There was a problem hiding this 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 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code LGTM
There was a problem hiding this 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'; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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:
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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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 !
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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
export type SearchRequest = any; | ||
export type SearchResponse = any; |
There was a problem hiding this comment.
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?
💚 Build Succeeded |
💔 Build Failed |
💚 Build Succeeded |
7.x (7.6.0): #51682 |
Summary
Typescriptify & jestify courier/search source.
Closes #46315.
Closes #49661