-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 visualization individual timeranges #17123
Changes from all commits
bae4f14
2661482
e59c43e
105c1cd
877a7e3
78289cd
7a579b9
edd5482
28291a0
ba9a882
0e3b5f1
5b65c91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ | |
app-state="state" | ||
editor-mode="chrome.getVisible()" | ||
show-spy-panel="chrome.getVisible()" | ||
time-range="timeRange" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass down the timeRange explicitly from the editor app. |
||
> | ||
|
||
</visualize> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,25 +8,25 @@ const MetricsRequestHandlerProvider = function (Private, Notifier, config, timef | |
|
||
return { | ||
name: 'metrics', | ||
handler: function (vis, appState, uiState) { | ||
handler: function (vis, { uiState, timeRange }) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make TSVB request handler only use the passed timeRange and not looking into timefilter directly anymore. |
||
const timezone = Private(timezoneProvider)(); | ||
return new Promise((resolve) => { | ||
const panel = vis.params; | ||
const uiStateObj = uiState.get(panel.type, {}); | ||
const timeRange = vis.params.timeRange || timefilter.getBounds(); | ||
const parsedTimeRange = timefilter.calculateBounds(timeRange); | ||
const scaledDataFormat = config.get('dateFormat:scaled'); | ||
const dateFormat = config.get('dateFormat'); | ||
if (panel && panel.id) { | ||
const params = { | ||
timerange: { timezone, ...timeRange }, | ||
timerange: { timezone, ...parsedTimeRange }, | ||
filters: [dashboardContext()], | ||
panels: [panel], | ||
state: uiStateObj | ||
}; | ||
|
||
try { | ||
const maxBuckets = config.get('metrics:max_buckets'); | ||
validateInterval(timeRange, panel, maxBuckets); | ||
validateInterval(parsedTimeRange, panel, maxBuckets); | ||
const httpResult = $http.post('../api/metrics/vis/data', params) | ||
.then(resp => ({ dateFormat, scaledDataFormat, timezone, ...resp.data })) | ||
.catch(resp => { throw resp.data; }); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import _ from 'lodash'; | |
import { dashboardContextProvider } from 'plugins/kibana/dashboard/dashboard_context'; | ||
|
||
import { timezoneProvider } from 'ui/vis/lib/timezone'; | ||
const TimelionRequestHandlerProvider = function (Private, Notifier, $http, $rootScope, timefilter) { | ||
const TimelionRequestHandlerProvider = function (Private, Notifier, $http) { | ||
const timezone = Private(timezoneProvider)(); | ||
const dashboardContext = Private(dashboardContextProvider); | ||
|
||
|
@@ -12,28 +12,20 @@ const TimelionRequestHandlerProvider = function (Private, Notifier, $http, $root | |
|
||
return { | ||
name: 'timelion', | ||
handler: function (vis /*, appState, uiState, queryFilter*/) { | ||
handler: function (vis, { timeRange }) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make timelion request handler only use the explicitly passed |
||
|
||
return new Promise((resolve, reject) => { | ||
const expression = vis.params.expression; | ||
if (!expression) return; | ||
|
||
let timeFilter = timefilter.time; | ||
if (vis.params.timeRange) { | ||
timeFilter = { | ||
mode: 'absolute', | ||
from: vis.params.timeRange.min.toJSON(), | ||
to: vis.params.timeRange.max.toJSON() | ||
}; | ||
} | ||
const httpResult = $http.post('../api/timelion/run', { | ||
sheet: [expression], | ||
extended: { | ||
es: { | ||
filter: dashboardContext() | ||
} | ||
}, | ||
time: _.extend(timeFilter, { | ||
time: _.extend(timeRange, { | ||
interval: vis.params.interval, | ||
timezone: timezone | ||
}), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ export function VegaRequestHandlerProvider(Private, es, timefilter, serviceSetti | |
|
||
name: 'vega', | ||
|
||
handler(vis) { | ||
handler(vis, { timeRange }) { | ||
timeCache.setTimeRange(timeRange); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass in the |
||
const vp = new VegaParser(vis.params.spec, searchCache, timeCache, dashboardContext, serviceSettings); | ||
return vp.parseAsync(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,46 @@ import { VisRequestHandlersRegistryProvider } from 'ui/registry/vis_request_hand | |
const CourierRequestHandlerProvider = function (Private, courier, timefilter) { | ||
const SearchSource = Private(SearchSourceProvider); | ||
|
||
/** | ||
* TODO: This code can be removed as soon as we got rid of inheritance in the | ||
* searchsource and pass down every filter explicitly. | ||
* we're only adding one range filter against the timeFieldName to ensure | ||
* that our filter is the only one applied and override the global filters. | ||
* this does rely on the "implementation detail" that filters are added first | ||
* on the leaf SearchSource and subsequently on the parents. | ||
*/ | ||
function removeSearchSourceParentTimefilter(searchSource) { | ||
searchSource.addFilterPredicate((filter, state) => { | ||
if (!filter.range) { | ||
return true; | ||
} | ||
|
||
const index = searchSource.index() || searchSource.getParent().index(); | ||
const timeFieldName = index.timeFieldName; | ||
if (!timeFieldName) { | ||
return true; | ||
} | ||
|
||
// Only check if we need to filter out this filter if it's actual a range filter | ||
// on our time field and not any other field. | ||
if (!filter.range[timeFieldName]) { | ||
return true; | ||
} | ||
|
||
return !(state.filters || []).find(f => f.range && f.range[timeFieldName]); | ||
}); | ||
|
||
} | ||
|
||
return { | ||
name: 'courier', | ||
handler: function (vis, appState, uiState, queryFilter, searchSource) { | ||
handler: function (vis, { appState, queryFilter, searchSource, timeRange }) { | ||
|
||
searchSource.filter(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move applying the In the long run we want to remove |
||
return timefilter.get(searchSource.index(), timeRange); | ||
}); | ||
|
||
removeSearchSourceParentTimefilter(searchSource, timeRange); | ||
|
||
if (queryFilter && vis.editorMode) { | ||
searchSource.set('filter', queryFilter.getFilters()); | ||
|
@@ -31,7 +67,7 @@ const CourierRequestHandlerProvider = function (Private, courier, timefilter) { | |
if (!_.isEqual(_.cloneDeep(searchSource.get('filter')), searchSource.lastQuery.filter)) return true; | ||
if (!_.isEqual(_.cloneDeep(searchSource.get('query')), searchSource.lastQuery.query)) return true; | ||
if (!_.isEqual(_.cloneDeep(copyAggs(vis.aggs)), searchSource.lastQuery.aggs)) return true; | ||
if (!_.isEqual(_.cloneDeep(timefilter.time), searchSource.lastQuery.time)) return true; | ||
if (!_.isEqual(_.cloneDeep(timeRange), searchSource.lastQuery.timeRange)) return true; | ||
|
||
return false; | ||
}; | ||
|
@@ -44,7 +80,7 @@ const CourierRequestHandlerProvider = function (Private, courier, timefilter) { | |
filter: _.cloneDeep(searchSource.get('filter')), | ||
query: _.cloneDeep(searchSource.get('query')), | ||
aggs: _.cloneDeep(copyAggs(vis.aggs)), | ||
time: _.cloneDeep(timefilter.time) | ||
timeRange: _.cloneDeep(timeRange) | ||
}; | ||
|
||
searchSource.rawResponse = resp; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the date histogram in the chart looks into this variable expected to be set by
visualize.js
we need to set it explicitly in the places we use<visualization>
directly. This is currently only discover. I think in the long run with the new chart component in EUI we should rather use the chart component directly and not any part of the visualize stack anymore in Discover, since discover and visualize already have a ton of special handling just for this one chart.