Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix date histogram time zone for rollup index #90632

Merged
merged 6 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import moment from 'moment-timezone';
import { i18n } from '@kbn/i18n';

import { KBN_FIELD_TYPES, TimeRange, TimeRangeBounds, UI_SETTINGS } from '../../../../common';
import { IFieldType } from '../../../index_patterns';

import { intervalOptions, autoInterval, isAutoInterval } from './_interval_options';
import { createFilterDateHistogram } from './create_filter/date_histogram';
Expand Down Expand Up @@ -58,7 +59,7 @@ export function isDateHistogramBucketAggConfig(agg: any): agg is IBucketDateHist
}

export interface AggParamsDateHistogram extends BaseAggParams {
field?: string;
field?: IFieldType | string;
timeRange?: TimeRange;
useNormalizedEsInterval?: boolean;
scaleMetricValues?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jest.mock('moment', () => {
return moment;
});

import { IndexPattern } from '../../../index_patterns';
import { IndexPattern, IndexPatternField } from '../../../index_patterns';
import { AggParamsDateHistogram } from '../buckets';
import { inferTimeZone } from './infer_time_zone';

Expand Down Expand Up @@ -51,6 +51,31 @@ describe('inferTimeZone', () => {
).toEqual('UTC');
});

it('reads time zone from index pattern type meta if available when the field is not a string', () => {
expect(
inferTimeZone(
{
field: {
name: 'mydatefield',
} as IndexPatternField,
},
({
typeMeta: {
aggs: {
date_histogram: {
mydatefield: {
time_zone: 'UTC',
},
},
},
},
} as unknown) as IndexPattern,
() => false,
jest.fn()
)
).toEqual('UTC');
});

it('reads time zone from moment if set to default', () => {
expect(inferTimeZone({}, {} as IndexPattern, () => true, jest.fn())).toEqual('CET');
});
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/common/search/aggs/utils/infer_time_zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function inferTimeZone(
if (!tz && params.field) {
// If a field has been configured check the index pattern's typeMeta if a date_histogram on that
// field requires a specific time_zone
tz = indexPattern.typeMeta?.aggs?.date_histogram?.[params.field]?.time_zone;
const fieldName = typeof params.field === 'string' ? params.field : params.field.name;
tz = indexPattern.typeMeta?.aggs?.date_histogram?.[fieldName]?.time_zone;
}
if (!tz) {
// If the index pattern typeMeta data, didn't had a time zone assigned for the selected field use the configured tz
Expand Down