[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,
|
true,
|
||||||
],
|
],
|
||||||
"id": Array [
|
"id": Array [
|
||||||
"col1",
|
"0",
|
||||||
],
|
],
|
||||||
"schema": Array [
|
"schema": Array [
|
||||||
"metric",
|
"metric",
|
||||||
|
@ -388,7 +388,7 @@ describe('IndexPattern Data Source', () => {
|
||||||
"timestamp",
|
"timestamp",
|
||||||
],
|
],
|
||||||
"id": Array [
|
"id": Array [
|
||||||
"col2",
|
"1",
|
||||||
],
|
],
|
||||||
"interval": Array [
|
"interval": Array [
|
||||||
"1d",
|
"1d",
|
||||||
|
@ -442,7 +442,7 @@ describe('IndexPattern Data Source', () => {
|
||||||
Object {
|
Object {
|
||||||
"arguments": Object {
|
"arguments": Object {
|
||||||
"idMap": Array [
|
"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",
|
"function": "lens_rename_columns",
|
||||||
|
@ -563,7 +563,7 @@ describe('IndexPattern Data Source', () => {
|
||||||
"{\\"language\\":\\"kuery\\",\\"query\\":\\"bytes > 5\\"}",
|
"{\\"language\\":\\"kuery\\",\\"query\\":\\"bytes > 5\\"}",
|
||||||
],
|
],
|
||||||
"id": Array [
|
"id": Array [
|
||||||
"col1-filter",
|
"0-filter",
|
||||||
],
|
],
|
||||||
"schema": Array [
|
"schema": Array [
|
||||||
"bucket",
|
"bucket",
|
||||||
|
@ -585,7 +585,7 @@ describe('IndexPattern Data Source', () => {
|
||||||
true,
|
true,
|
||||||
],
|
],
|
||||||
"id": Array [
|
"id": Array [
|
||||||
"col1-metric",
|
"0-metric",
|
||||||
],
|
],
|
||||||
"schema": Array [
|
"schema": Array [
|
||||||
"metric",
|
"metric",
|
||||||
|
@ -602,7 +602,7 @@ describe('IndexPattern Data Source', () => {
|
||||||
true,
|
true,
|
||||||
],
|
],
|
||||||
"id": Array [
|
"id": Array [
|
||||||
"col1",
|
"0",
|
||||||
],
|
],
|
||||||
"schema": Array [
|
"schema": Array [
|
||||||
"metric",
|
"metric",
|
||||||
|
@ -795,9 +795,9 @@ describe('IndexPattern Data Source', () => {
|
||||||
const ast = indexPatternDatasource.toExpression(state, 'first') as Ast;
|
const ast = indexPatternDatasource.toExpression(state, 'first') as Ast;
|
||||||
expect(ast.chain[0].arguments.metricsAtAllLevels).toEqual([false]);
|
expect(ast.chain[0].arguments.metricsAtAllLevels).toEqual([false]);
|
||||||
expect(JSON.parse(ast.chain[1].arguments.idMap[0] as string)).toEqual({
|
expect(JSON.parse(ast.chain[1].arguments.idMap[0] as string)).toEqual({
|
||||||
'col-0-bucket1': expect.any(Object),
|
'col-0-0': expect.objectContaining({ id: 'bucket1' }),
|
||||||
'col-1-bucket2': expect.any(Object),
|
'col-1-1': expect.objectContaining({ id: 'bucket2' }),
|
||||||
'col-2-metric': expect.any(Object),
|
'col-2-2': expect.objectContaining({ id: 'metric' }),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -919,7 +919,7 @@ describe('IndexPattern Data Source', () => {
|
||||||
|
|
||||||
const ast = indexPatternDatasource.toExpression(state, 'first') as Ast;
|
const ast = indexPatternDatasource.toExpression(state, 'first') as Ast;
|
||||||
expect(JSON.parse(ast.chain[1].arguments.idMap[0] as string)).toEqual({
|
expect(JSON.parse(ast.chain[1].arguments.idMap[0] as string)).toEqual({
|
||||||
'col-0-col1': expect.objectContaining({
|
'col-0-0': expect.objectContaining({
|
||||||
id: 'col1',
|
id: 'col1',
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
|
@ -205,7 +205,8 @@ describe('date_histogram', () => {
|
||||||
'col1',
|
'col1',
|
||||||
indexPattern1,
|
indexPattern1,
|
||||||
layer,
|
layer,
|
||||||
uiSettingsMock
|
uiSettingsMock,
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
expect(esAggsFn).toEqual(
|
expect(esAggsFn).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
|
@ -258,7 +259,8 @@ describe('date_histogram', () => {
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
layer,
|
layer,
|
||||||
uiSettingsMock
|
uiSettingsMock,
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
expect(esAggsFn).toEqual(
|
expect(esAggsFn).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
|
|
|
@ -355,7 +355,8 @@ interface FieldBasedOperationDefinition<C extends BaseIndexPatternColumn> {
|
||||||
columnId: string,
|
columnId: string,
|
||||||
indexPattern: IndexPattern,
|
indexPattern: IndexPattern,
|
||||||
layer: IndexPatternLayer,
|
layer: IndexPatternLayer,
|
||||||
uiSettings: IUiSettingsClient
|
uiSettings: IUiSettingsClient,
|
||||||
|
orderedColumnIds: string[]
|
||||||
) => ExpressionAstFunction;
|
) => ExpressionAstFunction;
|
||||||
/**
|
/**
|
||||||
* Validate that the operation has the right preconditions in the state. For example:
|
* Validate that the operation has the right preconditions in the state. For example:
|
||||||
|
|
|
@ -75,7 +75,8 @@ describe('last_value', () => {
|
||||||
'col1',
|
'col1',
|
||||||
{} as IndexPattern,
|
{} as IndexPattern,
|
||||||
layer,
|
layer,
|
||||||
uiSettingsMock
|
uiSettingsMock,
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
expect(esAggsFn).toEqual(
|
expect(esAggsFn).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
|
|
|
@ -123,7 +123,8 @@ describe('percentile', () => {
|
||||||
'col1',
|
'col1',
|
||||||
{} as IndexPattern,
|
{} as IndexPattern,
|
||||||
layer,
|
layer,
|
||||||
uiSettingsMock
|
uiSettingsMock,
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
expect(esAggsFn).toEqual(
|
expect(esAggsFn).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
|
|
|
@ -172,7 +172,8 @@ describe('ranges', () => {
|
||||||
'col1',
|
'col1',
|
||||||
{} as IndexPattern,
|
{} as IndexPattern,
|
||||||
layer,
|
layer,
|
||||||
uiSettingsMock
|
uiSettingsMock,
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
expect(esAggsFn).toMatchInlineSnapshot(`
|
expect(esAggsFn).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
|
@ -219,7 +220,8 @@ describe('ranges', () => {
|
||||||
'col1',
|
'col1',
|
||||||
{} as IndexPattern,
|
{} as IndexPattern,
|
||||||
layer,
|
layer,
|
||||||
uiSettingsMock
|
uiSettingsMock,
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(esAggsFn).toEqual(
|
expect(esAggsFn).toEqual(
|
||||||
|
@ -240,7 +242,8 @@ describe('ranges', () => {
|
||||||
'col1',
|
'col1',
|
||||||
{} as IndexPattern,
|
{} as IndexPattern,
|
||||||
layer,
|
layer,
|
||||||
uiSettingsMock
|
uiSettingsMock,
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(esAggsFn).toEqual(
|
expect(esAggsFn).toEqual(
|
||||||
|
@ -261,7 +264,8 @@ describe('ranges', () => {
|
||||||
'col1',
|
'col1',
|
||||||
{} as IndexPattern,
|
{} as IndexPattern,
|
||||||
layer,
|
layer,
|
||||||
uiSettingsMock
|
uiSettingsMock,
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
expect((esAggsFn as { arguments: unknown }).arguments).toEqual(
|
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', {
|
return buildExpressionFunction<AggFunctionsMapping['aggTerms']>('aggTerms', {
|
||||||
id: columnId,
|
id: columnId,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
schema: 'segment',
|
schema: 'segment',
|
||||||
field: column.sourceField,
|
field: column.sourceField,
|
||||||
orderBy:
|
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,
|
order: column.params.orderDirection,
|
||||||
size: column.params.size,
|
size: column.params.size,
|
||||||
otherBucket: Boolean(column.params.otherBucket),
|
otherBucket: Boolean(column.params.otherBucket),
|
||||||
|
|
|
@ -71,7 +71,8 @@ describe('terms', () => {
|
||||||
'col1',
|
'col1',
|
||||||
{} as IndexPattern,
|
{} as IndexPattern,
|
||||||
layer,
|
layer,
|
||||||
uiSettingsMock
|
uiSettingsMock,
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
expect(esAggsFn).toEqual(
|
expect(esAggsFn).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
|
@ -95,7 +96,8 @@ describe('terms', () => {
|
||||||
'col1',
|
'col1',
|
||||||
{} as IndexPattern,
|
{} as IndexPattern,
|
||||||
layer,
|
layer,
|
||||||
uiSettingsMock
|
uiSettingsMock,
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
expect(esAggsFn).toEqual(
|
expect(esAggsFn).toEqual(
|
||||||
expect.objectContaining({
|
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];
|
const def = operationDefinitionMap[col.operationType];
|
||||||
if (def.input !== 'fullReference' && def.input !== 'managedReference') {
|
if (def.input !== 'fullReference' && def.input !== 'managedReference') {
|
||||||
const wrapInFilter = Boolean(def.filterable && col.filter);
|
const wrapInFilter = Boolean(def.filterable && col.filter);
|
||||||
let aggAst = def.toEsAggsFn(
|
let aggAst = def.toEsAggsFn(
|
||||||
col,
|
col,
|
||||||
wrapInFilter ? `${colId}-metric` : colId,
|
wrapInFilter ? `${index}-metric` : String(index),
|
||||||
indexPattern,
|
indexPattern,
|
||||||
layer,
|
layer,
|
||||||
uiSettings
|
uiSettings,
|
||||||
|
orderedColumnIds
|
||||||
);
|
);
|
||||||
if (wrapInFilter) {
|
if (wrapInFilter) {
|
||||||
aggAst = buildExpressionFunction<AggFunctionsMapping['aggFilteredMetric']>(
|
aggAst = buildExpressionFunction<AggFunctionsMapping['aggFilteredMetric']>(
|
||||||
'aggFilteredMetric',
|
'aggFilteredMetric',
|
||||||
{
|
{
|
||||||
id: colId,
|
id: String(index),
|
||||||
enabled: true,
|
enabled: true,
|
||||||
schema: 'metric',
|
schema: 'metric',
|
||||||
customBucket: buildExpression([
|
customBucket: buildExpression([
|
||||||
buildExpressionFunction<AggFunctionsMapping['aggFilter']>('aggFilter', {
|
buildExpressionFunction<AggFunctionsMapping['aggFilter']>('aggFilter', {
|
||||||
id: `${colId}-filter`,
|
id: `${index}-filter`,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
schema: 'bucket',
|
schema: 'bucket',
|
||||||
filter: JSON.stringify(col.filter),
|
filter: JSON.stringify(col.filter),
|
||||||
|
@ -121,7 +123,7 @@ function getExpressionForLayer(
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const idMap = esAggEntries.reduce((currentIdMap, [colId, column], index) => {
|
const idMap = esAggEntries.reduce((currentIdMap, [colId, column], index) => {
|
||||||
const esAggsId = `col-${index}-${colId}`;
|
const esAggsId = `col-${index}-${index}`;
|
||||||
return {
|
return {
|
||||||
...currentIdMap,
|
...currentIdMap,
|
||||||
[esAggsId]: {
|
[esAggsId]: {
|
||||||
|
|
Loading…
Reference in a new issue