From df22cae44c453d455fa0adb94ce8d75807ccf588 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Tue, 23 Mar 2021 18:14:08 +0100 Subject: [PATCH 1/5] simplify date histogram meta and apply interval scaling to all levels --- .../data/common/search/aggs/agg_config.ts | 12 +- .../data/common/search/aggs/agg_configs.ts | 5 + .../common/search/aggs/aggs_service.test.ts | 3 +- .../data/common/search/aggs/aggs_service.ts | 7 - .../search/aggs/buckets/date_histogram.ts | 30 ++++ src/plugins/data/common/search/aggs/types.ts | 14 -- .../aggs/utils/get_date_histogram_meta.ts | 35 +++++ .../data/common/search/aggs/utils/index.ts | 1 + .../aggs/utils/time_column_meta.test.ts | 147 ------------------ .../search/aggs/utils/time_column_meta.ts | 57 ------- .../esaggs/request_handler.test.ts | 1 + .../expressions/esaggs/request_handler.ts | 1 + src/plugins/data/public/index.ts | 2 + .../public/search/aggs/aggs_service.test.ts | 3 +- .../data/public/search/aggs/aggs_service.ts | 18 +-- src/plugins/data/public/search/aggs/mocks.ts | 1 - .../data/server/search/aggs/aggs_service.ts | 2 - src/plugins/data/server/search/aggs/mocks.ts | 1 - .../time_scale.test.ts | 30 +++- .../indexpattern_datasource/time_scale.ts | 4 +- .../xy_visualization/expression.test.tsx | 32 ++-- .../public/xy_visualization/expression.tsx | 20 +-- .../lens/public/xy_visualization/index.ts | 1 - 23 files changed, 143 insertions(+), 284 deletions(-) create mode 100644 src/plugins/data/common/search/aggs/utils/get_date_histogram_meta.ts delete mode 100644 src/plugins/data/common/search/aggs/utils/time_column_meta.test.ts delete mode 100644 src/plugins/data/common/search/aggs/utils/time_column_meta.ts diff --git a/src/plugins/data/common/search/aggs/agg_config.ts b/src/plugins/data/common/search/aggs/agg_config.ts index f62fedc13b32a..a237f5dfc43b5 100644 --- a/src/plugins/data/common/search/aggs/agg_config.ts +++ b/src/plugins/data/common/search/aggs/agg_config.ts @@ -437,10 +437,14 @@ export class AggConfig { } fieldIsTimeField() { - const indexPattern = this.getIndexPattern(); - if (!indexPattern) return false; - const timeFieldName = indexPattern.timeFieldName; - return timeFieldName && this.fieldName() === timeFieldName; + const defaultTimeField = this.getIndexPattern()?.getTimeField?.()?.name; + const defaultTimeFields = defaultTimeField ? [defaultTimeField] : []; + const allTimeFields = + this.aggConfigs.timeFields && this.aggConfigs.timeFields.length > 0 + ? this.aggConfigs.timeFields + : defaultTimeFields; + const currentFieldName = this.fieldName(); + return allTimeFields.includes(currentFieldName); } public get type() { diff --git a/src/plugins/data/common/search/aggs/agg_configs.ts b/src/plugins/data/common/search/aggs/agg_configs.ts index c9986b7e93bed..ea42d0641f374 100644 --- a/src/plugins/data/common/search/aggs/agg_configs.ts +++ b/src/plugins/data/common/search/aggs/agg_configs.ts @@ -57,6 +57,7 @@ export type IAggConfigs = AggConfigs; export class AggConfigs { public indexPattern: IndexPattern; public timeRange?: TimeRange; + public timeFields?: string[]; private readonly typesRegistry: AggTypesRegistryStart; aggs: IAggConfig[]; @@ -76,6 +77,10 @@ export class AggConfigs { configStates.forEach((params: any) => this.createAggConfig(params)); } + setTimeFields(timeFields: string[] | undefined) { + this.timeFields = timeFields; + } + setTimeRange(timeRange: TimeRange) { this.timeRange = timeRange; diff --git a/src/plugins/data/common/search/aggs/aggs_service.test.ts b/src/plugins/data/common/search/aggs/aggs_service.test.ts index 92e6168b169c6..14e4f7932e9c1 100644 --- a/src/plugins/data/common/search/aggs/aggs_service.test.ts +++ b/src/plugins/data/common/search/aggs/aggs_service.test.ts @@ -192,9 +192,8 @@ describe('Aggs service', () => { describe('start()', () => { test('exposes proper contract', () => { const start = service.start(startDeps); - expect(Object.keys(start).length).toBe(5); + expect(Object.keys(start).length).toBe(4); expect(start).toHaveProperty('calculateAutoTimeExpression'); - expect(start).toHaveProperty('getDateMetaByDatatableColumn'); expect(start).toHaveProperty('createAggConfigs'); expect(start).toHaveProperty('types'); expect(start).toHaveProperty('datatableUtilities'); diff --git a/src/plugins/data/common/search/aggs/aggs_service.ts b/src/plugins/data/common/search/aggs/aggs_service.ts index c5543e5037fc6..86bda5019a496 100644 --- a/src/plugins/data/common/search/aggs/aggs_service.ts +++ b/src/plugins/data/common/search/aggs/aggs_service.ts @@ -17,7 +17,6 @@ import { getCalculateAutoTimeExpression, } from './'; import { AggsCommonSetup, AggsCommonStart } from './types'; -import { getDateMetaByDatatableColumn } from './utils/time_column_meta'; import { getDatatableColumnUtilities } from './utils/datatable_column_meta'; /** @internal */ @@ -89,12 +88,6 @@ export class AggsCommonService { return { calculateAutoTimeExpression, - getDateMetaByDatatableColumn: getDateMetaByDatatableColumn({ - calculateAutoTimeExpression, - getIndexPattern, - getConfig, - isDefaultTimezone, - }), datatableUtilities: getDatatableColumnUtilities({ getIndexPattern, createAggConfigs, diff --git a/src/plugins/data/common/search/aggs/buckets/date_histogram.ts b/src/plugins/data/common/search/aggs/buckets/date_histogram.ts index 61ad66d7efdc9..4fa4d4f213ca2 100644 --- a/src/plugins/data/common/search/aggs/buckets/date_histogram.ts +++ b/src/plugins/data/common/search/aggs/buckets/date_histogram.ts @@ -64,7 +64,9 @@ export interface AggParamsDateHistogram extends BaseAggParams { useNormalizedEsInterval?: boolean; scaleMetricValues?: boolean; interval?: string; + used_interval?: string; time_zone?: string; + used_time_zone?: string; drop_partials?: boolean; format?: string; min_doc_count?: number; @@ -220,6 +222,22 @@ export const getDateHistogramBucketAgg = ({ } }, }, + { + name: 'used_interval', + default: autoInterval, + shouldShow() { + return false; + }, + write: () => {}, + serialize(val, agg) { + if (!agg) return undefined; + updateTimeBuckets(agg, calculateBounds); + const { useNormalizedEsInterval } = agg.params; + const interval = agg.buckets.getInterval(useNormalizedEsInterval); + return interval.expression; + }, + toExpressionAst: () => undefined, + }, { name: 'time_zone', default: undefined, @@ -232,6 +250,18 @@ export const getDateHistogramBucketAgg = ({ output.params.time_zone = tz; }, }, + { + name: 'used_timezone', + shouldShow() { + return false; + }, + write: () => {}, + serialize(val, agg) { + if (!agg) return undefined; + return inferTimeZone(agg.params, agg.getIndexPattern(), isDefaultTimezone, getConfig); + }, + toExpressionAst: () => undefined, + }, { name: 'drop_partials', default: false, diff --git a/src/plugins/data/common/search/aggs/types.ts b/src/plugins/data/common/search/aggs/types.ts index 48ded7fa7a7fc..a4e51efc0f609 100644 --- a/src/plugins/data/common/search/aggs/types.ts +++ b/src/plugins/data/common/search/aggs/types.ts @@ -9,7 +9,6 @@ import { Assign } from '@kbn/utility-types'; import { DatatableColumn } from 'src/plugins/expressions'; import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern'; -import { TimeRange } from '../../query'; import { aggAvg, aggBucketAvg, @@ -104,19 +103,6 @@ export interface AggsCommonSetup { /** @internal */ export interface AggsCommonStart { calculateAutoTimeExpression: ReturnType; - /** - * Helper function returning meta data about use date intervals for a data table column. - * If the column is not a column created by a date histogram aggregation of the esaggs data source, - * this function will return undefined. - * - * Otherwise, it will return the following attributes in an object: - * * `timeZone` time zone used to create the buckets (important e.g. for DST), - * * `timeRange` total time range of the fetch data (to infer partial buckets at the beginning and end of the data) - * * `interval` Interval used on elasticsearch (`auto` resolved to the actual interval) - */ - getDateMetaByDatatableColumn: ( - column: DatatableColumn - ) => Promise; datatableUtilities: { getIndexPattern: (column: DatatableColumn) => Promise; getAggConfig: (column: DatatableColumn) => Promise; diff --git a/src/plugins/data/common/search/aggs/utils/get_date_histogram_meta.ts b/src/plugins/data/common/search/aggs/utils/get_date_histogram_meta.ts new file mode 100644 index 0000000000000..86631c24f58ad --- /dev/null +++ b/src/plugins/data/common/search/aggs/utils/get_date_histogram_meta.ts @@ -0,0 +1,35 @@ +/* + * 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 { DatatableColumn } from 'src/plugins/expressions/common'; +import { TimeRange } from '../../../types'; +import type { AggParamsDateHistogram } from '../buckets'; +import { BUCKET_TYPES } from '../buckets/bucket_agg_types'; + +/** + * Helper function returning the used interval for data table column created by the histogramm agg type. + * "auto" will get expanded to the actually used interval. + * If the column is not a column created by a histogram aggregation of the esaggs data source, + * this function will return undefined. + */ +export const getDateHistogramMetaDataByDatatableColumn = (column: DatatableColumn) => { + if (column.meta.source !== 'esaggs') return; + if (column.meta.sourceParams?.type !== BUCKET_TYPES.DATE_HISTOGRAM) return; + const params = (column.meta.sourceParams.params as unknown) as AggParamsDateHistogram; + + let interval: string | undefined; + if (params.used_interval && params.used_interval !== 'auto') { + interval = params.used_interval; + } + + return { + interval, + timeZone: params.used_time_zone, + timeRange: column.meta.sourceParams.appliedTimeRange as TimeRange | undefined, + }; +}; diff --git a/src/plugins/data/common/search/aggs/utils/index.ts b/src/plugins/data/common/search/aggs/utils/index.ts index f90e8f88546f4..c92653e843233 100644 --- a/src/plugins/data/common/search/aggs/utils/index.ts +++ b/src/plugins/data/common/search/aggs/utils/index.ts @@ -8,6 +8,7 @@ export * from './calculate_auto_time_expression'; export { getNumberHistogramIntervalByDatatableColumn } from './get_number_histogram_interval'; +export { getDateHistogramMetaDataByDatatableColumn } from './get_date_histogram_meta'; export * from './date_interval_utils'; export * from './get_format_with_aggs'; export * from './ipv4_address'; diff --git a/src/plugins/data/common/search/aggs/utils/time_column_meta.test.ts b/src/plugins/data/common/search/aggs/utils/time_column_meta.test.ts deleted file mode 100644 index d9527ecd92a12..0000000000000 --- a/src/plugins/data/common/search/aggs/utils/time_column_meta.test.ts +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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 { BUCKET_TYPES } from '../buckets'; -import { DateMetaByColumnDeps, getDateMetaByDatatableColumn } from './time_column_meta'; - -describe('getDateMetaByDatatableColumn', () => { - let params: DateMetaByColumnDeps; - beforeEach(() => { - params = { - calculateAutoTimeExpression: jest.fn().mockReturnValue('5m'), - getIndexPattern: jest.fn().mockResolvedValue({}), - isDefaultTimezone: jest.fn().mockReturnValue(true), - getConfig: jest.fn(), - }; - }); - - it('returns nothing on column from other data source', async () => { - expect( - await getDateMetaByDatatableColumn(params)({ - id: 'test', - name: 'test', - meta: { - type: 'date', - source: 'essql', - }, - }) - ).toEqual(undefined); - }); - - it('returns nothing on non date histogram column', async () => { - expect( - await getDateMetaByDatatableColumn(params)({ - id: 'test', - name: 'test', - meta: { - type: 'date', - source: 'esaggs', - sourceParams: { - type: BUCKET_TYPES.TERMS, - }, - }, - }) - ).toEqual(undefined); - }); - - it('returns time range, time zone and interval', async () => { - expect( - await getDateMetaByDatatableColumn(params)({ - id: 'test', - name: 'test', - meta: { - type: 'date', - source: 'esaggs', - sourceParams: { - type: BUCKET_TYPES.DATE_HISTOGRAM, - params: { - time_zone: 'UTC', - interval: '1h', - }, - appliedTimeRange: { - from: 'now-5d', - to: 'now', - }, - }, - }, - }) - ).toEqual({ - timeZone: 'UTC', - timeRange: { - from: 'now-5d', - to: 'now', - }, - interval: '1h', - }); - }); - - it('throws if unable to resolve interval', async () => { - await expect( - getDateMetaByDatatableColumn(params)({ - id: 'test', - name: 'test', - meta: { - type: 'date', - source: 'esaggs', - sourceParams: { - type: BUCKET_TYPES.DATE_HISTOGRAM, - params: { - time_zone: 'UTC', - interval: 'auto', - }, - }, - }, - }) - ).rejects.toBeDefined(); - - await expect( - getDateMetaByDatatableColumn(params)({ - id: 'test', - name: 'test', - meta: { - type: 'date', - source: 'esaggs', - sourceParams: { - type: BUCKET_TYPES.DATE_HISTOGRAM, - params: { - time_zone: 'UTC', - }, - }, - }, - }) - ).rejects.toBeDefined(); - }); - - it('returns resolved auto interval', async () => { - expect( - await getDateMetaByDatatableColumn(params)({ - id: 'test', - name: 'test', - meta: { - type: 'date', - source: 'esaggs', - sourceParams: { - type: BUCKET_TYPES.DATE_HISTOGRAM, - params: { - time_zone: 'UTC', - interval: 'auto', - }, - appliedTimeRange: { - from: '2020-10-05T00:00:00.000Z', - to: '2020-10-10T00:00:00.000Z', - }, - }, - }, - }) - ).toEqual( - expect.objectContaining({ - interval: '5m', - }) - ); - }); -}); diff --git a/src/plugins/data/common/search/aggs/utils/time_column_meta.ts b/src/plugins/data/common/search/aggs/utils/time_column_meta.ts deleted file mode 100644 index b0912803908cc..0000000000000 --- a/src/plugins/data/common/search/aggs/utils/time_column_meta.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 { DatatableColumn } from 'src/plugins/expressions/common'; -import { IndexPattern } from '../../../index_patterns'; - -import { TimeRange } from '../../../types'; -import { AggParamsDateHistogram, BUCKET_TYPES } from '../buckets'; -import { inferTimeZone } from './infer_time_zone'; - -export interface DateMetaByColumnDeps { - calculateAutoTimeExpression: (range: TimeRange) => string | undefined; - getIndexPattern: (id: string) => Promise; - isDefaultTimezone: () => boolean; - getConfig: (key: string) => T; -} - -export const getDateMetaByDatatableColumn = ({ - calculateAutoTimeExpression, - getIndexPattern, - isDefaultTimezone, - getConfig, -}: DateMetaByColumnDeps) => async ( - column: DatatableColumn -): Promise => { - if (column.meta.source !== 'esaggs') return; - if (column.meta.sourceParams?.type !== BUCKET_TYPES.DATE_HISTOGRAM) return; - const params = column.meta.sourceParams.params as AggParamsDateHistogram; - const appliedTimeRange = column.meta.sourceParams.appliedTimeRange as TimeRange | undefined; - - const tz = inferTimeZone( - params, - await getIndexPattern(column.meta.sourceParams.indexPatternId as string), - isDefaultTimezone, - getConfig - ); - - const interval = - params.interval === 'auto' && appliedTimeRange - ? calculateAutoTimeExpression(appliedTimeRange) - : params.interval; - - if (!interval || interval === 'auto') { - throw new Error('time interval could not be determined'); - } - - return { - timeZone: tz, - timeRange: appliedTimeRange, - interval, - }; -}; diff --git a/src/plugins/data/common/search/expressions/esaggs/request_handler.test.ts b/src/plugins/data/common/search/expressions/esaggs/request_handler.test.ts index f8604266cd6e0..7580032b0dd85 100644 --- a/src/plugins/data/common/search/expressions/esaggs/request_handler.test.ts +++ b/src/plugins/data/common/search/expressions/esaggs/request_handler.test.ts @@ -33,6 +33,7 @@ describe('esaggs expression function - public', () => { setTimeRange: jest.fn(), toDsl: jest.fn().mockReturnValue({ aggs: {} }), onSearchRequestStart: jest.fn(), + setTimeFields: jest.fn(), } as unknown) as jest.Mocked, filters: undefined, indexPattern: ({ id: 'logstash-*' } as unknown) as jest.Mocked, diff --git a/src/plugins/data/common/search/expressions/esaggs/request_handler.ts b/src/plugins/data/common/search/expressions/esaggs/request_handler.ts index e2ee1a31757cb..72d9cc4095570 100644 --- a/src/plugins/data/common/search/expressions/esaggs/request_handler.ts +++ b/src/plugins/data/common/search/expressions/esaggs/request_handler.ts @@ -73,6 +73,7 @@ export const handleRequest = async ({ const requestSearchSource = timeFilterSearchSource.createChild({ callParentStartHandlers: true }); aggs.setTimeRange(timeRange as TimeRange); + aggs.setTimeFields(timeFields); // For now we need to mirror the history of the passed search source, since // the request inspector wouldn't work otherwise. diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index 1838ca43e8c23..c47cd6cd9740d 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -313,6 +313,7 @@ import { toAbsoluteDates, boundsDescendingRaw, getNumberHistogramIntervalByDatatableColumn, + getDateHistogramMetaDataByDatatableColumn, // expressions utils getRequestInspectorStats, getResponseInspectorStats, @@ -423,6 +424,7 @@ export const search = { toAbsoluteDates, boundsDescendingRaw, getNumberHistogramIntervalByDatatableColumn, + getDateHistogramMetaDataByDatatableColumn, }, getRequestInspectorStats, getResponseInspectorStats, diff --git a/src/plugins/data/public/search/aggs/aggs_service.test.ts b/src/plugins/data/public/search/aggs/aggs_service.test.ts index 63c27eeaf0b11..3d17565efbc5f 100644 --- a/src/plugins/data/public/search/aggs/aggs_service.test.ts +++ b/src/plugins/data/public/search/aggs/aggs_service.test.ts @@ -79,9 +79,8 @@ describe('AggsService - public', () => { describe('start()', () => { test('exposes proper contract', () => { const start = service.start(startDeps); - expect(Object.keys(start).length).toBe(5); + expect(Object.keys(start).length).toBe(4); expect(start).toHaveProperty('calculateAutoTimeExpression'); - expect(start).toHaveProperty('getDateMetaByDatatableColumn'); expect(start).toHaveProperty('createAggConfigs'); expect(start).toHaveProperty('types'); expect(start).toHaveProperty('datatableUtilities'); diff --git a/src/plugins/data/public/search/aggs/aggs_service.ts b/src/plugins/data/public/search/aggs/aggs_service.ts index 26f19ca7eaef4..f603bd733f601 100644 --- a/src/plugins/data/public/search/aggs/aggs_service.ts +++ b/src/plugins/data/public/search/aggs/aggs_service.ts @@ -91,16 +91,13 @@ export class AggsService { public start({ fieldFormats, uiSettings, indexPatterns }: AggsStartDependencies): AggsStart { const isDefaultTimezone = () => uiSettings.isDefault('dateFormat:tz'); - const { - calculateAutoTimeExpression, - getDateMetaByDatatableColumn, - datatableUtilities, - types, - } = this.aggsCommonService.start({ - getConfig: this.getConfig!, - getIndexPattern: indexPatterns.get, - isDefaultTimezone, - }); + const { calculateAutoTimeExpression, datatableUtilities, types } = this.aggsCommonService.start( + { + getConfig: this.getConfig!, + getIndexPattern: indexPatterns.get, + isDefaultTimezone, + } + ); const aggTypesDependencies: AggTypesDependencies = { calculateBounds: this.calculateBounds, @@ -140,7 +137,6 @@ export class AggsService { return { calculateAutoTimeExpression, - getDateMetaByDatatableColumn, datatableUtilities, createAggConfigs: (indexPattern, configStates = []) => { return new AggConfigs(indexPattern, configStates, { typesRegistry }); diff --git a/src/plugins/data/public/search/aggs/mocks.ts b/src/plugins/data/public/search/aggs/mocks.ts index 9c90af801bdac..fb50058f08348 100644 --- a/src/plugins/data/public/search/aggs/mocks.ts +++ b/src/plugins/data/public/search/aggs/mocks.ts @@ -56,7 +56,6 @@ export const searchAggsSetupMock = (): AggsSetup => ({ export const searchAggsStartMock = (): AggsStart => ({ calculateAutoTimeExpression: getCalculateAutoTimeExpression(getConfig), - getDateMetaByDatatableColumn: jest.fn(), datatableUtilities: { isFilterable: jest.fn(), getAggConfig: jest.fn(), diff --git a/src/plugins/data/server/search/aggs/aggs_service.ts b/src/plugins/data/server/search/aggs/aggs_service.ts index ac81c5b0d5df4..96927728f2f2f 100644 --- a/src/plugins/data/server/search/aggs/aggs_service.ts +++ b/src/plugins/data/server/search/aggs/aggs_service.ts @@ -74,7 +74,6 @@ export class AggsService { const { calculateAutoTimeExpression, - getDateMetaByDatatableColumn, datatableUtilities, types, } = this.aggsCommonService.start({ @@ -119,7 +118,6 @@ export class AggsService { return { calculateAutoTimeExpression, - getDateMetaByDatatableColumn, datatableUtilities, createAggConfigs: (indexPattern, configStates = []) => { return new AggConfigs(indexPattern, configStates, { typesRegistry }); diff --git a/src/plugins/data/server/search/aggs/mocks.ts b/src/plugins/data/server/search/aggs/mocks.ts index 70864d57b3565..3644a3c13c48d 100644 --- a/src/plugins/data/server/search/aggs/mocks.ts +++ b/src/plugins/data/server/search/aggs/mocks.ts @@ -58,7 +58,6 @@ export const searchAggsSetupMock = (): AggsSetup => ({ const commonStartMock = (): AggsCommonStart => ({ calculateAutoTimeExpression: getCalculateAutoTimeExpression(getConfig), - getDateMetaByDatatableColumn: jest.fn(), datatableUtilities: { getIndexPattern: jest.fn(), getAggConfig: jest.fn(), diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/time_scale.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/time_scale.test.ts index 2e4de8b52dacb..34579927cfe19 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/time_scale.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/time_scale.test.ts @@ -7,7 +7,7 @@ import moment from 'moment'; import { Datatable } from 'src/plugins/expressions/public'; -import { DataPublicPluginStart } from 'src/plugins/data/public'; +import { DataPublicPluginStart, TimeRange } from 'src/plugins/data/public'; import { dataPluginMock } from '../../../../../src/plugins/data/public/mocks'; import { functionWrapper } from 'src/plugins/expressions/common/expression_functions/specs/tests/utils'; import { getTimeScaleFunction, TimeScaleArgs } from './time_scale'; @@ -44,9 +44,25 @@ describe('time_scale', () => { targetUnit: 'h', }; + function setDateHistogramMeta(options: { + timeZone: string; + timeRange: TimeRange; + interval: string; + }) { + emptyTable.columns[0].meta.source = 'esaggs'; + emptyTable.columns[0].meta.sourceParams = { + type: 'date_histogram', + params: { + used_interval: options.interval, + used_time_zone: options.timeZone, + }, + appliedTimeRange: options.timeRange, + }; + } + beforeEach(() => { dataMock = dataPluginMock.createStartContract(); - (dataMock.search.aggs.getDateMetaByDatatableColumn as jest.Mock).mockReturnValue({ + setDateHistogramMeta({ timeZone: 'UTC', timeRange: { from: '2020-10-05T00:00:00.000Z', @@ -156,7 +172,7 @@ describe('time_scale', () => { }); it('should be able to scale up as well', async () => { - (dataMock.search.aggs.getDateMetaByDatatableColumn as jest.Mock).mockReturnValue({ + setDateHistogramMeta({ timeZone: 'UTC', timeRange: { from: '2020-10-05T12:00:00.000Z', @@ -196,7 +212,7 @@ describe('time_scale', () => { }); it('can scale starting from unit multiple target intervals', async () => { - (dataMock.search.aggs.getDateMetaByDatatableColumn as jest.Mock).mockReturnValue({ + setDateHistogramMeta({ timeZone: 'UTC', timeRange: { from: '2020-10-05T13:00:00.000Z', @@ -238,7 +254,7 @@ describe('time_scale', () => { }); it('take start and end of timerange into account', async () => { - (dataMock.search.aggs.getDateMetaByDatatableColumn as jest.Mock).mockReturnValue({ + setDateHistogramMeta({ timeZone: 'UTC', timeRange: { from: '2020-10-05T12:00:00.000Z', @@ -283,7 +299,7 @@ describe('time_scale', () => { }); it('should respect DST switches', async () => { - (dataMock.search.aggs.getDateMetaByDatatableColumn as jest.Mock).mockReturnValue({ + setDateHistogramMeta({ timeZone: 'Europe/Berlin', timeRange: { from: '2020-10-23T00:00:00.000+02:00', @@ -323,7 +339,7 @@ describe('time_scale', () => { }); it('take leap years into account', async () => { - (dataMock.search.aggs.getDateMetaByDatatableColumn as jest.Mock).mockReturnValue({ + setDateHistogramMeta({ timeZone: 'UTC', timeRange: { from: '2010-01-01T00:00:00.000Z', diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/time_scale.ts b/x-pack/plugins/lens/public/indexpattern_datasource/time_scale.ts index 33395de389125..368e06110efc9 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/time_scale.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/time_scale.ts @@ -97,8 +97,8 @@ export function getTimeScaleFunction(data: DataPublicPluginStart) { } const targetUnitInMs = unitInMs[targetUnit]; - const timeInfo = await data.search.aggs.getDateMetaByDatatableColumn(dateColumnDefinition); - const intervalDuration = timeInfo && search.aggs.parseInterval(timeInfo.interval); + const timeInfo = search.aggs.getDateHistogramMetaDataByDatatableColumn(dateColumnDefinition); + const intervalDuration = timeInfo?.interval && search.aggs.parseInterval(timeInfo.interval); if (!timeInfo || !intervalDuration) { throw new Error( diff --git a/x-pack/plugins/lens/public/xy_visualization/expression.test.tsx b/x-pack/plugins/lens/public/xy_visualization/expression.test.tsx index c3ce391f4469d..2487ddf32cd1f 100644 --- a/x-pack/plugins/lens/public/xy_visualization/expression.test.tsx +++ b/x-pack/plugins/lens/public/xy_visualization/expression.test.tsx @@ -1894,10 +1894,14 @@ describe('xy_expression', () => { xyProps.args.layers[0].xScaleType = 'time'; }); it('should use first valid layer and determine interval', async () => { - const result = await calculateMinInterval( - xyProps, - jest.fn().mockResolvedValue({ interval: '5m' }) - ); + xyProps.data.tables.first.columns[2].meta.source = 'esaggs'; + xyProps.data.tables.first.columns[2].meta.sourceParams = { + type: 'date_histogram', + params: { + used_interval: '5m', + }, + }; + const result = await calculateMinInterval(xyProps); expect(result).toEqual(5 * 60 * 1000); }); @@ -1915,34 +1919,38 @@ describe('xy_expression', () => { }, }, }; - const result = await calculateMinInterval(xyProps, jest.fn().mockResolvedValue(undefined)); + const result = await calculateMinInterval(xyProps); expect(result).toEqual(5); }); it('should return undefined if data table is empty', async () => { xyProps.data.tables.first.rows = []; - const result = await calculateMinInterval( - xyProps, - jest.fn().mockResolvedValue({ interval: '5m' }) - ); + xyProps.data.tables.first.columns[2].meta.source = 'esaggs'; + xyProps.data.tables.first.columns[2].meta.sourceParams = { + type: 'date_histogram', + params: { + used_interval: '5m', + }, + }; + const result = await calculateMinInterval(xyProps); expect(result).toEqual(undefined); }); it('should return undefined if interval can not be checked', async () => { - const result = await calculateMinInterval(xyProps, jest.fn().mockResolvedValue(undefined)); + const result = await calculateMinInterval(xyProps); expect(result).toEqual(undefined); }); it('should return undefined if date column is not found', async () => { xyProps.data.tables.first.columns.splice(2, 1); - const result = await calculateMinInterval(xyProps, jest.fn().mockResolvedValue(undefined)); + const result = await calculateMinInterval(xyProps); expect(result).toEqual(undefined); }); it('should return undefined if x axis is not a date', async () => { xyProps.args.layers[0].xScaleType = 'ordinal'; xyProps.data.tables.first.columns.splice(2, 1); - const result = await calculateMinInterval(xyProps, jest.fn().mockResolvedValue(undefined)); + const result = await calculateMinInterval(xyProps); expect(result).toEqual(undefined); }); }); diff --git a/x-pack/plugins/lens/public/xy_visualization/expression.tsx b/x-pack/plugins/lens/public/xy_visualization/expression.tsx index 0bf5c139e2403..4dda44ad46d65 100644 --- a/x-pack/plugins/lens/public/xy_visualization/expression.tsx +++ b/x-pack/plugins/lens/public/xy_visualization/expression.tsx @@ -45,11 +45,7 @@ import { import { XYArgs, SeriesType, visualizationTypes, LayerArgs } from './types'; import { VisualizationContainer } from '../visualization_container'; import { isHorizontalChart, getSeriesColor } from './state_helpers'; -import { - DataPublicPluginStart, - ExpressionValueSearchContext, - search, -} from '../../../../../src/plugins/data/public'; +import { ExpressionValueSearchContext, search } from '../../../../../src/plugins/data/public'; import { ChartsPluginSetup, PaletteRegistry, @@ -192,10 +188,7 @@ export const xyChart: ExpressionFunctionDefinition< }, }; -export async function calculateMinInterval( - { args: { layers }, data }: XYChartProps, - getIntervalByColumn: DataPublicPluginStart['search']['aggs']['getDateMetaByDatatableColumn'] -) { +export async function calculateMinInterval({ args: { layers }, data }: XYChartProps) { const filteredLayers = getFilteredLayers(layers, data); if (filteredLayers.length === 0) return; const isTimeViz = data.dateRange && filteredLayers.every((l) => l.xScaleType === 'time'); @@ -212,9 +205,9 @@ export async function calculateMinInterval( return undefined; } } - const dateMetaData = await getIntervalByColumn(xColumn); - if (!dateMetaData) return; - const intervalDuration = search.aggs.parseInterval(dateMetaData.interval); + const dateInterval = search.aggs.getDateHistogramMetaDataByDatatableColumn(xColumn)?.interval; + if (!dateInterval) return; + const intervalDuration = search.aggs.parseInterval(dateInterval); if (!intervalDuration) return; return intervalDuration.as('milliseconds'); } @@ -223,7 +216,6 @@ export const getXyChartRenderer = (dependencies: { formatFactory: Promise; chartsThemeService: ChartsPluginSetup['theme']; paletteService: PaletteRegistry; - getIntervalByColumn: DataPublicPluginStart['search']['aggs']['getDateMetaByDatatableColumn']; timeZone: string; }): ExpressionRenderDefinition => ({ name: 'lens_xy_chart_renderer', @@ -254,7 +246,7 @@ export const getXyChartRenderer = (dependencies: { chartsThemeService={dependencies.chartsThemeService} paletteService={dependencies.paletteService} timeZone={dependencies.timeZone} - minInterval={await calculateMinInterval(config, dependencies.getIntervalByColumn)} + minInterval={await calculateMinInterval(config)} onClickValue={onClickValue} onSelectRange={onSelectRange} renderMode={handlers.getRenderMode()} diff --git a/x-pack/plugins/lens/public/xy_visualization/index.ts b/x-pack/plugins/lens/public/xy_visualization/index.ts index 1ca0bbb3f2da9..8650dedca0e2c 100644 --- a/x-pack/plugins/lens/public/xy_visualization/index.ts +++ b/x-pack/plugins/lens/public/xy_visualization/index.ts @@ -63,7 +63,6 @@ export class XyVisualization { chartsThemeService: charts.theme, paletteService: palettes, timeZone: getTimeZone(core.uiSettings), - getIntervalByColumn: data.search.aggs.getDateMetaByDatatableColumn, }) ); return getXyVisualization({ paletteService: palettes, data }); From e57838f250b5f9d80df53abcf252f2c274ec6f47 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Tue, 23 Mar 2021 18:16:01 +0100 Subject: [PATCH 2/5] adjust documentation --- .../data/common/search/aggs/utils/get_date_histogram_meta.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/data/common/search/aggs/utils/get_date_histogram_meta.ts b/src/plugins/data/common/search/aggs/utils/get_date_histogram_meta.ts index 86631c24f58ad..0a3aab6286d89 100644 --- a/src/plugins/data/common/search/aggs/utils/get_date_histogram_meta.ts +++ b/src/plugins/data/common/search/aggs/utils/get_date_histogram_meta.ts @@ -12,9 +12,9 @@ import type { AggParamsDateHistogram } from '../buckets'; import { BUCKET_TYPES } from '../buckets/bucket_agg_types'; /** - * Helper function returning the used interval for data table column created by the histogramm agg type. + * Helper function returning the used interval, used time zone and applied time filters for data table column created by the date_histogramm agg type. * "auto" will get expanded to the actually used interval. - * If the column is not a column created by a histogram aggregation of the esaggs data source, + * If the column is not a column created by a date_histogram aggregation of the esaggs data source, * this function will return undefined. */ export const getDateHistogramMetaDataByDatatableColumn = (column: DatatableColumn) => { From 385e488efc45f29a73d358edfad4124a7260550e Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 24 Mar 2021 09:34:10 +0100 Subject: [PATCH 3/5] update docs --- ...-data-public.aggconfig.fieldistimefield.md | 4 +- ...a-plugin-plugins-data-public.aggconfigs.md | 2 + ...ns-data-public.aggconfigs.settimefields.md | 22 +++++++++ ...ugins-data-public.aggconfigs.timefields.md | 11 +++++ ...ibana-plugin-plugins-data-public.search.md | 7 ++- ...ibana-plugin-plugins-data-server.search.md | 2 +- src/plugins/data/public/public.api.md | 45 +++++++++++-------- src/plugins/data/server/server.api.md | 2 +- 8 files changed, 72 insertions(+), 23 deletions(-) create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfigs.settimefields.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfigs.timefields.md diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfig.fieldistimefield.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfig.fieldistimefield.md index a1fde4dec25b1..6e7b753320270 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfig.fieldistimefield.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfig.fieldistimefield.md @@ -7,9 +7,9 @@ Signature: ```typescript -fieldIsTimeField(): boolean | "" | undefined; +fieldIsTimeField(): boolean; ``` Returns: -`boolean | "" | undefined` +`boolean` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfigs.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfigs.md index c0ba1bbeea334..22f8994747aa2 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfigs.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfigs.md @@ -23,6 +23,7 @@ export declare class AggConfigs | [aggs](./kibana-plugin-plugins-data-public.aggconfigs.aggs.md) | | IAggConfig[] | | | [createAggConfig](./kibana-plugin-plugins-data-public.aggconfigs.createaggconfig.md) | | <T extends AggConfig = AggConfig>(params: CreateAggConfigParams, { addToAggConfigs }?: {
addToAggConfigs?: boolean | undefined;
}) => T | | | [indexPattern](./kibana-plugin-plugins-data-public.aggconfigs.indexpattern.md) | | IndexPattern | | +| [timeFields](./kibana-plugin-plugins-data-public.aggconfigs.timefields.md) | | string[] | | | [timeRange](./kibana-plugin-plugins-data-public.aggconfigs.timerange.md) | | TimeRange | | ## Methods @@ -43,6 +44,7 @@ export declare class AggConfigs | [getResponseAggs()](./kibana-plugin-plugins-data-public.aggconfigs.getresponseaggs.md) | | Gets the AggConfigs (and possibly ResponseAggConfigs) that represent the values that will be produced when all aggs are run.With multi-value metric aggs it is possible for a single agg request to result in multiple agg values, which is why the length of a vis' responseValuesAggs may be different than the vis' aggs {array\[AggConfig\]} | | [jsonDataEquals(aggConfigs)](./kibana-plugin-plugins-data-public.aggconfigs.jsondataequals.md) | | Data-by-data comparison of this Aggregation Ignores the non-array indexes | | [onSearchRequestStart(searchSource, options)](./kibana-plugin-plugins-data-public.aggconfigs.onsearchrequeststart.md) | | | +| [setTimeFields(timeFields)](./kibana-plugin-plugins-data-public.aggconfigs.settimefields.md) | | | | [setTimeRange(timeRange)](./kibana-plugin-plugins-data-public.aggconfigs.settimerange.md) | | | | [toDsl(hierarchical)](./kibana-plugin-plugins-data-public.aggconfigs.todsl.md) | | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfigs.settimefields.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfigs.settimefields.md new file mode 100644 index 0000000000000..31eadc5756d3d --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfigs.settimefields.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [AggConfigs](./kibana-plugin-plugins-data-public.aggconfigs.md) > [setTimeFields](./kibana-plugin-plugins-data-public.aggconfigs.settimefields.md) + +## AggConfigs.setTimeFields() method + +Signature: + +```typescript +setTimeFields(timeFields: string[] | undefined): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| timeFields | string[] | undefined | | + +Returns: + +`void` + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfigs.timefields.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfigs.timefields.md new file mode 100644 index 0000000000000..903370fd8eb84 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.aggconfigs.timefields.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [AggConfigs](./kibana-plugin-plugins-data-public.aggconfigs.md) > [timeFields](./kibana-plugin-plugins-data-public.aggconfigs.timefields.md) + +## AggConfigs.timeFields property + +Signature: + +```typescript +timeFields?: string[]; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.search.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.search.md index 440fd25993d64..cfaad01c029ea 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.search.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.search.md @@ -14,7 +14,7 @@ search: { intervalOptions: ({ display: string; val: string; - enabled(agg: import("../common").IBucketAggConfig): boolean | "" | undefined; + enabled(agg: import("../common").IBucketAggConfig): boolean; } | { display: string; val: string; @@ -47,6 +47,11 @@ search: { intervalLabel: string; })[]; getNumberHistogramIntervalByDatatableColumn: (column: import("../../expressions").DatatableColumn) => number | undefined; + getDateHistogramMetaDataByDatatableColumn: (column: import("../../expressions").DatatableColumn) => { + interval: string | undefined; + timeZone: string | undefined; + timeRange: import("../common").TimeRange | undefined; + } | undefined; }; getRequestInspectorStats: typeof getRequestInspectorStats; getResponseInspectorStats: typeof getResponseInspectorStats; diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.search.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.search.md index 4f8a0beefa421..0911c3e86964d 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.search.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.search.md @@ -14,7 +14,7 @@ search: { intervalOptions: ({ display: string; val: string; - enabled(agg: import("../common").IBucketAggConfig): boolean | "" | undefined; + enabled(agg: import("../common").IBucketAggConfig): boolean; } | { display: string; val: string; diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index a61b8f400d285..58c08d602f776 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -133,7 +133,7 @@ export class AggConfig { enabled: boolean; static ensureIds(list: any[]): any[]; // (undocumented) - fieldIsTimeField(): boolean | "" | undefined; + fieldIsTimeField(): boolean; // (undocumented) fieldName(): any; // (undocumented) @@ -261,8 +261,12 @@ export class AggConfigs { // (undocumented) onSearchRequestStart(searchSource: ISearchSource_2, options?: ISearchOptions_2): Promise<[unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]>; // (undocumented) + setTimeFields(timeFields: string[] | undefined): void; + // (undocumented) setTimeRange(timeRange: TimeRange): void; // (undocumented) + timeFields?: string[]; + // (undocumented) timeRange?: TimeRange; // (undocumented) toDsl(hierarchical?: boolean): Record; @@ -2235,7 +2239,7 @@ export const search: { intervalOptions: ({ display: string; val: string; - enabled(agg: import("../common").IBucketAggConfig): boolean | "" | undefined; + enabled(agg: import("../common").IBucketAggConfig): boolean; } | { display: string; val: string; @@ -2268,6 +2272,11 @@ export const search: { intervalLabel: string; })[]; getNumberHistogramIntervalByDatatableColumn: (column: import("../../expressions").DatatableColumn) => number | undefined; + getDateHistogramMetaDataByDatatableColumn: (column: import("../../expressions").DatatableColumn) => { + interval: string | undefined; + timeZone: string | undefined; + timeRange: import("../common").TimeRange | undefined; + } | undefined; }; getRequestInspectorStats: typeof getRequestInspectorStats; getResponseInspectorStats: typeof getResponseInspectorStats; @@ -2649,7 +2658,7 @@ export const UI_SETTINGS: { // src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:65:5 - (ae-forgotten-export) The symbol "FormatFieldFn" needs to be exported by the entry point index.d.ts // src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:138:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts // src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:169:7 - (ae-forgotten-export) The symbol "RuntimeField" needs to be exported by the entry point index.d.ts -// src/plugins/data/common/search/aggs/types.ts:139:51 - (ae-forgotten-export) The symbol "AggTypesRegistryStart" needs to be exported by the entry point index.d.ts +// src/plugins/data/common/search/aggs/types.ts:125:51 - (ae-forgotten-export) The symbol "AggTypesRegistryStart" needs to be exported by the entry point index.d.ts // src/plugins/data/public/field_formats/field_formats_service.ts:56:3 - (ae-forgotten-export) The symbol "FormatFactory" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:56:23 - (ae-forgotten-export) The symbol "FILTERS" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:56:23 - (ae-forgotten-export) The symbol "getDisplayValueFromFilter" needs to be exported by the entry point index.d.ts @@ -2683,21 +2692,21 @@ export const UI_SETTINGS: { // src/plugins/data/public/index.ts:238:27 - (ae-forgotten-export) The symbol "validateIndexPattern" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:238:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:238:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:403:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:403:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:403:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:403:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:405:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:406:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:415:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:416:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:417:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:418:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:422:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:423:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:426:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:427:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:430:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:404:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:404:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:404:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:404:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:406:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:407:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:416:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:417:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:418:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:419:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:423:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:424:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:427:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:428:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:431:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // src/plugins/data/public/query/state_sync/connect_to_query_state.ts:34:5 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts // src/plugins/data/public/search/session/session_service.ts:55:5 - (ae-forgotten-export) The symbol "UrlGeneratorStateMapping" needs to be exported by the entry point index.d.ts diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index 83f7c67eba057..772204af37ecc 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -1297,7 +1297,7 @@ export const search: { intervalOptions: ({ display: string; val: string; - enabled(agg: import("../common").IBucketAggConfig): boolean | "" | undefined; + enabled(agg: import("../common").IBucketAggConfig): boolean; } | { display: string; val: string; From fe846c3e6dca921546051c78826d2e55e5b11826 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 24 Mar 2021 10:34:40 +0100 Subject: [PATCH 4/5] fix error case --- src/plugins/data/common/search/aggs/buckets/date_histogram.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/data/common/search/aggs/buckets/date_histogram.ts b/src/plugins/data/common/search/aggs/buckets/date_histogram.ts index 4fa4d4f213ca2..4a83ae38d34db 100644 --- a/src/plugins/data/common/search/aggs/buckets/date_histogram.ts +++ b/src/plugins/data/common/search/aggs/buckets/date_histogram.ts @@ -231,7 +231,6 @@ export const getDateHistogramBucketAgg = ({ write: () => {}, serialize(val, agg) { if (!agg) return undefined; - updateTimeBuckets(agg, calculateBounds); const { useNormalizedEsInterval } = agg.params; const interval = agg.buckets.getInterval(useNormalizedEsInterval); return interval.expression; From 563f42c4fdafc0804515a91f00051a2ad963f7b0 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Sat, 27 Mar 2021 15:29:26 +0100 Subject: [PATCH 5/5] fix tests --- .../apply_aggs_to_search_source.test.ts | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/plugins/discover/public/application/components/histogram/apply_aggs_to_search_source.test.ts b/src/plugins/discover/public/application/components/histogram/apply_aggs_to_search_source.test.ts index 29c93886ebba3..5d2be533065e7 100644 --- a/src/plugins/discover/public/application/components/histogram/apply_aggs_to_search_source.test.ts +++ b/src/plugins/discover/public/application/components/histogram/apply_aggs_to_search_source.test.ts @@ -24,45 +24,46 @@ describe('applyAggsToSearchSource', () => { const aggsConfig = applyAggsToSearchSource(true, searchSource, 'auto', indexPattern, dataMock); expect(aggsConfig!.aggs).toMatchInlineSnapshot(` - Array [ - Object { - "enabled": true, - "id": "1", - "params": Object {}, - "schema": "metric", - "type": "count", - }, - Object { - "enabled": true, - "id": "2", - "params": Object { - "drop_partials": false, - "extended_bounds": Object {}, - "field": "timestamp", - "interval": "auto", - "min_doc_count": 1, - "scaleMetricValues": false, - "useNormalizedEsInterval": true, + Array [ + Object { + "enabled": true, + "id": "1", + "params": Object {}, + "schema": "metric", + "type": "count", }, - "schema": "segment", - "type": "date_histogram", - }, - ] - `); + Object { + "enabled": true, + "id": "2", + "params": Object { + "drop_partials": false, + "extended_bounds": Object {}, + "field": "timestamp", + "interval": "auto", + "min_doc_count": 1, + "scaleMetricValues": false, + "useNormalizedEsInterval": true, + "used_interval": "0ms", + }, + "schema": "segment", + "type": "date_histogram", + }, + ] + `); expect(setField).toHaveBeenCalledWith('aggs', expect.any(Function)); const dslFn = setField.mock.calls[0][1]; expect(dslFn()).toMatchInlineSnapshot(` - Object { - "2": Object { - "date_histogram": Object { - "field": "timestamp", - "min_doc_count": 1, - "time_zone": "America/New_York", - }, - }, - } - `); + Object { + "2": Object { + "date_histogram": Object { + "field": "timestamp", + "min_doc_count": 1, + "time_zone": "America/New_York", + }, + }, + } + `); }); test('enabled = false', () => {