[maps] fix Data Mapper resets after switch to clusters for scaling (#161796)

Closes https://github.com/elastic/kibana/issues/158551

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Nathan Reese 2023-07-14 09:11:56 -06:00 committed by GitHub
parent 41056193d9
commit 235eac899b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 158 additions and 26 deletions

View file

@ -9,11 +9,9 @@ import { AggField } from './agg_field';
import { AGG_TYPE, FIELD_ORIGIN } from '../../../../common/constants';
import { IESAggSource } from '../../sources/es_agg_source';
const mockEsAggSource = {} as unknown as IESAggSource;
const defaultParams = {
label: 'my agg field',
source: mockEsAggSource,
source: {} as unknown as IESAggSource,
origin: FIELD_ORIGIN.SOURCE,
};
@ -41,24 +39,98 @@ describe('supportsFieldMetaFromEs', () => {
});
describe('supportsFieldMetaFromLocalData', () => {
test('number metrics should support field meta from local', () => {
const avgMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.AVG });
expect(avgMetric.supportsFieldMetaFromLocalData()).toBe(true);
const maxMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.MAX });
expect(maxMetric.supportsFieldMetaFromLocalData()).toBe(true);
const minMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.MIN });
expect(minMetric.supportsFieldMetaFromLocalData()).toBe(true);
const sumMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.SUM });
expect(sumMetric.supportsFieldMetaFromLocalData()).toBe(true);
const uniqueCountMetric = new AggField({
...defaultParams,
aggType: AGG_TYPE.UNIQUE_COUNT,
describe('source is vector tiles', () => {
const mvtSource = {
isMvt: () => {
return true;
},
} as unknown as IESAggSource;
test('number metrics should support field meta from local', () => {
const avgMetric = new AggField({
...defaultParams,
source: mvtSource,
aggType: AGG_TYPE.AVG,
});
expect(avgMetric.supportsFieldMetaFromLocalData()).toBe(true);
const maxMetric = new AggField({
...defaultParams,
source: mvtSource,
aggType: AGG_TYPE.MAX,
});
expect(maxMetric.supportsFieldMetaFromLocalData()).toBe(true);
const minMetric = new AggField({
...defaultParams,
source: mvtSource,
aggType: AGG_TYPE.MIN,
});
expect(minMetric.supportsFieldMetaFromLocalData()).toBe(true);
const sumMetric = new AggField({
...defaultParams,
source: mvtSource,
aggType: AGG_TYPE.SUM,
});
expect(sumMetric.supportsFieldMetaFromLocalData()).toBe(true);
const uniqueCountMetric = new AggField({
...defaultParams,
source: mvtSource,
aggType: AGG_TYPE.UNIQUE_COUNT,
});
expect(uniqueCountMetric.supportsFieldMetaFromLocalData()).toBe(true);
});
test('Non number metrics should not support field meta from local', () => {
const termMetric = new AggField({
...defaultParams,
source: mvtSource,
aggType: AGG_TYPE.TERMS,
});
expect(termMetric.supportsFieldMetaFromLocalData()).toBe(false);
});
expect(uniqueCountMetric.supportsFieldMetaFromLocalData()).toBe(true);
});
test('Non number metrics should not support field meta from local', () => {
const termMetric = new AggField({ ...defaultParams, aggType: AGG_TYPE.TERMS });
expect(termMetric.supportsFieldMetaFromLocalData()).toBe(false);
describe('source is not vector tiles', () => {
const geojsonSource = {
isMvt: () => {
return false;
},
} as unknown as IESAggSource;
test('should always support field meta from local', () => {
const avgMetric = new AggField({
...defaultParams,
source: geojsonSource,
aggType: AGG_TYPE.AVG,
});
expect(avgMetric.supportsFieldMetaFromLocalData()).toBe(true);
const maxMetric = new AggField({
...defaultParams,
source: geojsonSource,
aggType: AGG_TYPE.MAX,
});
expect(maxMetric.supportsFieldMetaFromLocalData()).toBe(true);
const minMetric = new AggField({
...defaultParams,
source: geojsonSource,
aggType: AGG_TYPE.MIN,
});
expect(minMetric.supportsFieldMetaFromLocalData()).toBe(true);
const sumMetric = new AggField({
...defaultParams,
source: geojsonSource,
aggType: AGG_TYPE.SUM,
});
expect(sumMetric.supportsFieldMetaFromLocalData()).toBe(true);
const uniqueCountMetric = new AggField({
...defaultParams,
source: geojsonSource,
aggType: AGG_TYPE.UNIQUE_COUNT,
});
expect(uniqueCountMetric.supportsFieldMetaFromLocalData()).toBe(true);
const termMetric = new AggField({
...defaultParams,
source: geojsonSource,
aggType: AGG_TYPE.TERMS,
});
expect(termMetric.supportsFieldMetaFromLocalData()).toBe(true);
});
});
});

View file

@ -44,7 +44,7 @@ export class AggField extends CountAggField {
supportsFieldMetaFromLocalData(): boolean {
// Elasticsearch vector tile search API returns meta tiles with numeric aggregation metrics.
return this._getDataTypeSynchronous() === 'number';
return this._source.isMvt() ? this._getDataTypeSynchronous() === 'number' : true;
}
isValid(): boolean {

View file

@ -5,7 +5,10 @@
* 2.0.
*/
import { percentilesValuesToFieldMeta } from './dynamic_style_property';
import { DynamicStyleProperty, percentilesValuesToFieldMeta } from './dynamic_style_property';
import type { IField } from '../../../fields/field';
import type { IVectorLayer } from '../../../layers/vector_layer';
import { type RawValue, VECTOR_STYLES } from '../../../../../common/constants';
describe('percentilesValuesToFieldMeta', () => {
test('should return null when values is not defined', () => {
@ -46,3 +49,59 @@ describe('percentilesValuesToFieldMeta', () => {
]);
});
});
describe('getFieldMetaOptions', () => {
const dynamicColorOptions = {
color: 'Blues',
colorCategory: 'palette_0',
field: {
name: 'machine.os.keyword',
origin: 'source',
},
fieldMetaOptions: {
isEnabled: false,
},
type: 'CATEGORICAL',
};
test('should not automatically enable fieldMeta when field does support field meta from local', () => {
const property = new DynamicStyleProperty(
dynamicColorOptions,
VECTOR_STYLES.FILL_COLOR,
{
supportsFieldMetaFromLocalData: () => {
return true;
},
} as unknown as IField,
{} as unknown as IVectorLayer,
() => {
return (value: RawValue) => value + '_format';
}
);
const fieldMetaOptions = property.getFieldMetaOptions();
expect(fieldMetaOptions.isEnabled).toBe(false);
});
test('should automatically enable fieldMeta when field does not support field meta from local', () => {
const property = new DynamicStyleProperty(
dynamicColorOptions,
VECTOR_STYLES.FILL_COLOR,
{
supportsFieldMetaFromLocalData: () => {
return false;
},
} as unknown as IField,
{} as unknown as IVectorLayer,
() => {
return (value: RawValue) => value + '_format';
}
);
const fieldMetaOptions = property.getFieldMetaOptions();
expect(fieldMetaOptions.isEnabled).toBe(true);
// should not mutate original options state
expect(dynamicColorOptions.fieldMetaOptions.isEnabled).toBe(false);
});
});

View file

@ -341,11 +341,12 @@ export class DynamicStyleProperty<T>
// The exact case that spawned this fix is with ES_SEARCH sources and 8.0 where vector tiles switched
// from vector tiles generated via Kibana server to vector tiles generated via Elasticsearch.
// Kibana vector tiles supported fieldMeta from local while Elasticsearch vector tiles do not support fieldMeta from local.
if (this._field && !this._field.supportsFieldMetaFromLocalData()) {
fieldMetaOptions.isEnabled = true;
}
return fieldMetaOptions;
return this._field && !this._field.supportsFieldMetaFromLocalData()
? {
...fieldMetaOptions,
isEnabled: true,
}
: fieldMetaOptions;
}
getDataMappingFunction() {