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

remove vis dependency from request handlers #24119

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ const MetricsRequestHandlerProvider = function (Private, Notifier, config, $http

return {
name: 'metrics',
handler: function (vis, { uiState, timeRange, filters, query }) {
handler: function ({ aggs, uiState, timeRange, filters, query, visParams }) {
const timezone = Private(timezoneProvider)();
return new Promise((resolve) => {
const panel = vis.params;
const panel = visParams;
const uiStateObj = uiState.get(panel.type, {});
const parsedTimeRange = timefilter.calculateBounds(timeRange);
const scaledDataFormat = config.get('dateFormat:scaled');
const dateFormat = config.get('dateFormat');
if (panel && panel.id) {
const params = {
timerange: { timezone, ...parsedTimeRange },
filters: [buildEsQuery(vis.indexPattern, [query], filters)],
filters: [buildEsQuery(aggs.indexPattern, [query], filters)],
panels: [panel],
state: uiStateObj
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ const TimelionRequestHandlerProvider = function (Private, Notifier, $http) {

return {
name: 'timelion',
handler: function (vis, { timeRange, filters, query }) {
handler: function ({ aggs, timeRange, filters, query, visParams }) {

return new Promise((resolve, reject) => {
const expression = vis.params.expression;
const expression = visParams.expression;
if (!expression) return;

const httpResult = $http.post('../api/timelion/run', {
sheet: [expression],
extended: {
es: {
filter: buildEsQuery(vis.indexPattern, [query], filters)
filter: buildEsQuery(aggs.indexPattern, [query], filters)
}
},
time: _.extend(timeRange, {
interval: vis.params.interval,
interval: visParams.interval,
timezone: timezone
}),
})
Expand Down
6 changes: 3 additions & 3 deletions src/core_plugins/vega/public/vega_request_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export function VegaRequestHandlerProvider(Private, es, serviceSettings) {

name: 'vega',

handler(vis, { timeRange, filters, query }) {
handler({ aggs, timeRange, filters, query, visParams }) {
timeCache.setTimeRange(timeRange);
const filtersDsl = buildEsQuery(vis.indexPattern, [query], filters);
const vp = new VegaParser(vis.params.spec, searchCache, timeCache, filtersDsl, serviceSettings);
const filtersDsl = buildEsQuery(aggs.indexPattern, [query], filters);
const vp = new VegaParser(visParams.spec, searchCache, timeCache, filtersDsl, serviceSettings);
return vp.parseAsync();
}

Expand Down
15 changes: 8 additions & 7 deletions src/ui/public/vis/request_handlers/courier.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ const CourierRequestHandlerProvider = function () {

return {
name: 'courier',
handler: async function (vis, {
handler: async function ({
searchSource,
aggs,
timeRange,
query,
filters,
forceFetch,
partialRows,
isHierarchical,
inspectorAdapters,
queryFilter
}) {

// Create a new search source that inherits the original search source
Expand All @@ -65,7 +67,7 @@ const CourierRequestHandlerProvider = function () {
});

requestSearchSource.setField('aggs', function () {
return aggs.toDsl(vis.isHierarchical());
return aggs.toDsl(isHierarchical);
});

requestSearchSource.onRequestStart((searchSource, searchRequest) => {
Expand Down Expand Up @@ -130,24 +132,23 @@ const CourierRequestHandlerProvider = function () {
}

const parsedTimeRange = timeRange ? getTime(aggs.indexPattern, timeRange) : null;
const tabifyAggs = vis.getAggConfig();
const tabifyParams = {
metricsAtAllLevels: vis.isHierarchical(),
metricsAtAllLevels: isHierarchical,
partialRows,
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
const shouldCalculateNewTabify = shouldQuery || (searchSource.lastTabifyHash !== tabifyCacheHash);

if (shouldCalculateNewTabify) {
searchSource.lastTabifyHash = tabifyCacheHash;
searchSource.tabifiedResponse = tabifyAggResponse(tabifyAggs, searchSource.finalResponse, tabifyParams);
searchSource.tabifiedResponse = tabifyAggResponse(aggs, searchSource.finalResponse, tabifyParams);
}

inspectorAdapters.data.setTabularLoader(
() => buildTabularInspectorData(searchSource.tabifiedResponse, vis.API.queryFilter),
() => buildTabularInspectorData(searchSource.tabifiedResponse, queryFilter),
{ returnsFormattedValues: true }
);

Expand Down
4 changes: 3 additions & 1 deletion src/ui/public/vis/request_handlers/request_handlers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ export interface RequestHandlerParams {
uiState: PersistedState;
partialRows?: boolean;
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 {
name: string;
Expand Down
4 changes: 3 additions & 1 deletion src/ui/public/visualize/loader/visualize_data_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ export class VisualizeDataLoader {

try {
// 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,
isHierarchical: this.vis.isHierarchical(),
visParams: this.vis.params,
...params,
filters: params.filters
? params.filters.filter(filter => !filter.meta.disabled)
Expand Down