diff --git a/src/core_plugins/metrics/public/kbn_vis_types/request_handler.js b/src/core_plugins/metrics/public/kbn_vis_types/request_handler.js index 839b79c56fcf1..522e73fb15322 100644 --- a/src/core_plugins/metrics/public/kbn_vis_types/request_handler.js +++ b/src/core_plugins/metrics/public/kbn_vis_types/request_handler.js @@ -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); @@ -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] }; diff --git a/src/core_plugins/metrics/server/lib/vis_data/__tests__/build_request_body.js b/src/core_plugins/metrics/server/lib/vis_data/__tests__/build_request_body.js index 93b6802b509ac..4d8d93e96bba5 100644 --- a/src/core_plugins/metrics/server/lib/vis_data/__tests__/build_request_body.js +++ b/src/core_plugins/metrics/server/lib/vis_data/__tests__/build_request_body.js @@ -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" } @@ -104,6 +105,7 @@ describe('buildRequestBody(req)', () => { 'field': '@timestamp', 'interval': '10s', 'min_doc_count': 0, + 'time_zone': 'UTC', 'extended_bounds': { 'min': 1485463055881, 'max': 1485463955881 diff --git a/src/core_plugins/metrics/server/lib/vis_data/request_processors/annotations/date_histogram.js b/src/core_plugins/metrics/server/lib/vis_data/request_processors/annotations/date_histogram.js index 08d51dc05ca7a..f64ab9ad5fbab 100644 --- a/src/core_plugins/metrics/server/lib/vis_data/request_processors/annotations/date_histogram.js +++ b/src/core_plugins/metrics/server/lib/vis_data/request_processors/annotations/date_histogram.js @@ -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) diff --git a/src/core_plugins/metrics/server/lib/vis_data/request_processors/series/__tests__/date_histogram.js b/src/core_plugins/metrics/server/lib/vis_data/request_processors/series/__tests__/date_histogram.js index f14f649d4b715..cb0046f6e7ed2 100644 --- a/src/core_plugins/metrics/server/lib/vis_data/request_processors/series/__tests__/date_histogram.js +++ b/src/core_plugins/metrics/server/lib/vis_data/request_processors/series/__tests__/date_histogram.js @@ -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' } @@ -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 @@ -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 @@ -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 diff --git a/src/core_plugins/metrics/server/lib/vis_data/request_processors/series/date_histogram.js b/src/core_plugins/metrics/server/lib/vis_data/request_processors/series/date_histogram.js index 2dcac4ce0942f..fcbb07a6f2736 100644 --- a/src/core_plugins/metrics/server/lib/vis_data/request_processors/series/date_histogram.js +++ b/src/core_plugins/metrics/server/lib/vis_data/request_processors/series/date_histogram.js @@ -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()