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

cleaning up esaggs #77646

Merged
merged 4 commits into from
Sep 19, 2020
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
87 changes: 32 additions & 55 deletions src/plugins/data/public/search/expressions/esaggs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import { get, hasIn } from 'lodash';
import { i18n } from '@kbn/i18n';
import { KibanaDatatable, KibanaDatatableColumn } from 'src/plugins/expressions/public';
import { calculateObjectHash } from '../../../../../plugins/kibana_utils/public';
import { PersistedState } from '../../../../../plugins/visualizations/public';
import { Adapters } from '../../../../../plugins/inspector/public';

Expand Down Expand Up @@ -60,7 +59,6 @@ export interface RequestHandlerParams {
indexPattern?: IIndexPattern;
query?: Query;
filters?: Filter[];
forceFetch: boolean;
filterManager: FilterManager;
uiState?: PersistedState;
partialRows?: boolean;
Expand All @@ -80,7 +78,6 @@ const handleCourierRequest = async ({
indexPattern,
query,
filters,
forceFetch,
partialRows,
metricsAtAllLevels,
inspectorAdapters,
Expand Down Expand Up @@ -137,46 +134,35 @@ const handleCourierRequest = async ({
requestSearchSource.setField('filter', filters);
requestSearchSource.setField('query', query);

const reqBody = await requestSearchSource.getSearchRequestBody();

const queryHash = calculateObjectHash(reqBody);
// We only need to reexecute the query, if forceFetch was true or the hash of the request body has changed
// since the last request
const shouldQuery = forceFetch || (searchSource as any).lastQuery !== queryHash;
Comment on lines -143 to -145
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be removing the forceFetch request handler param as well, since it doesn't do anything at this point?


if (shouldQuery) {
inspectorAdapters.requests.reset();
const request = inspectorAdapters.requests.start(
i18n.translate('data.functions.esaggs.inspector.dataRequest.title', {
defaultMessage: 'Data',
inspectorAdapters.requests.reset();
const request = inspectorAdapters.requests.start(
i18n.translate('data.functions.esaggs.inspector.dataRequest.title', {
defaultMessage: 'Data',
}),
{
description: i18n.translate('data.functions.esaggs.inspector.dataRequest.description', {
defaultMessage:
'This request queries Elasticsearch to fetch the data for the visualization.',
}),
{
description: i18n.translate('data.functions.esaggs.inspector.dataRequest.description', {
defaultMessage:
'This request queries Elasticsearch to fetch the data for the visualization.',
}),
}
);
request.stats(getRequestInspectorStats(requestSearchSource));

try {
const response = await requestSearchSource.fetch({ abortSignal });

(searchSource as any).lastQuery = queryHash;

request.stats(getResponseInspectorStats(response, searchSource)).ok({ json: response });

(searchSource as any).rawResponse = response;
} catch (e) {
// Log any error during request to the inspector
request.error({ json: e });
throw e;
} finally {
// Add the request body no matter if things went fine or not
requestSearchSource.getSearchRequestBody().then((req: unknown) => {
request.json(req);
});
}
);
request.stats(getRequestInspectorStats(requestSearchSource));

try {
const response = await requestSearchSource.fetch({ abortSignal });

request.stats(getResponseInspectorStats(response, searchSource)).ok({ json: response });

(searchSource as any).rawResponse = response;
} catch (e) {
// Log any error during request to the inspector
request.error({ json: e });
throw e;
} finally {
// Add the request body no matter if things went fine or not
requestSearchSource.getSearchRequestBody().then((req: unknown) => {
request.json(req);
});
}

// Note that rawResponse is not deeply cloned here, so downstream applications using courier
Expand Down Expand Up @@ -207,19 +193,11 @@ const handleCourierRequest = async ({
: undefined,
};

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 as any).lastTabifyHash !== tabifyCacheHash;

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

inspectorAdapters.data.setTabularLoader(
() =>
Expand Down Expand Up @@ -294,7 +272,6 @@ export const esaggs = (): EsaggsExpressionFunctionDefinition => ({
query: get(input, 'query', undefined) as any,
filters: get(input, 'filters', undefined),
timeFields: args.timeFields,
forceFetch: true,
metricsAtAllLevels: args.metricsAtAllLevels,
partialRows: args.partialRows,
inspectorAdapters: inspectorAdapters as Adapters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export function getTimelionRequestHandler({
filters: Filter[];
query: Query;
visParams: VisParams;
forceFetch?: boolean;
}): Promise<TimelionSuccessResponse> {
const expression = visParams.expression;

Expand Down
1 change: 0 additions & 1 deletion src/plugins/vis_type_timelion/public/timelion_vis_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const getTimelionVisualizationConfig = (
query: get(input, 'query') as Query,
filters: get(input, 'filters') as Filter[],
visParams,
forceFetch: true,
});

response.visType = TIMELION_VIS_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export const visualization = (): ExpressionFunctionVisualization => ({
uiState,
inspectorAdapters,
queryFilter: getFilterManager(),
forceFetch: true,
aggs,
});
}
Expand Down