[Lens] Improve caching with more stable Elasticsearch requests (#100414)
This commit is contained in:
parent
7cfa0d2b06
commit
f6266c431b
|
@ -359,7 +359,7 @@ describe('IndexPattern Data Source', () => {
|
|||
true,
|
||||
],
|
||||
"id": Array [
|
||||
"col1",
|
||||
"0",
|
||||
],
|
||||
"schema": Array [
|
||||
"metric",
|
||||
|
@ -388,7 +388,7 @@ describe('IndexPattern Data Source', () => {
|
|||
"timestamp",
|
||||
],
|
||||
"id": Array [
|
||||
"col2",
|
||||
"1",
|
||||
],
|
||||
"interval": Array [
|
||||
"1d",
|
||||
|
@ -442,7 +442,7 @@ describe('IndexPattern Data Source', () => {
|
|||
Object {
|
||||
"arguments": Object {
|
||||
"idMap": Array [
|
||||
"{\\"col-0-col1\\":{\\"label\\":\\"Count of records\\",\\"dataType\\":\\"number\\",\\"isBucketed\\":false,\\"sourceField\\":\\"Records\\",\\"operationType\\":\\"count\\",\\"id\\":\\"col1\\"},\\"col-1-col2\\":{\\"label\\":\\"Date\\",\\"dataType\\":\\"date\\",\\"isBucketed\\":true,\\"operationType\\":\\"date_histogram\\",\\"sourceField\\":\\"timestamp\\",\\"params\\":{\\"interval\\":\\"1d\\"},\\"id\\":\\"col2\\"}}",
|
||||
"{\\"col-0-0\\":{\\"label\\":\\"Count of records\\",\\"dataType\\":\\"number\\",\\"isBucketed\\":false,\\"sourceField\\":\\"Records\\",\\"operationType\\":\\"count\\",\\"id\\":\\"col1\\"},\\"col-1-1\\":{\\"label\\":\\"Date\\",\\"dataType\\":\\"date\\",\\"isBucketed\\":true,\\"operationType\\":\\"date_histogram\\",\\"sourceField\\":\\"timestamp\\",\\"params\\":{\\"interval\\":\\"1d\\"},\\"id\\":\\"col2\\"}}",
|
||||
],
|
||||
},
|
||||
"function": "lens_rename_columns",
|
||||
|
@ -563,7 +563,7 @@ describe('IndexPattern Data Source', () => {
|
|||
"{\\"language\\":\\"kuery\\",\\"query\\":\\"bytes > 5\\"}",
|
||||
],
|
||||
"id": Array [
|
||||
"col1-filter",
|
||||
"0-filter",
|
||||
],
|
||||
"schema": Array [
|
||||
"bucket",
|
||||
|
@ -585,7 +585,7 @@ describe('IndexPattern Data Source', () => {
|
|||
true,
|
||||
],
|
||||
"id": Array [
|
||||
"col1-metric",
|
||||
"0-metric",
|
||||
],
|
||||
"schema": Array [
|
||||
"metric",
|
||||
|
@ -602,7 +602,7 @@ describe('IndexPattern Data Source', () => {
|
|||
true,
|
||||
],
|
||||
"id": Array [
|
||||
"col1",
|
||||
"0",
|
||||
],
|
||||
"schema": Array [
|
||||
"metric",
|
||||
|
@ -795,9 +795,9 @@ describe('IndexPattern Data Source', () => {
|
|||
const ast = indexPatternDatasource.toExpression(state, 'first') as Ast;
|
||||
expect(ast.chain[0].arguments.metricsAtAllLevels).toEqual([false]);
|
||||
expect(JSON.parse(ast.chain[1].arguments.idMap[0] as string)).toEqual({
|
||||
'col-0-bucket1': expect.any(Object),
|
||||
'col-1-bucket2': expect.any(Object),
|
||||
'col-2-metric': expect.any(Object),
|
||||
'col-0-0': expect.objectContaining({ id: 'bucket1' }),
|
||||
'col-1-1': expect.objectContaining({ id: 'bucket2' }),
|
||||
'col-2-2': expect.objectContaining({ id: 'metric' }),
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -919,7 +919,7 @@ describe('IndexPattern Data Source', () => {
|
|||
|
||||
const ast = indexPatternDatasource.toExpression(state, 'first') as Ast;
|
||||
expect(JSON.parse(ast.chain[1].arguments.idMap[0] as string)).toEqual({
|
||||
'col-0-col1': expect.objectContaining({
|
||||
'col-0-0': expect.objectContaining({
|
||||
id: 'col1',
|
||||
}),
|
||||
});
|
||||
|
|
|
@ -205,7 +205,8 @@ describe('date_histogram', () => {
|
|||
'col1',
|
||||
indexPattern1,
|
||||
layer,
|
||||
uiSettingsMock
|
||||
uiSettingsMock,
|
||||
[]
|
||||
);
|
||||
expect(esAggsFn).toEqual(
|
||||
expect.objectContaining({
|
||||
|
@ -258,7 +259,8 @@ describe('date_histogram', () => {
|
|||
]),
|
||||
},
|
||||
layer,
|
||||
uiSettingsMock
|
||||
uiSettingsMock,
|
||||
[]
|
||||
);
|
||||
expect(esAggsFn).toEqual(
|
||||
expect.objectContaining({
|
||||
|
|
|
@ -355,7 +355,8 @@ interface FieldBasedOperationDefinition<C extends BaseIndexPatternColumn> {
|
|||
columnId: string,
|
||||
indexPattern: IndexPattern,
|
||||
layer: IndexPatternLayer,
|
||||
uiSettings: IUiSettingsClient
|
||||
uiSettings: IUiSettingsClient,
|
||||
orderedColumnIds: string[]
|
||||
) => ExpressionAstFunction;
|
||||
/**
|
||||
* Validate that the operation has the right preconditions in the state. For example:
|
||||
|
|
|
@ -75,7 +75,8 @@ describe('last_value', () => {
|
|||
'col1',
|
||||
{} as IndexPattern,
|
||||
layer,
|
||||
uiSettingsMock
|
||||
uiSettingsMock,
|
||||
[]
|
||||
);
|
||||
expect(esAggsFn).toEqual(
|
||||
expect.objectContaining({
|
||||
|
|
|
@ -123,7 +123,8 @@ describe('percentile', () => {
|
|||
'col1',
|
||||
{} as IndexPattern,
|
||||
layer,
|
||||
uiSettingsMock
|
||||
uiSettingsMock,
|
||||
[]
|
||||
);
|
||||
expect(esAggsFn).toEqual(
|
||||
expect.objectContaining({
|
||||
|
|
|
@ -172,7 +172,8 @@ describe('ranges', () => {
|
|||
'col1',
|
||||
{} as IndexPattern,
|
||||
layer,
|
||||
uiSettingsMock
|
||||
uiSettingsMock,
|
||||
[]
|
||||
);
|
||||
expect(esAggsFn).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
|
@ -219,7 +220,8 @@ describe('ranges', () => {
|
|||
'col1',
|
||||
{} as IndexPattern,
|
||||
layer,
|
||||
uiSettingsMock
|
||||
uiSettingsMock,
|
||||
[]
|
||||
);
|
||||
|
||||
expect(esAggsFn).toEqual(
|
||||
|
@ -240,7 +242,8 @@ describe('ranges', () => {
|
|||
'col1',
|
||||
{} as IndexPattern,
|
||||
layer,
|
||||
uiSettingsMock
|
||||
uiSettingsMock,
|
||||
[]
|
||||
);
|
||||
|
||||
expect(esAggsFn).toEqual(
|
||||
|
@ -261,7 +264,8 @@ describe('ranges', () => {
|
|||
'col1',
|
||||
{} as IndexPattern,
|
||||
layer,
|
||||
uiSettingsMock
|
||||
uiSettingsMock,
|
||||
[]
|
||||
);
|
||||
|
||||
expect((esAggsFn as { arguments: unknown }).arguments).toEqual(
|
||||
|
|
|
@ -132,14 +132,16 @@ export const termsOperation: OperationDefinition<TermsIndexPatternColumn, 'field
|
|||
},
|
||||
};
|
||||
},
|
||||
toEsAggsFn: (column, columnId, _indexPattern, layer) => {
|
||||
toEsAggsFn: (column, columnId, _indexPattern, layer, uiSettings, orderedColumnIds) => {
|
||||
return buildExpressionFunction<AggFunctionsMapping['aggTerms']>('aggTerms', {
|
||||
id: columnId,
|
||||
enabled: true,
|
||||
schema: 'segment',
|
||||
field: column.sourceField,
|
||||
orderBy:
|
||||
column.params.orderBy.type === 'alphabetical' ? '_key' : column.params.orderBy.columnId,
|
||||
column.params.orderBy.type === 'alphabetical'
|
||||
? '_key'
|
||||
: String(orderedColumnIds.indexOf(column.params.orderBy.columnId)),
|
||||
order: column.params.orderDirection,
|
||||
size: column.params.size,
|
||||
otherBucket: Boolean(column.params.otherBucket),
|
||||
|
|
|
@ -71,7 +71,8 @@ describe('terms', () => {
|
|||
'col1',
|
||||
{} as IndexPattern,
|
||||
layer,
|
||||
uiSettingsMock
|
||||
uiSettingsMock,
|
||||
[]
|
||||
);
|
||||
expect(esAggsFn).toEqual(
|
||||
expect.objectContaining({
|
||||
|
@ -95,7 +96,8 @@ describe('terms', () => {
|
|||
'col1',
|
||||
{} as IndexPattern,
|
||||
layer,
|
||||
uiSettingsMock
|
||||
uiSettingsMock,
|
||||
[]
|
||||
);
|
||||
expect(esAggsFn).toEqual(
|
||||
expect.objectContaining({
|
||||
|
|
|
@ -77,27 +77,29 @@ function getExpressionForLayer(
|
|||
}
|
||||
});
|
||||
|
||||
esAggEntries.forEach(([colId, col]) => {
|
||||
const orderedColumnIds = esAggEntries.map(([colId]) => colId);
|
||||
esAggEntries.forEach(([colId, col], index) => {
|
||||
const def = operationDefinitionMap[col.operationType];
|
||||
if (def.input !== 'fullReference' && def.input !== 'managedReference') {
|
||||
const wrapInFilter = Boolean(def.filterable && col.filter);
|
||||
let aggAst = def.toEsAggsFn(
|
||||
col,
|
||||
wrapInFilter ? `${colId}-metric` : colId,
|
||||
wrapInFilter ? `${index}-metric` : String(index),
|
||||
indexPattern,
|
||||
layer,
|
||||
uiSettings
|
||||
uiSettings,
|
||||
orderedColumnIds
|
||||
);
|
||||
if (wrapInFilter) {
|
||||
aggAst = buildExpressionFunction<AggFunctionsMapping['aggFilteredMetric']>(
|
||||
'aggFilteredMetric',
|
||||
{
|
||||
id: colId,
|
||||
id: String(index),
|
||||
enabled: true,
|
||||
schema: 'metric',
|
||||
customBucket: buildExpression([
|
||||
buildExpressionFunction<AggFunctionsMapping['aggFilter']>('aggFilter', {
|
||||
id: `${colId}-filter`,
|
||||
id: `${index}-filter`,
|
||||
enabled: true,
|
||||
schema: 'bucket',
|
||||
filter: JSON.stringify(col.filter),
|
||||
|
@ -121,7 +123,7 @@ function getExpressionForLayer(
|
|||
return null;
|
||||
}
|
||||
const idMap = esAggEntries.reduce((currentIdMap, [colId, column], index) => {
|
||||
const esAggsId = `col-${index}-${colId}`;
|
||||
const esAggsId = `col-${index}-${index}`;
|
||||
return {
|
||||
...currentIdMap,
|
||||
[esAggsId]: {
|
||||
|
|
Loading…
Reference in a new issue