Skip to content

Commit

Permalink
Fixes #12113 - Add timezone to date histogram aggregations for TSVB (#…
Browse files Browse the repository at this point in the history
…13378)

* Fixes #12113 - Add timezone to date histogram aggregations

* Fixing tests

* Fixing tests

* Moving to universal timezone function
  • Loading branch information
simianhacker committed Aug 14, 2017
1 parent 4578501 commit ab66d4a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { validateInterval } from '../lib/validate_interval';
import { dashboardContextProvider } from 'plugins/kibana/dashboard/dashboard_context';
import { timezoneProvider } from 'ui/vis/lib/timezone';

const MetricsRequestHandlerProvider = function (Private, Notifier, config, timefilter, $http) {
const dashboardContext = Private(dashboardContextProvider);
Expand All @@ -8,12 +9,13 @@ const MetricsRequestHandlerProvider = function (Private, Notifier, config, timef
return {
name: 'metrics',
handler: function (vis /*, appState, uiState, queryFilter*/) {
const timezone = Private(timezoneProvider)();

return new Promise((resolve) => {
const panel = vis.params;
if (panel && panel.id) {
const params = {
timerange: timefilter.getBounds(),
timerange: { timezone, ...timefilter.getBounds() },
filters: [dashboardContext()],
panels: [panel]
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const body = JSON.parse(`
}
],
"timerange": {
"timezone": "UTC",
"max": "2017-01-26T20:52:35.881Z",
"min": "2017-01-26T20:37:35.881Z"
}
Expand Down Expand Up @@ -104,6 +105,7 @@ describe('buildRequestBody(req)', () => {
'field': '@timestamp',
'interval': '10s',
'min_doc_count': 0,
'time_zone': 'UTC',
'extended_bounds': {
'min': 1485463055881,
'max': 1485463955881
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ export default function dateHistogram(req, panel, annotation) {
const timeField = annotation.time_field;
const { bucketSize, intervalString } = getBucketSize(req, 'auto');
const { from, to } = getTimerange(req);
const { timezone:time_zone } = req.payload.timerange;
_.set(doc, `aggs.${annotation.id}.date_histogram`, {
field: timeField,
interval: intervalString,
min_doc_count: 0,
time_zone,
extended_bounds: {
min: from.valueOf(),
max: to.valueOf() - (bucketSize * 1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('dateHistogram(req, panel, series)', () => {
req = {
payload: {
timerange: {
timezone: 'UTC',
min: '2017-01-01T00:00:00Z',
max: '2017-01-01T01:00:00Z'
}
Expand Down Expand Up @@ -42,6 +43,7 @@ describe('dateHistogram(req, panel, series)', () => {
field: '@timestamp',
interval: '10s',
min_doc_count: 0,
time_zone: 'UTC',
extended_bounds: {
min: 1483228800000,
max: 1483232400000
Expand All @@ -67,6 +69,7 @@ describe('dateHistogram(req, panel, series)', () => {
field: '@timestamp',
interval: '10s',
min_doc_count: 0,
time_zone: 'UTC',
extended_bounds: {
min: 1483225200000,
max: 1483228800000
Expand Down Expand Up @@ -95,6 +98,7 @@ describe('dateHistogram(req, panel, series)', () => {
field: 'timestamp',
interval: '20s',
min_doc_count: 0,
time_zone: 'UTC',
extended_bounds: {
min: 1483228800000,
max: 1483232400000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export default function dateHistogram(req, panel, series) {
const { timeField, interval } = getIntervalAndTimefield(panel, series);
const { intervalString } = getBucketSize(req, interval);
const { from, to } = offsetTime(req, series.offset_time);
const { timezone:time_zone } = req.payload.timerange;

set(doc, `aggs.${series.id}.aggs.timeseries.date_histogram`, {
field: timeField,
interval: intervalString,
min_doc_count: 0,
time_zone,
extended_bounds: {
min: from.valueOf(),
max: to.valueOf()
Expand Down

0 comments on commit ab66d4a

Please sign in to comment.