From 27bd92e30d39d197676b19263ae2ea2313c06754 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Wed, 18 Aug 2021 15:31:33 +0300 Subject: [PATCH 1/9] [vega] Handle removal of deprecated date histogram interval Fixes: #106352 --- .../public/data_model/es_query_parser.ts | 58 ++++++++++++------- .../vis_type_vega/public/data_model/types.ts | 1 - 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/plugins/vis_type_vega/public/data_model/es_query_parser.ts b/src/plugins/vis_type_vega/public/data_model/es_query_parser.ts index d0c63b8f2a6a01..bafbe3afb0b286 100644 --- a/src/plugins/vis_type_vega/public/data_model/es_query_parser.ts +++ b/src/plugins/vis_type_vega/public/data_model/es_query_parser.ts @@ -10,6 +10,7 @@ import moment from 'moment'; import { i18n } from '@kbn/i18n'; import { cloneDeep, isPlainObject } from 'lodash'; import type { estypes } from '@elastic/elasticsearch'; +import { Assign } from 'utility-types'; import { TimeCache } from './time_cache'; import { SearchAPI } from './search_api'; import { @@ -22,6 +23,7 @@ import { Query, ContextVarsObject, } from './types'; +import { dateHistogramInterval } from '../../../data/common'; const TIMEFILTER: string = '%timefilter%'; const AUTOINTERVAL: string = '%autointerval%'; @@ -226,7 +228,15 @@ export class EsQueryParser { * @param {*} obj * @param {boolean} isQuery - if true, the `obj` belongs to the req's query portion */ - _injectContextVars(obj: Query | estypes.SearchRequest['body']['aggs'], isQuery: boolean) { + _injectContextVars( + obj: Assign< + Query | estypes.SearchRequest['body']['aggs'], + { + interval?: { '%autointerval%': true | number } | string; + } + >, + isQuery: boolean + ) { if (obj && typeof obj === 'object') { if (Array.isArray(obj)) { // For arrays, replace MUST_CLAUSE and MUST_NOT_CLAUSE string elements @@ -270,27 +280,33 @@ export class EsQueryParser { const subObj = (obj as ContextVarsObject)[prop]; if (!subObj || typeof obj !== 'object') continue; - // replace "interval": { "%autointerval%": true|integer } with - // auto-generated range based on the timepicker - if (prop === 'interval' && subObj[AUTOINTERVAL]) { - let size = subObj[AUTOINTERVAL]; - if (size === true) { - size = 50; // by default, try to get ~80 values - } else if (typeof size !== 'number') { - throw new Error( - i18n.translate('visTypeVega.esQueryParser.autointervalValueTypeErrorMessage', { - defaultMessage: '{autointerval} must be either {trueValue} or a number', - values: { - autointerval: `"${AUTOINTERVAL}"`, - trueValue: 'true', - }, - }) - ); + // replace "interval" with ES acceptable fixed_interval / calendar_interval + if (prop === 'interval') { + let intervalString: string; + + if (typeof subObj === 'string') { + intervalString = subObj; + } else if (subObj[AUTOINTERVAL]) { + let size = subObj[AUTOINTERVAL]; + if (size === true) { + size = 50; // by default, try to get ~80 values + } else if (typeof size !== 'number') { + throw new Error( + i18n.translate('visTypeVega.esQueryParser.autointervalValueTypeErrorMessage', { + defaultMessage: '{autointerval} must be either {trueValue} or a number', + values: { + autointerval: `"${AUTOINTERVAL}"`, + trueValue: 'true', + }, + }) + ); + } + const { max, min } = this._timeCache.getTimeBounds(); + intervalString = EsQueryParser._roundInterval((max - min) / size); } - const bounds = this._timeCache.getTimeBounds(); - (obj as ContextVarsObject).interval = EsQueryParser._roundInterval( - (bounds.max - bounds.min) / size - ); + + Object.assign(obj, dateHistogramInterval(intervalString)); + delete obj.interval; continue; } diff --git a/src/plugins/vis_type_vega/public/data_model/types.ts b/src/plugins/vis_type_vega/public/data_model/types.ts index 75b1132176d672..d1568bba6c98cb 100644 --- a/src/plugins/vis_type_vega/public/data_model/types.ts +++ b/src/plugins/vis_type_vega/public/data_model/types.ts @@ -192,7 +192,6 @@ export type EmsQueryRequest = Requests & { export interface ContextVarsObject { [index: string]: any; prop: ContextVarsObjectProps; - interval: string; } export interface TooltipConfig { From 9187d9dd16e1adb23b39c35ca63f3c24c23fad9a Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Fri, 20 Aug 2021 15:52:12 +0300 Subject: [PATCH 2/9] fix CI --- .../vis_type_vega/public/data_model/es_query_parser.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/vis_type_vega/public/data_model/es_query_parser.test.js b/src/plugins/vis_type_vega/public/data_model/es_query_parser.test.js index 27ed5aa18a96d2..bb3c0276f4cf9f 100644 --- a/src/plugins/vis_type_vega/public/data_model/es_query_parser.test.js +++ b/src/plugins/vis_type_vega/public/data_model/es_query_parser.test.js @@ -178,11 +178,11 @@ describe(`EsQueryParser.injectQueryContextVars`, () => { ); test( `%autointerval% = true`, - check({ interval: { '%autointerval%': true } }, { interval: `1h` }, ctxObj) + check({ interval: { '%autointerval%': true } }, { calendar_interval: `1h` }, ctxObj) ); test( `%autointerval% = 10`, - check({ interval: { '%autointerval%': 10 } }, { interval: `3h` }, ctxObj) + check({ interval: { '%autointerval%': 10 } }, { fixed_interval: `3h` }, ctxObj) ); test(`%timefilter% = min`, check({ a: { '%timefilter%': 'min' } }, { a: rangeStart })); test(`%timefilter% = max`, check({ a: { '%timefilter%': 'max' } }, { a: rangeEnd })); From 5bfad4728ff62f46647b06bbbc6740baacd8548c Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Wed, 25 Aug 2021 16:21:09 +0300 Subject: [PATCH 3/9] add deprecation_interval_info --- .../parse_es_interval.test.ts | 7 ++ .../date_interval_utils/parse_es_interval.ts | 27 ++++++- .../components/deprecated_interval_info.tsx | 51 +++++++++++++ .../components/experimental_map_vis_info.tsx | 72 +++++++------------ .../public/components/vega_info_message.tsx | 41 +++++++++++ .../vis_type_vega/public/default.spec.hjson | 14 +--- src/plugins/vis_type_vega/public/vega_type.ts | 2 +- 7 files changed, 154 insertions(+), 60 deletions(-) create mode 100644 src/plugins/vis_type_vega/public/components/deprecated_interval_info.tsx create mode 100644 src/plugins/vis_type_vega/public/components/vega_info_message.tsx diff --git a/src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_es_interval.test.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_es_interval.test.ts index 2e7ffd9d562c3f..13d957e7c38bc7 100644 --- a/src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_es_interval.test.ts +++ b/src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_es_interval.test.ts @@ -22,6 +22,13 @@ describe('parseEsInterval', () => { expect(parseEsInterval('1y')).toEqual({ value: 1, unit: 'y', type: 'calendar' }); }); + it('should correctly parse an user-friendly intervals', () => { + expect(parseEsInterval('minute')).toEqual({ value: 1, unit: 'm', type: 'calendar' }); + expect(parseEsInterval('hour')).toEqual({ value: 1, unit: 'h', type: 'calendar' }); + expect(parseEsInterval('month')).toEqual({ value: 1, unit: 'M', type: 'calendar' }); + expect(parseEsInterval('year')).toEqual({ value: 1, unit: 'y', type: 'calendar' }); + }); + it('should correctly parse an interval containing unit and multiple value', () => { expect(parseEsInterval('250ms')).toEqual({ value: 250, unit: 'ms', type: 'fixed' }); expect(parseEsInterval('90s')).toEqual({ value: 90, unit: 's', type: 'fixed' }); diff --git a/src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_es_interval.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_es_interval.ts index 0280cc0f7c8af2..b723c3f45c5a6c 100644 --- a/src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_es_interval.ts +++ b/src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_es_interval.ts @@ -7,16 +7,37 @@ */ import dateMath, { Unit } from '@elastic/datemath'; - import { InvalidEsCalendarIntervalError } from './invalid_es_calendar_interval_error'; import { InvalidEsIntervalFormatError } from './invalid_es_interval_format_error'; const ES_INTERVAL_STRING_REGEX = new RegExp( '^([1-9][0-9]*)\\s*(' + dateMath.units.join('|') + ')$' ); - export type ParsedInterval = ReturnType; +/** ES allows to work at user-friendly intervals. + * This method matches between these intervals and the intervals accepted by parseEsInterval. + * @internal **/ +const mapToEquivalentInterval = (interval: string) => { + switch (interval) { + case 'minute': + return '1m'; + case 'hour': + return '1h'; + case 'day': + return '1d'; + case 'week': + return '1w'; + case 'month': + return '1M'; + case 'quarter': + return '1q'; + case 'year': + return '1y'; + } + return interval; +}; + /** * Extracts interval properties from an ES interval string. Disallows unrecognized interval formats * and fractional values. Converts some intervals from "calendar" to "fixed" when the number of @@ -37,7 +58,7 @@ export type ParsedInterval = ReturnType; * */ export function parseEsInterval(interval: string) { - const matches = String(interval).trim().match(ES_INTERVAL_STRING_REGEX); + const matches = String(mapToEquivalentInterval(interval)).trim().match(ES_INTERVAL_STRING_REGEX); if (!matches) { throw new InvalidEsIntervalFormatError(interval); diff --git a/src/plugins/vis_type_vega/public/components/deprecated_interval_info.tsx b/src/plugins/vis_type_vega/public/components/deprecated_interval_info.tsx new file mode 100644 index 00000000000000..43a89a1b4f604d --- /dev/null +++ b/src/plugins/vis_type_vega/public/components/deprecated_interval_info.tsx @@ -0,0 +1,51 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import React from 'react'; +import { EuiCallOut, EuiButtonIcon } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { VegaSpec } from '../data_model/types'; +import { getDocLinks } from '../services'; + +import { BUCKET_TYPES } from '../../../data/public'; + +export const DeprecatedHistogramIntervalInfo = () => ( + + ), + }} + /> + } + iconType="help" + /> +); + +export const shouldShowDeprecatedHistogramIntervalInfo = (spec: VegaSpec) => { + const data = Array.isArray(spec.data) ? spec.data : [spec.data]; + + return data.some((dataItem) => { + const aggs = dataItem.url?.body?.aggs ?? {}; + return Object.keys(aggs).some( + (key) => 'interval' in (aggs[key]?.[BUCKET_TYPES.DATE_HISTOGRAM] || {}) + ); + }); +}; diff --git a/src/plugins/vis_type_vega/public/components/experimental_map_vis_info.tsx b/src/plugins/vis_type_vega/public/components/experimental_map_vis_info.tsx index ca0cb0f0ff7973..8a1f2c27949743 100644 --- a/src/plugins/vis_type_vega/public/components/experimental_map_vis_info.tsx +++ b/src/plugins/vis_type_vega/public/components/experimental_map_vis_info.tsx @@ -6,55 +6,37 @@ * Side Public License, v 1. */ -import { parse } from 'hjson'; import React from 'react'; import { EuiCallOut, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { Vis } from '../../../visualizations/public'; -function ExperimentalMapLayerInfo() { - const title = ( - - GitHub - - ), - }} - /> - ); - - return ( - - ); -} +import type { VegaSpec } from '../data_model/types'; -export const getInfoMessage = (vis: Vis) => { - if (vis.params.spec) { - try { - const spec = parse(vis.params.spec, { legacyRoot: false, keepWsc: true }); - - if (spec.config?.kibana?.type === 'map') { - return ; - } - } catch (e) { - // spec is invalid +export const ExperimentalMapLayerInfo = () => ( + + GitHub + + ), + }} + /> } - } + iconType="beaker" + /> +); - return null; -}; +export const shouldShowMapLayerInfo = (spec: VegaSpec) => spec.config?.kibana?.type === 'map'; diff --git a/src/plugins/vis_type_vega/public/components/vega_info_message.tsx b/src/plugins/vis_type_vega/public/components/vega_info_message.tsx new file mode 100644 index 00000000000000..b29cfaa8d26753 --- /dev/null +++ b/src/plugins/vis_type_vega/public/components/vega_info_message.tsx @@ -0,0 +1,41 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import React, { useMemo } from 'react'; +import { parse } from 'hjson'; +import { ExperimentalMapLayerInfo, shouldShowMapLayerInfo } from './experimental_map_vis_info'; +import { + DeprecatedHistogramIntervalInfo, + shouldShowDeprecatedHistogramIntervalInfo, +} from './deprecated_interval_info'; + +import type { Vis } from '../../../visualizations/public'; +import type { VegaSpec } from '../data_model/types'; + +const parseSpec = (spec: string) => { + if (spec) { + try { + return parse(spec, { legacyRoot: false, keepWsc: true }); + } catch (e) { + // spec is invalid + } + } +}; + +const InfoMessage = ({ spec }: { spec: string }) => { + const vegaSpec: VegaSpec = useMemo(() => parseSpec(spec), [spec]); + + return ( + <> + {shouldShowMapLayerInfo(vegaSpec) && } + {shouldShowDeprecatedHistogramIntervalInfo(vegaSpec) && } + + ); +}; + +export const getInfoMessage = (vis: Vis) => ; diff --git a/src/plugins/vis_type_vega/public/default.spec.hjson b/src/plugins/vis_type_vega/public/default.spec.hjson index 834bfdc4ff2780..e22ed42b1ac3cd 100644 --- a/src/plugins/vis_type_vega/public/default.spec.hjson +++ b/src/plugins/vis_type_vega/public/default.spec.hjson @@ -33,19 +33,11 @@ See .search() documentation for : https://www.elastic.co/guide/en/elasticsearch body: { aggs: { time_buckets: { - date_histogram: { - // Use date histogram aggregation on @timestamp field + auto_date_histogram: { + // Use auto date histogram aggregation on @timestamp field field: @timestamp - // The interval value will depend on the daterange picker (true), or use an integer to set an approximate bucket count - interval: {%autointerval%: true} // Make sure we get an entire range, even if it has no data - extended_bounds: { - // Use the current time range's start and end - min: {%timefilter%: "min"} - max: {%timefilter%: "max"} - } - // Use this for linear (e.g. line, area) graphs. Without it, empty buckets will not show up - min_doc_count: 0 + buckets: 50 } } } diff --git a/src/plugins/vis_type_vega/public/vega_type.ts b/src/plugins/vis_type_vega/public/vega_type.ts index 902f79d03e680e..25b8a01d24dee9 100644 --- a/src/plugins/vis_type_vega/public/vega_type.ts +++ b/src/plugins/vis_type_vega/public/vega_type.ts @@ -16,7 +16,7 @@ import { getDefaultSpec } from './default_spec'; import { extractIndexPatternsFromSpec } from './lib/extract_index_pattern'; import { createInspectorAdapters } from './vega_inspector'; import { toExpressionAst } from './to_ast'; -import { getInfoMessage } from './components/experimental_map_vis_info'; +import { getInfoMessage } from './components/vega_info_message'; import { VegaVisEditorComponent } from './components/vega_vis_editor_lazy'; import type { VisParams } from './vega_fn'; From 4a64eb1aa83733ea396168f149ea41ba65cce898 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Wed, 25 Aug 2021 16:35:54 +0300 Subject: [PATCH 4/9] add test --- .../deprecated_interval_info.test.tsx | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/plugins/vis_type_vega/public/components/deprecated_interval_info.test.tsx diff --git a/src/plugins/vis_type_vega/public/components/deprecated_interval_info.test.tsx b/src/plugins/vis_type_vega/public/components/deprecated_interval_info.test.tsx new file mode 100644 index 00000000000000..bf4908f5b2e728 --- /dev/null +++ b/src/plugins/vis_type_vega/public/components/deprecated_interval_info.test.tsx @@ -0,0 +1,117 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { shouldShowDeprecatedHistogramIntervalInfo } from './deprecated_interval_info'; + +describe('shouldShowDeprecatedHistogramIntervalInfo', () => { + test('should show deprecated histogram interval', () => { + expect( + shouldShowDeprecatedHistogramIntervalInfo({ + data: { + url: { + body: { + aggs: { + test: { + date_histogram: { + interval: 'day', + }, + }, + }, + }, + }, + }, + }) + ).toBeTruthy(); + + expect( + shouldShowDeprecatedHistogramIntervalInfo({ + data: [ + { + url: { + body: { + aggs: { + test: { + date_histogram: { + interval: 'day', + }, + }, + }, + }, + }, + }, + { + url: { + body: { + aggs: { + test: { + date_histogram: { + calendar_interval: 'day', + }, + }, + }, + }, + }, + }, + ], + }) + ).toBeTruthy(); + }); + + test('should not show deprecated histogram interval', () => { + expect( + shouldShowDeprecatedHistogramIntervalInfo({ + data: { + url: { + body: { + aggs: { + test: { + auto_date_histogram: { + field: 'bytes', + }, + }, + }, + }, + }, + }, + }) + ).toBeFalsy(); + + expect( + shouldShowDeprecatedHistogramIntervalInfo({ + data: [ + { + url: { + body: { + aggs: { + test: { + date_histogram: { + calendar_interval: 'week', + }, + }, + }, + }, + }, + }, + { + url: { + body: { + aggs: { + test: { + date_histogram: { + fixed_interval: '23d', + }, + }, + }, + }, + }, + }, + ], + }) + ).toBeFalsy(); + }); +}); From e4276921f3720c397a1e94762bd0560aa5db4716 Mon Sep 17 00:00:00 2001 From: Uladzislau Lasitsa Date: Mon, 30 Aug 2021 18:17:28 +0300 Subject: [PATCH 5/9] Update vega_info_message.tsx --- .../vis_type_vega/public/components/vega_info_message.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/vis_type_vega/public/components/vega_info_message.tsx b/src/plugins/vis_type_vega/public/components/vega_info_message.tsx index b29cfaa8d26753..fbae8b2a926be4 100644 --- a/src/plugins/vis_type_vega/public/components/vega_info_message.tsx +++ b/src/plugins/vis_type_vega/public/components/vega_info_message.tsx @@ -30,6 +30,10 @@ const parseSpec = (spec: string) => { const InfoMessage = ({ spec }: { spec: string }) => { const vegaSpec: VegaSpec = useMemo(() => parseSpec(spec), [spec]); + if (!vegaSpec) { + return null; + } + return ( <> {shouldShowMapLayerInfo(vegaSpec) && } From 93a6a02f7723f9367dde72d5ef8086e9d5d8f42c Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Thu, 9 Sep 2021 13:21:02 +0300 Subject: [PATCH 6/9] fix types --- .../vega/public/components/deprecated_interval_info.tsx | 2 +- .../vis_types/vega/public/components/vega_info_message.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx b/src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx index 43a89a1b4f604d..913ad3e255bd11 100644 --- a/src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx +++ b/src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx @@ -12,7 +12,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { VegaSpec } from '../data_model/types'; import { getDocLinks } from '../services'; -import { BUCKET_TYPES } from '../../../data/public'; +import { BUCKET_TYPES } from '../../../../data/public'; export const DeprecatedHistogramIntervalInfo = () => ( { From afdcf77a7adcfe75c011d6dd0ce93c9a16613bbf Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Thu, 9 Sep 2021 15:19:49 +0300 Subject: [PATCH 7/9] Update es_query_parser.ts --- src/plugins/vis_types/vega/public/data_model/es_query_parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/vis_types/vega/public/data_model/es_query_parser.ts b/src/plugins/vis_types/vega/public/data_model/es_query_parser.ts index bafbe3afb0b286..134e82d6767638 100644 --- a/src/plugins/vis_types/vega/public/data_model/es_query_parser.ts +++ b/src/plugins/vis_types/vega/public/data_model/es_query_parser.ts @@ -23,7 +23,7 @@ import { Query, ContextVarsObject, } from './types'; -import { dateHistogramInterval } from '../../../data/common'; +import { dateHistogramInterval } from '../../../../data/common'; const TIMEFILTER: string = '%timefilter%'; const AUTOINTERVAL: string = '%autointerval%'; From 3e7018138d0e2763567498642bbec12554596cf6 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Tue, 21 Sep 2021 17:54:35 +0300 Subject: [PATCH 8/9] apply comments --- .../deprecated_interval_info.test.tsx | 18 ++++++++++++++++++ .../components/deprecated_interval_info.tsx | 8 +++++--- .../vis_types/vega/public/default.spec.hjson | 14 +++++++++++--- test/functional/apps/visualize/_vega_chart.ts | 3 +-- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/plugins/vis_types/vega/public/components/deprecated_interval_info.test.tsx b/src/plugins/vis_types/vega/public/components/deprecated_interval_info.test.tsx index bf4908f5b2e728..d88cf279881b37 100644 --- a/src/plugins/vis_types/vega/public/components/deprecated_interval_info.test.tsx +++ b/src/plugins/vis_types/vega/public/components/deprecated_interval_info.test.tsx @@ -63,6 +63,24 @@ describe('shouldShowDeprecatedHistogramIntervalInfo', () => { }); test('should not show deprecated histogram interval', () => { + expect( + shouldShowDeprecatedHistogramIntervalInfo({ + data: { + url: { + body: { + aggs: { + test: { + date_histogram: { + interval: { '%autointerval%': true }, + }, + }, + }, + }, + }, + }, + }) + ).toBeFalsy(); + expect( shouldShowDeprecatedHistogramIntervalInfo({ data: { diff --git a/src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx b/src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx index 913ad3e255bd11..c9ebb1a8695746 100644 --- a/src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx +++ b/src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx @@ -44,8 +44,10 @@ export const shouldShowDeprecatedHistogramIntervalInfo = (spec: VegaSpec) => { return data.some((dataItem) => { const aggs = dataItem.url?.body?.aggs ?? {}; - return Object.keys(aggs).some( - (key) => 'interval' in (aggs[key]?.[BUCKET_TYPES.DATE_HISTOGRAM] || {}) - ); + + return Object.keys(aggs).some((key) => { + const dateHistogram = aggs[key]?.[BUCKET_TYPES.DATE_HISTOGRAM] || {}; + return 'interval' in dateHistogram && typeof dateHistogram.interval !== 'object'; + }); }); }; diff --git a/src/plugins/vis_types/vega/public/default.spec.hjson b/src/plugins/vis_types/vega/public/default.spec.hjson index e22ed42b1ac3cd..834bfdc4ff2780 100644 --- a/src/plugins/vis_types/vega/public/default.spec.hjson +++ b/src/plugins/vis_types/vega/public/default.spec.hjson @@ -33,11 +33,19 @@ See .search() documentation for : https://www.elastic.co/guide/en/elasticsearch body: { aggs: { time_buckets: { - auto_date_histogram: { - // Use auto date histogram aggregation on @timestamp field + date_histogram: { + // Use date histogram aggregation on @timestamp field field: @timestamp + // The interval value will depend on the daterange picker (true), or use an integer to set an approximate bucket count + interval: {%autointerval%: true} // Make sure we get an entire range, even if it has no data - buckets: 50 + extended_bounds: { + // Use the current time range's start and end + min: {%timefilter%: "min"} + max: {%timefilter%: "max"} + } + // Use this for linear (e.g. line, area) graphs. Without it, empty buckets will not show up + min_doc_count: 0 } } } diff --git a/test/functional/apps/visualize/_vega_chart.ts b/test/functional/apps/visualize/_vega_chart.ts index c52b0e0f8451f8..b2692c2a00d781 100644 --- a/test/functional/apps/visualize/_vega_chart.ts +++ b/test/functional/apps/visualize/_vega_chart.ts @@ -41,8 +41,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { const retry = getService('retry'); const browser = getService('browser'); - // SKIPPED: https://github.com/elastic/kibana/issues/106352 - describe.skip('vega chart in visualize app', () => { + describe('vega chart in visualize app', () => { before(async () => { await PageObjects.visualize.initTests(); log.debug('navigateToApp visualize'); From adfd563cc57742dd50f73620e7acf5e080e7d932 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Wed, 22 Sep 2021 12:57:37 +0300 Subject: [PATCH 9/9] fix error --- .../vega/public/components/deprecated_interval_info.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx b/src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx index c9ebb1a8695746..23144a4c2084d3 100644 --- a/src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx +++ b/src/plugins/vis_types/vega/public/components/deprecated_interval_info.tsx @@ -40,9 +40,9 @@ export const DeprecatedHistogramIntervalInfo = () => ( ); export const shouldShowDeprecatedHistogramIntervalInfo = (spec: VegaSpec) => { - const data = Array.isArray(spec.data) ? spec.data : [spec.data]; + const data = Array.isArray(spec.data) ? spec?.data : [spec.data]; - return data.some((dataItem) => { + return data.some((dataItem = {}) => { const aggs = dataItem.url?.body?.aggs ?? {}; return Object.keys(aggs).some((key) => {