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
Remove Angular from courier request handler #20032
Changes from all commits
143d5d7
6efb1b7
7a28adf
169c33e
5601a4c
6188a4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,17 +18,15 @@ | |
*/ | ||
|
||
import _ from 'lodash'; | ||
import { SearchSourceProvider } from '../../courier/data_source/search_source'; | ||
import { VisRequestHandlersRegistryProvider } from '../../registry/vis_request_handlers'; | ||
import { calculateObjectHash } from '../lib/calculate_object_hash'; | ||
import { timefilter } from 'ui/timefilter'; | ||
import { getRequestInspectorStats, getResponseInspectorStats } from '../../courier/utils/courier_inspector_utils'; | ||
import { tabifyAggResponse } from '../../agg_response/tabify/tabify'; | ||
|
||
import { FormattedData } from '../../inspector/adapters'; | ||
import { getTime } from '../../timefilter/get_time'; | ||
|
||
const CourierRequestHandlerProvider = function (Private, courier) { | ||
const SearchSource = Private(SearchSourceProvider); | ||
const CourierRequestHandlerProvider = function () { | ||
|
||
/** | ||
* This function builds tabular data from the response and attaches it to the | ||
|
@@ -74,7 +72,7 @@ const CourierRequestHandlerProvider = function (Private, courier) { | |
|
||
return { | ||
name: 'courier', | ||
handler: function (vis, { searchSource, timeRange, query, filters, forceFetch }) { | ||
handler: function (vis, { searchSource, aggs, timeRange, query, filters, forceFetch }) { | ||
|
||
// Create a new search source that inherits the original search source | ||
// but has the propriate timeRange applied via a filter. | ||
|
@@ -83,8 +81,8 @@ const CourierRequestHandlerProvider = function (Private, courier) { | |
// Using callParentStartHandlers: true we make sure, that the parent searchSource | ||
// onSearchRequestStart will be called properly even though we use an inherited | ||
// search source. | ||
const timeFilterSearchSource = searchSource.makeChild(); | ||
const requestSearchSource = timeFilterSearchSource.makeChild(); | ||
const timeFilterSearchSource = searchSource.makeChild({ callParentStartHandlers: true }); | ||
const requestSearchSource = timeFilterSearchSource.makeChild({ callParentStartHandlers: true }); | ||
|
||
// For now we need to mirror the history of the passed search source, since | ||
// the spy panel wouldn't work otherwise. | ||
|
@@ -98,15 +96,15 @@ const CourierRequestHandlerProvider = function (Private, courier) { | |
}); | ||
|
||
requestSearchSource.aggs(function () { | ||
return vis.getAggConfig().toDsl(); | ||
return aggs.toDsl(); | ||
}); | ||
|
||
requestSearchSource.onRequestStart((searchSource, searchRequest) => { | ||
return vis.onSearchRequestStart(searchSource, searchRequest); | ||
return aggs.onSearchRequestStart(searchSource, searchRequest); | ||
}); | ||
|
||
timeFilterSearchSource.set('filter', () => { | ||
return timefilter.createFilter(searchSource.get('index'), timeRange); | ||
return getTime(searchSource.get('index'), timeRange); | ||
}); | ||
|
||
requestSearchSource.set('filter', filters); | ||
|
@@ -128,7 +126,7 @@ const CourierRequestHandlerProvider = function (Private, courier) { | |
}); | ||
request.stats(getRequestInspectorStats(requestSearchSource)); | ||
|
||
requestSearchSource.onResults().then(resp => { | ||
requestSearchSource.fetch().then(resp => { | ||
searchSource.lastQuery = queryHash; | ||
|
||
request | ||
|
@@ -138,10 +136,10 @@ const CourierRequestHandlerProvider = function (Private, courier) { | |
searchSource.rawResponse = resp; | ||
return _.cloneDeep(resp); | ||
}).then(async resp => { | ||
for (const agg of vis.getAggConfig()) { | ||
for (const agg of aggs) { | ||
if (_.has(agg, 'type.postFlightRequest')) { | ||
const nestedSearchSource = new SearchSource().inherits(requestSearchSource); | ||
resp = await agg.type.postFlightRequest(resp, vis.aggs, agg, nestedSearchSource); | ||
const nestedSearchSource = requestSearchSource.makeChild(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to note that down: this will change the behavior slightly, since we now call all parents start handler (i.e. the one of |
||
resp = await agg.type.postFlightRequest(resp, aggs, agg, nestedSearchSource); | ||
} | ||
} | ||
|
||
|
@@ -159,7 +157,6 @@ const CourierRequestHandlerProvider = function (Private, courier) { | |
request.json(req); | ||
}); | ||
|
||
courier.fetch(); | ||
} else { | ||
resolve(searchSource.finalResponse); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,6 @@ import { onBrushEvent } from '../utils/brush_event'; | |
import { FilterBarQueryFilterProvider } from '../filter_bar/query_filter'; | ||
import { FilterBarClickHandlerProvider } from '../filter_bar/filter_bar_click_handler'; | ||
import { updateVisualizationConfig } from './vis_update'; | ||
import { queryManagerFactory } from '../query_manager'; | ||
import { SearchSourceProvider } from '../courier/data_source/search_source'; | ||
import { SavedObjectsClientProvider } from '../saved_objects'; | ||
import { timefilter } from 'ui/timefilter'; | ||
|
@@ -56,7 +55,7 @@ const getTerms = (table, columnIndex, rowIndex) => { | |
}))]; | ||
}; | ||
|
||
export function VisProvider(Private, Promise, indexPatterns, getAppState) { | ||
export function VisProvider(Private, indexPatterns, getAppState) { | ||
const visTypes = Private(VisTypesRegistryProvider); | ||
const queryFilter = Private(FilterBarQueryFilterProvider); | ||
const filterBarClickHandler = Private(FilterBarClickHandlerProvider); | ||
|
@@ -88,7 +87,6 @@ export function VisProvider(Private, Promise, indexPatterns, getAppState) { | |
indexPatterns: indexPatterns, | ||
timeFilter: timefilter, | ||
queryFilter: queryFilter, | ||
queryManager: queryManagerFactory(getAppState), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops! Should this be re-added? |
||
events: { | ||
// the filter method will be removed in the near feature | ||
// you should rather use addFilter method below | ||
|
@@ -111,12 +109,6 @@ export function VisProvider(Private, Promise, indexPatterns, getAppState) { | |
onBrushEvent(event, getAppState()); | ||
} | ||
}, | ||
createInheritedSearchSource: (parentSearchSource) => { | ||
if (!parentSearchSource) { | ||
throw new Error('Unable to inherit search source, visualize saved object does not have search source.'); | ||
} | ||
return new SearchSource().inherits(parentSearchSource); | ||
}, | ||
inspectorAdapters: this._getActiveInspectorAdapters(), | ||
}; | ||
} | ||
|
@@ -247,19 +239,6 @@ export function VisProvider(Private, Promise, indexPatterns, getAppState) { | |
return this.getStateInternal(true); | ||
} | ||
|
||
/** | ||
* Hook for pre-flight logic, see AggType#onSearchRequestStart() | ||
* @param {Courier.SearchSource} searchSource | ||
* @param {Courier.SearchRequest} searchRequest | ||
* @return {Promise<undefined>} | ||
*/ | ||
onSearchRequestStart(searchSource, searchRequest) { | ||
return Promise.map( | ||
this.aggs.getRequestAggs(), | ||
agg => agg.onSearchRequestStart(searchSource, searchRequest) | ||
); | ||
} | ||
|
||
isHierarchical() { | ||
if (_.isFunction(this.type.hierarchicalData)) { | ||
return !!this.type.hierarchicalData(this); | ||
|
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 same here as below (yeah sorry for the mixed up order). We'll change the behavior here slightly, by calling the parent searchsource start handler when calling this. The handler will eventually call the
modifyAggConfigOnSearchRequestStart
of the individual aggregations. I am not sure if we want this to happen in this place already (and the one below). It seems to work fine, but I am wondering about some weird situations we might end up with, where we should not call that method "out of place". Maybe we could give themakeChild
method an options, parameter to pass to theinherit
method, so we can only enablecallParentStartHandlers
in the one place in courier request handler where it was also enabled beforehand?