-
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
[esaggs][inspector]: Refactor to prep for esaggs move to server. #83199
Conversation
e7121ca
to
90aa172
Compare
@@ -40,8 +40,10 @@ interface ValueSuggestionsGetFnArgs { | |||
signal?: AbortSignal; | |||
} | |||
|
|||
const getAutocompleteTimefilter = (indexPattern: IIndexPattern) => { | |||
const { timefilter } = getQueryService().timefilter; |
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.
When I removed the getQueryService
service getter, I realized it was still being used here. Rather than revert the change, I simply updated the autocomplete
service since it was a straightforward fix.
getStartDependencies: async () => { | ||
const [, , self] = await core.getStartServices(); | ||
const { fieldFormats, indexPatterns, query, search } = self; | ||
return { | ||
addFilters: query.filterManager.addFilters.bind(query.filterManager), | ||
aggs: search.aggs, | ||
deserializeFieldFormat: fieldFormats.deserialize.bind(fieldFormats), | ||
indexPatterns, | ||
searchSource: search.searchSource, | ||
}; | ||
}, |
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.
All these service dependencies are now wired up in the top-level plugin.ts
, which should make it easy to update when we register the function on the server.
Some of these dependencies may also be adjusted when we clean up the esaggs index patterns & aggs args in a follow up PR.
@@ -131,7 +131,7 @@ export class SearchEmbeddable | |||
this.savedSearch = savedSearch; | |||
this.$rootScope = $rootScope; | |||
this.$compile = $compile; | |||
this.inspectorAdaptors = { | |||
this.inspectorAdapters = { |
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.
Changed this to fix a typo :) Adaptors -> Adapters
const title = i18n.translate('discover.embeddable.inspectorRequestDataTitle', { | ||
defaultMessage: 'Data', | ||
}); | ||
const description = i18n.translate('discover.embeddable.inspectorRequestDescription', { | ||
defaultMessage: 'This request queries Elasticsearch to fetch the data for the search.', | ||
}); | ||
|
||
const inspectorRequest = this.inspectorAdaptors.requests.start(title, { | ||
const inspectorRequest = this.inspectorAdapters.requests!.start(title, { |
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.
The only reason this worked without !
or a check for inspectorAdapters.requests
was because the Adapters
interface was [key: string]: any
Now that requests
and data
are added as optional properties, TS makes you check for their presence or assert that you know they are there.
data?: DataAdapter; | ||
requests?: RequestAdapter; |
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.
Rationale for this change:
- data and requests are the most commonly used adapters
- they ship in the
inspector
plugin so it stands to reason that we would provide typings for them - they are optional because technically they aren't guaranteed to be there as they need to be added by apps
- putting them here improves type safety, and also helps prevent name collisions
- in a perfect world, we could consider a refactor to make this generic so that you can provide type params for other Adapters to it. In the meantime, downstream apps can use casting.
@@ -44,7 +44,7 @@ interface DataViewComponentState { | |||
tabularData: TabularData | null; | |||
tabularOptions: TabularLoaderOptions; | |||
adapters: Adapters; | |||
tabularPromise: TabularCallback | null; | |||
tabularPromise: Promise<TabularHolder> | null; |
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.
The existing typings were actually incorrect, which was hidden by the fact that TabularData
was any
90aa172
to
1004b0b
Compare
Pinging @elastic/kibana-app-arch (Team:AppArch) |
* This function builds tabular data from the response and attaches it to the | ||
* inspector. It will only be called when the data view in the inspector is opened. | ||
* |
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 we can get rid of this function (maybe in a separate PR). We had this to support inspector in expressions in the early days but i think right now its no longer needed. Rather, we should:
- log the
Datatable
in every chart function (as esaggs is not the right place, futrther modifications to the datatable could happen further in expression) - update inspector view to work with new datatable format
// response data incorrectly in the inspector. | ||
let response = (searchSource as any).rawResponse; | ||
for (const agg of aggs.aggs) { | ||
if (typeof agg.type.postFlightRequest === 'function') { |
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.
not related to this PR, but so bad :| terms other bucket only works inside expressions, not with searchsource directly
let request; | ||
if (inspectorAdapters.requests) { | ||
inspectorAdapters.requests.reset(); | ||
request = inspectorAdapters.requests.start( |
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.
hmm .... feels this should rather exist on the searchsource?
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.
Maps changes lgtm!
- code review
Here's the plan @ppisljar and I discussed offline. First, we wrap up this PR and merge it as-is so we can move toward getting Then we take some follow-up steps:
|
1004b0b
to
a35018f
Compare
💚 Build SucceededMetrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
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.
KibanaApp owned code LGTM 👍 , didn't test, just a typo & TypeScript fix, thx for you explanations!
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
@ppisljar I created follow-up issues for the items we discussed here: |
…o-node-details * 'master' of github.com:elastic/kibana: Derive the port from the protocol in cases where it's not explicitly stated (elastic#83583) [CI] Build docker image during packer_cache (elastic#82145) [esaggs][inspector]: Refactor to prep for esaggs move to server. (elastic#83199)
Part of #65067
Summary
This PR restructures the
esaggs
expression function in preparation for moving it to the server. It also improves some of theAdapters
typings in the inspector plugin so that they provide added type safety in the esaggs request handler.Following this PR, we'll be able to make some of the needed changes to improve the semantics of esaggs args, and ultimately move the function to
common
so it can be registered on both client & server.Changes
Inspector:
TabularData
which has been a longstanding TODO itemdata
andrequests
adapters to theAdapters
interfaceAdapters
at any point, and the current typings forAdapters
are basically[key: string]: any
.data
andrequests
are both baked into theinspector
plugin, it felt like we should at least provide type safety for these. It also prevents any potential naming collisions if someone else wants to add an adapter with the same names.Adapters
to handle the new typings.Esaggs:
courierRequestHandler
out ofesaggs
and renamesrequestHandler
buildTabularInspectorData
toesaggs
since it's the only place it is usedesaggs
,requestHandler
,buildTabularInspectorData
to extract dependencies on external servicesesaggs
implementation.Reviewers
data
Testing
This PR should introduce no functional changes as it is simply a refactor. It touches the search infrastructure used by Visualizations, including Lens. It also touches the code that logs requests/responses to the inspector in these apps.