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

[Lens] Remove Over time suggestions for numeric intervals #78442

Merged
merged 19 commits into from
Oct 19, 2020

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Sep 24, 2020

Summary

Current state

After some discussion there wasn't a clear consensus on the value of having a Over time suggestion for numeric histograms type of charts.

Therefore the current state is to detect this scenario and avoid to push a Over time suggestion for it.


Previous state

The aim of this PR is to improve the suggestion system for histograms not date-based, providing better Over time suggestions.
This is the continuation of #76121 .

The current state of suggestions for the Over time option is to add a new interval date dimension to the break down section of the panel, keeping other dimensions on their place.

intervals-overtime-before-change-accessors

This PR makes a distinction between interval type operations, making the suggestion system aware of the data type, pushing for a swap of the x and splitBy dimensions to propose a date histogram based chart:

intervals-overtime-to-change-accessors

This is a first attempt with it: so far I couldn't find another route than the dataType to detect the different type of intervals.

Checklist

@dej611 dej611 added Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 v7.10.0 labels Sep 24, 2020
@dej611 dej611 requested a review from wylieconlon September 24, 2020 15:52
@dej611 dej611 self-assigned this Sep 24, 2020
@wylieconlon
Copy link
Contributor

@dej611 I'm interested in coming up with a solution that doesn't involve the XY chart at all. Could you take a look at the logic in indexpattern_suggestions.ts? Maybe you can avoid adding the date histogram when there is already a number histogram.

@dej611
Copy link
Contributor Author

dej611 commented Oct 8, 2020

Reworked the logic to tune the data table at indexpattern_suggestions.ts level. It's probably not super clean (it relies on some combination of parameters not documented) but it works.

@dej611
Copy link
Contributor Author

dej611 commented Oct 8, 2020

@elasticmachine merge upstream

@wylieconlon
Copy link
Contributor

@dej611 This is looking closer, but it seems like this is still generating suggestions to insert the time field in cases where inserting the time field is not helpful. What do you think about my previous comment:

Maybe you can avoid adding the date histogram when there is already a number histogram?

@dej611
Copy link
Contributor Author

dej611 commented Oct 13, 2020

Talked offline, not sure to find a consensus on what it should show in this scenario.
So as for now I'll just remove the Over time suggestion in this particular scenario: note it applies only to the basic Interval mode, not the Custom intervals mode.

@dej611 dej611 changed the title [Lens] Improve suggestion quality for numeric intervals [Lens] Remove Over time suggestions for numeric intervals Oct 13, 2020
@dej611
Copy link
Contributor Author

dej611 commented Oct 13, 2020

@elasticmachine merge upstream

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

I tested this out locally and it did what I expected, but also seems to do other unrelated things. Can you clarify the parts that are directly related here?

@@ -455,6 +455,10 @@ export function getDatasourceSuggestionsFromCurrentState(
({ name }) => name === indexPattern.timeFieldName
);

const hasNumericDimension =
buckets.length === 1 &&
buckets.some((columnId) => layer.columns[columnId].dataType === 'number');
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of looking for numeric operations, which can include the number range aggregation too, could you filter for any existing column.scale === 'interval'? This should allow the timestamp to be added when it's a "Custom ranges" option, which is currently not added.

@@ -1381,6 +1381,51 @@ describe('IndexPattern Data Source suggestions', () => {
);
});

it('does not create an over time suggestion if tables with numeric buckets with time dimension', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add a test when the aggregation is the "Custom ranges" mode?

@@ -665,7 +677,7 @@ function createSuggestionWithDefaultDateHistogram(
label: i18n.translate('xpack.lens.indexpattern.suggestions.overTimeLabel', {
defaultMessage: 'Over time',
}),
changeType: 'extended',
changeType: shouldSwitchTimeWithBuckets ? 'reorder' : 'extended',
Copy link
Contributor

Choose a reason for hiding this comment

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

This suggestion should always be extended because it should always add a new column. Calling it a reorder will affect how the XY charts use the suggestion, which I don't think is intentional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. All the code in this function needs to be removed as it was shaped to make it work the initial way.

@@ -117,8 +117,6 @@ function flipSeriesType(seriesType: SeriesType) {
return 'bar_stacked';
case 'bar':
return 'bar_horizontal';
case 'bar_horizontal_stacked':
return 'bar_stacked';
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't look right to me, why was this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a duplicate. At line 116 there's exactly the same case.

columnOrder: shouldSwitchTimeWithBuckets
? // in this case the order is very important to assign the split accessor!
[newId, ...buckets, ...metrics]
: [...buckets, newId, ...metrics],
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary? If so, can you please write a test for it?

@dej611
Copy link
Contributor Author

dej611 commented Oct 16, 2020

@elasticmachine merge upstream

@dej611 dej611 marked this pull request as ready for review October 16, 2020 10:47
@dej611 dej611 requested a review from a team October 16, 2020 10:47
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

Tested and LGTM!

@dej611
Copy link
Contributor Author

dej611 commented Oct 19, 2020

@elasticmachine merge upstream

@dej611 dej611 added v7.11.0 and removed v7.10.0 labels Oct 19, 2020
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

async chunks size

id before after diff
lens 1.0MB 1.0MB +104.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@dej611 dej611 merged commit 7b1b36e into elastic:master Oct 19, 2020
@dej611 dej611 deleted the feature/lens/intervals-suggestions branch October 19, 2020 12:45
dej611 added a commit to dej611/kibana that referenced this pull request Oct 20, 2020
)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
dej611 added a commit to dej611/kibana that referenced this pull request Oct 20, 2020
)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
dej611 added a commit that referenced this pull request Oct 20, 2020
) (#81118)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
dej611 added a commit that referenced this pull request Oct 20, 2020
…) (#81117)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@wylieconlon wylieconlon added release_note:skip Skip the PR/issue when compiling release notes and removed release_note:fix labels Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.10.0 v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants