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

Scale histogram aggregation interval to avoid crashing browser #14157

Merged
merged 7 commits into from Oct 24, 2017

Conversation

nreese
Copy link
Contributor

@nreese nreese commented Sep 25, 2017

Fixes #2908

@spalger's PR added the infrastructure required for aggregations to perform pre-flight requests before getting serialized. This PR uses onRequestStart to fetch the min/max before serializing the histogram aggregation. That way, the interval can be scaled to ensure that a proper value is provided to avoid creating a gazillion buckets and crashing the browser.

}
},

{
name: 'max',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use a less generic param name, maybe combine min/max to autoBounds: { min/max }?

Interval
<kbn-info
placement="right"
info="Interval will be automatically scaled in the event that the provided internval creates more buckets than specified by Advanced Setting's 'histogram:maxBars'">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo - internval

@thomasneirynck thomasneirynck added Feature:Visualizations Generic visualization features (in case no more specific feature label is available) Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc and removed v6.0.0 labels Sep 28, 2017
Copy link
Contributor

@thomasneirynck thomasneirynck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is going to make a lot of people happy, awesome!

I have mostly minor comments to improve understanding and navigability of the new methods. The onStart-hook makes a lot of sense, but I'd tighten the method signatures a little bit more explicitly.

I would also add a selenium test for this, create a bar chart or something with a very small interval. e.g. add a test-case here: https://github.com/thomasneirynck/kibana/blob/b278ad96a9c0d4e9e0fcf91efb878884d1401fff/test/functional/apps/visualize/_vertical_bar_chart.js#L112-L112

@@ -0,0 +1,19 @@
<div class="form-group">
<label for="visEditorInterval{{agg.id}}">
Interval
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rename now to "Minimum Interval"

// ensure interval does not create too many buckets and crash browser
if (aggConfig.autoBounds) {
const range = aggConfig.autoBounds.max - aggConfig.autoBounds.min;
const bars = range / interval;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd check if interval is 0. Through the magic of JS bars is either going to be NaN or Infinity depending on the nominator, so I'd just avoid this altogether.

An option too is modify the number_interval, to disallow 0 input for the agg.params.interval value.

*
* @returns {Promise<undefined>|undefined}
*/
BaseParamType.prototype.onSearchRequestStart = function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I'd have this return a dummy resolved Promise iso undefined.

  • I'd make the function signature also more explicit

BaseParamType.prototype.onSearchRequestStart = async function (aggconfig, searchSource, searchRequest) {
  • Given this is a side-effect function, consider renaming as modifyAggConfigOnSearchRequestStart. This rename would also to distinguish it from AggConfig#onsearchRequestStart(searchSource,SearchRequest)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the method name and added @param comments about the arguments but I could not put the arguments in the method definition since BaseParamType#modifyAggConfigOnSearchRequestStart does not use the arguments and eslint is not happy about unused arguments

self.type && self.type.params.forEach(function (param) {
if (param.onRequest) param.onRequest(self);
});
AggConfig.prototype.onSearchRequestStart = function (...args) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't use the varargs and just call them what they are:
AggConfig.prototype.onSearchRequestStart = function (searchSource, searchRequest) { ...

})
.fetchAsRejectablePromise()
.then((resp) => {
aggConfig.autoBounds = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do this stuff quite a bit in Kibana, and side-effects when well managed are very useful, but I'd consider making this explicit with a getter/setter on AggConfig. It will help jumping around in the code.

So I'd add something like:
AggConfig.prototype.setAutoBounds(autoBounds) and AggConfig.prototype.getAutoBounds().

This would be similar to https://github.com/thomasneirynck/kibana/blob/1423d068f8d4d38e5c0f2087482e4a9155e77a28/src/ui/public/time_buckets/time_buckets.js#L44-L44, which I find a little more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the getters/setter methods really be added to AggConfig since most other configs will never need autoBounds? Autobounds is added to AggConfig as a decoration https://github.com/nreese/kibana/blob/hist_pre_flight/src/ui/public/agg_types/buckets/histogram.js#L22.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should go on the aggConfig at all, but should go on aggConfig.params. That's what the params object is for, and adding a getter/setter to a general class like AggConfig doesn't really make sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I guess you could just update your decorateAggConfig function with getAutoBounds() and setAutoBounds()...

@nreese
Copy link
Contributor Author

nreese commented Sep 28, 2017

@thomasneirynck The PR contains a selenium test. Is another needed?

@thomasneirynck
Copy link
Contributor

@nreese ok, shame on me, I completely missed https://github.com/elastic/kibana/pull/14157/files#diff-492637ba8caab7b809370b55eecad4e1. no, that's good, sorry for run around.

@nreese
Copy link
Contributor Author

nreese commented Sep 29, 2017

@thomasneirynck Everything has been addressed and should be ready for another look

@nreese
Copy link
Contributor Author

nreese commented Sep 29, 2017

jenkins, test this

@thomasneirynck thomasneirynck self-requested a review October 5, 2017 16:59
Copy link
Contributor

@thomasneirynck thomasneirynck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 👨‍🚒

great, thx!

@nreese nreese force-pushed the hist_pre_flight branch 2 times, most recently from 2e56fa1 to 2d76f03 Compare October 23, 2017 11:42
@nreese
Copy link
Contributor Author

nreese commented Oct 23, 2017

Failed test caused by #14503. Trying again

Jenkins, test this

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! LGTM

@nreese nreese merged commit 88f3af4 into elastic:master Oct 24, 2017
nreese added a commit to nreese/kibana that referenced this pull request Oct 24, 2017
…ic#14157)

* update histogram agg to fetch min and max when search request started

* scale interval when too many buckets are created

* move min and max params into autoBounds param, remove typo in help text

* use decorated property instead of params to avoid changing agg state, add functional test

* remove sleep from functional test

* make args for onSearchRequest functions specific. Add getters and setters for autoBounds to AggConfig. Protect against divide by zero

* add unused arguments with eslint comment
nreese added a commit to nreese/kibana that referenced this pull request Oct 24, 2017
…ic#14157)

* update histogram agg to fetch min and max when search request started

* scale interval when too many buckets are created

* move min and max params into autoBounds param, remove typo in help text

* use decorated property instead of params to avoid changing agg state, add functional test

* remove sleep from functional test

* make args for onSearchRequest functions specific. Add getters and setters for autoBounds to AggConfig. Protect against divide by zero

* add unused arguments with eslint comment
nreese added a commit that referenced this pull request Oct 25, 2017
… (#14531)

* update histogram agg to fetch min and max when search request started

* scale interval when too many buckets are created

* move min and max params into autoBounds param, remove typo in help text

* use decorated property instead of params to avoid changing agg state, add functional test

* remove sleep from functional test

* make args for onSearchRequest functions specific. Add getters and setters for autoBounds to AggConfig. Protect against divide by zero

* add unused arguments with eslint comment
chrisronline pushed a commit to chrisronline/kibana that referenced this pull request Nov 20, 2017
…ic#14157)

* update histogram agg to fetch min and max when search request started

* scale interval when too many buckets are created

* move min and max params into autoBounds param, remove typo in help text

* use decorated property instead of params to avoid changing agg state, add functional test

* remove sleep from functional test

* make args for onSearchRequest functions specific. Add getters and setters for autoBounds to AggConfig. Protect against divide by zero

* add unused arguments with eslint comment
chrisronline pushed a commit to chrisronline/kibana that referenced this pull request Dec 1, 2017
…ic#14157)

* update histogram agg to fetch min and max when search request started

* scale interval when too many buckets are created

* move min and max params into autoBounds param, remove typo in help text

* use decorated property instead of params to avoid changing agg state, add functional test

* remove sleep from functional test

* make args for onSearchRequest functions specific. Add getters and setters for autoBounds to AggConfig. Protect against divide by zero

* add unused arguments with eslint comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Visualizations Generic visualization features (in case no more specific feature label is available) release_note:fix Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v6.1.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants