remove vis dependency from request handlers (#24119) (#25287)

This commit is contained in:
Peter Pisljar 2018-11-07 18:09:04 +01:00 committed by GitHub
parent 113891cca1
commit bfd422294e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 19 deletions

View file

@ -28,10 +28,10 @@ const MetricsRequestHandlerProvider = function (Private, Notifier, config, $http
return { return {
name: 'metrics', name: 'metrics',
handler: function (vis, { uiState, timeRange, filters, query }) { handler: function ({ aggs, uiState, timeRange, filters, query, visParams }) {
const timezone = Private(timezoneProvider)(); const timezone = Private(timezoneProvider)();
return new Promise((resolve) => { return new Promise((resolve) => {
const panel = vis.params; const panel = visParams;
const uiStateObj = uiState.get(panel.type, {}); const uiStateObj = uiState.get(panel.type, {});
const parsedTimeRange = timefilter.calculateBounds(timeRange); const parsedTimeRange = timefilter.calculateBounds(timeRange);
const scaledDataFormat = config.get('dateFormat:scaled'); const scaledDataFormat = config.get('dateFormat:scaled');
@ -39,7 +39,7 @@ const MetricsRequestHandlerProvider = function (Private, Notifier, config, $http
if (panel && panel.id) { if (panel && panel.id) {
const params = { const params = {
timerange: { timezone, ...parsedTimeRange }, timerange: { timezone, ...parsedTimeRange },
filters: [buildEsQuery(vis.indexPattern, [query], filters)], filters: [buildEsQuery(aggs.indexPattern, [query], filters)],
panels: [panel], panels: [panel],
state: uiStateObj state: uiStateObj
}; };

View file

@ -31,21 +31,21 @@ const TimelionRequestHandlerProvider = function (Private, Notifier, $http) {
return { return {
name: 'timelion', name: 'timelion',
handler: function (vis, { timeRange, filters, query }) { handler: function ({ aggs, timeRange, filters, query, visParams }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const expression = vis.params.expression; const expression = visParams.expression;
if (!expression) return; if (!expression) return;
const httpResult = $http.post('../api/timelion/run', { const httpResult = $http.post('../api/timelion/run', {
sheet: [expression], sheet: [expression],
extended: { extended: {
es: { es: {
filter: buildEsQuery(vis.indexPattern, [query], filters) filter: buildEsQuery(aggs.indexPattern, [query], filters)
} }
}, },
time: _.extend(timeRange, { time: _.extend(timeRange, {
interval: vis.params.interval, interval: visParams.interval,
timezone: timezone timezone: timezone
}), }),
}) })

View file

@ -33,10 +33,10 @@ export function VegaRequestHandlerProvider(Private, es, serviceSettings) {
name: 'vega', name: 'vega',
handler(vis, { timeRange, filters, query }) { handler({ aggs, timeRange, filters, query, visParams }) {
timeCache.setTimeRange(timeRange); timeCache.setTimeRange(timeRange);
const filtersDsl = buildEsQuery(vis.indexPattern, [query], filters); const filtersDsl = buildEsQuery(aggs.indexPattern, [query], filters);
const vp = new VegaParser(vis.params.spec, searchCache, timeCache, filtersDsl, serviceSettings); const vp = new VegaParser(visParams.spec, searchCache, timeCache, filtersDsl, serviceSettings);
return vp.parseAsync(); return vp.parseAsync();
} }

View file

@ -30,7 +30,7 @@ const CourierRequestHandlerProvider = function () {
return { return {
name: 'courier', name: 'courier',
handler: async function (vis, { handler: async function ({
searchSource, searchSource,
aggs, aggs,
timeRange, timeRange,
@ -38,7 +38,9 @@ const CourierRequestHandlerProvider = function () {
filters, filters,
forceFetch, forceFetch,
partialRows, partialRows,
isHierarchical,
inspectorAdapters, inspectorAdapters,
queryFilter
}) { }) {
// Create a new search source that inherits the original search source // Create a new search source that inherits the original search source
@ -65,7 +67,7 @@ const CourierRequestHandlerProvider = function () {
}); });
requestSearchSource.setField('aggs', function () { requestSearchSource.setField('aggs', function () {
return aggs.toDsl(vis.isHierarchical()); return aggs.toDsl(isHierarchical);
}); });
requestSearchSource.onRequestStart((searchSource, searchRequest) => { requestSearchSource.onRequestStart((searchSource, searchRequest) => {
@ -130,24 +132,23 @@ const CourierRequestHandlerProvider = function () {
} }
const parsedTimeRange = timeRange ? getTime(aggs.indexPattern, timeRange) : null; const parsedTimeRange = timeRange ? getTime(aggs.indexPattern, timeRange) : null;
const tabifyAggs = vis.getAggConfig();
const tabifyParams = { const tabifyParams = {
metricsAtAllLevels: vis.isHierarchical(), metricsAtAllLevels: isHierarchical,
partialRows, partialRows,
timeRange: parsedTimeRange ? parsedTimeRange.range : undefined, timeRange: parsedTimeRange ? parsedTimeRange.range : undefined,
}; };
const tabifyCacheHash = calculateObjectHash({ tabifyAggs, ...tabifyParams }); const tabifyCacheHash = calculateObjectHash({ tabifyAggs: aggs, ...tabifyParams });
// We only need to reexecute tabify, if either we did a new request or some input params to tabify changed // We only need to reexecute tabify, if either we did a new request or some input params to tabify changed
const shouldCalculateNewTabify = shouldQuery || (searchSource.lastTabifyHash !== tabifyCacheHash); const shouldCalculateNewTabify = shouldQuery || (searchSource.lastTabifyHash !== tabifyCacheHash);
if (shouldCalculateNewTabify) { if (shouldCalculateNewTabify) {
searchSource.lastTabifyHash = tabifyCacheHash; searchSource.lastTabifyHash = tabifyCacheHash;
searchSource.tabifiedResponse = tabifyAggResponse(tabifyAggs, searchSource.finalResponse, tabifyParams); searchSource.tabifiedResponse = tabifyAggResponse(aggs, searchSource.finalResponse, tabifyParams);
} }
inspectorAdapters.data.setTabularLoader( inspectorAdapters.data.setTabularLoader(
() => buildTabularInspectorData(searchSource.tabifiedResponse, vis.API.queryFilter), () => buildTabularInspectorData(searchSource.tabifiedResponse, queryFilter),
{ returnsFormattedValues: true } { returnsFormattedValues: true }
); );

View file

@ -36,9 +36,11 @@ export interface RequestHandlerParams {
uiState: PersistedState; uiState: PersistedState;
partialRows?: boolean; partialRows?: boolean;
inspectorAdapters?: Adapters; inspectorAdapters?: Adapters;
isHierarchical?: boolean;
visParams?: any;
} }
export type RequestHandler = <T>(vis: Vis, params: RequestHandlerParams) => T; export type RequestHandler = <T>(params: RequestHandlerParams) => T;
export interface RequestHandlerDescription { export interface RequestHandlerDescription {
name: string; name: string;

View file

@ -74,8 +74,10 @@ export class VisualizeDataLoader {
try { try {
// searchSource is only there for courier request handler // searchSource is only there for courier request handler
const requestHandlerResponse = await this.requestHandler(this.vis, { const requestHandlerResponse = await this.requestHandler({
partialRows: this.vis.params.partialRows || this.vis.type.requiresPartialRows, partialRows: this.vis.params.partialRows || this.vis.type.requiresPartialRows,
isHierarchical: this.vis.isHierarchical(),
visParams: this.vis.params,
...params, ...params,
filters: params.filters filters: params.filters
? params.filters.filter(filter => !filter.meta.disabled) ? params.filters.filter(filter => !filter.meta.disabled)