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

[Discover] Fix csv export with relative time filter from discover main view #123206

Merged
merged 21 commits into from
Mar 16, 2022

Conversation

dimaanj
Copy link
Contributor

@dimaanj dimaanj commented Jan 18, 2022

Summary

Fixes #122575

This PR redundant absolute filter from csv export generated from discover main view.

Test notes

  • Create an index pattern which contains data during the last N days.
  • Choose Last 24h in the timepicker (note the URL contains only (filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-24h%2Fh,to:now))&_a=(columns:!(),filters:!(),index:'10881820-3b02-11eb-a646-7340c405390d',interval:auto,query:(language:kuery,query:''),sort:!(!(timestamp,desc))))
  • Save the Saved Search - The URL still shows (filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-24h%2Fh,to:now))&_a=(columns:!(),filters:!(),grid:(),hideChart:!f,index:'10881820-3b02-11eb-a646-7340c405390d',interval:auto,query:(language:kuery,query:''),sort:!(!(timestamp,desc)))
  • Go on Share / CSV Export / Copy POST URL
  • Decode URL
  • Decoded URL should contain only one relative (last 24 hours) time range query, like that query:(range:(timestamp:(format:strict_date_optional_time,gte:now-24h/h,lte:now))))

@dimaanj dimaanj added Feature:Discover Discover Application release_note:fix v8.1.0 Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. labels Jan 18, 2022
@dimaanj dimaanj self-assigned this Jan 18, 2022
@dimaanj dimaanj marked this pull request as ready for review January 18, 2022 12:24
@dimaanj dimaanj requested a review from a team as a code owner January 18, 2022 12:24
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@dimaanj
Copy link
Contributor Author

dimaanj commented Jan 20, 2022

@elasticmachine merge upstream

Comment on lines 59 to 72
const absoluteFilter = data.query.timefilter.timefilter.createFilter(index);
const timeFilter = absoluteTime
? data.query.timefilter.timefilter.createFilter(index)
? absoluteFilter
: data.query.timefilter.timefilter.createRelativeFilter(index);

// remove timeFilter from existing filter
if (Array.isArray(existingFilter)) {
existingFilter = existingFilter.filter(
(current) => !isEqualFilters(current, absoluteFilter)
);
} else if (isEqualFilters(existingFilter, absoluteFilter)) {
existingFilter = undefined;
}

Copy link
Member

Choose a reason for hiding this comment

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

a first thought about this ... now is converted to absolute time when creating a filter, are we sure the generated time here matches to the existing time of the existing filter, which might also be converted, but it was converted before the creation of absoluteFilter. I'm not 100% sure here how this works, so I'd need to dive a bit deeper then I can this week. in any case we'd need test coverage for this.

Copy link
Contributor

@jloleysens jloleysens Feb 3, 2022

Choose a reason for hiding this comment

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

@kertal it does look like there could be a race condition.

This is quite tricky to reason about -- I agree tests for the different cases would be really useful (even as a way to document all this!). AFAICT there are 2 scenarios we want to handle:

  1. Share data is requested for immediate use (e.g. CSV of exactly now)
  2. Share data is requested for deferred use (e.g. CSV whenever + rolling window)

In case 1 we want a search source containing an absolute time range so that we can give the user an accurate picture of their data in that moment.

In case 2 we want to give users a "rolling window" so they can get their data over time (unless they've explicitly set an absolute time filter, then RIP relative time filter).

A complication is in both cases there could be cascading time range filters, themselves either relative or absolute 🤪

therefore I think this code should try to "only" concern itself with the 2 scenarios AND not overriding existing filters. broadly something like:

if (absoluteTime === true) {
  // we want to generate a search source that will generate a picture of the data now
  // append the absolute time filter
} else {
 // we want to generate a search source that will provide a rolling window
 // append the relative time filter
}

What do you guys think?

Copy link
Contributor

@jloleysens jloleysens Feb 3, 2022

Choose a reason for hiding this comment

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

Ah, one piece I missed is "extracting" the current time range filter in Discover because we are converting to either relative or absolute, so some overriding is required 🤔 are these perhaps not separated by SearchSource.getParent?

Copy link
Member

Choose a reason for hiding this comment

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

Alright, I think we agree then we should improve code here, but since we also need to backport I'd suggest to keep the scope small, just suggested a way we can be sure that there are no race conditions. If this is fine, it would fix the issue, and we could think about improving stuff in a future PR targeting simplification in this area. How does that sound

@dimaanj
Copy link
Contributor Author

dimaanj commented Jan 24, 2022

@elasticmachine merge upstream

@dimaanj
Copy link
Contributor Author

dimaanj commented Jan 26, 2022

@elasticmachine merge upstream

@dimaanj
Copy link
Contributor Author

dimaanj commented Jan 27, 2022

@elasticmachine merge upstream

@kertal kertal requested a review from tsullivan January 28, 2022 09:45
@dimaanj
Copy link
Contributor Author

dimaanj commented Jan 31, 2022

@elasticmachine merge upstream

Copy link
Member

@tsullivan tsullivan left a comment

Choose a reason for hiding this comment

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

LGTM

@dimaanj
Copy link
Contributor Author

dimaanj commented Mar 16, 2022

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
discover 376.6KB 380.3KB +3.7KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
discover 50.4KB 50.4KB +22.0B

History

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

cc @dmitriynj

@kertal kertal self-requested a review March 16, 2022 06:33
Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

LGTM, thx for the fix and the functional coverage 👍

@dimaanj dimaanj added auto-backport Deprecated - use backport:version if exact versions are needed v7.17.1 v8.1.1 and removed v8.1.0 labels Mar 16, 2022
@dimaanj dimaanj merged commit deb7099 into elastic:main Mar 16, 2022
kibanamachine pushed a commit that referenced this pull request Mar 16, 2022
…n view (#123206)

* [Discover] fix relative time filter for csv export from discover main page

* [Discover] fix array assignment

* [Discover] fix functional test

* [Discover] add test coverage for the issue

* [Discover] add debug points for functional test

* [Discover] try to get clipboard permissions

* [Discover] fix functional test

* [Discover] apply suggestion

* [Discover] apply suggestion

* [Discover] apply naming suggestion

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit deb7099)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
7.17 Backport failed because of merge conflicts
8.1

Manual backport

To create the backport manually run:

node scripts/backport --pr 123206

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Mar 16, 2022
…n view (#123206) (#127847)

* [Discover] fix relative time filter for csv export from discover main page

* [Discover] fix array assignment

* [Discover] fix functional test

* [Discover] add test coverage for the issue

* [Discover] add debug points for functional test

* [Discover] try to get clipboard permissions

* [Discover] fix functional test

* [Discover] apply suggestion

* [Discover] apply suggestion

* [Discover] apply naming suggestion

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit deb7099)

Co-authored-by: Dmitry Tomashevich <39378793+Dmitriynj@users.noreply.github.com>
maksimkovalev pushed a commit to maksimkovalev/kibana that referenced this pull request Mar 18, 2022
…n view (elastic#123206)

* [Discover] fix relative time filter for csv export from discover main page

* [Discover] fix array assignment

* [Discover] fix functional test

* [Discover] add test coverage for the issue

* [Discover] add debug points for functional test

* [Discover] try to get clipboard permissions

* [Discover] fix functional test

* [Discover] apply suggestion

* [Discover] apply suggestion

* [Discover] apply naming suggestion

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
dimaanj added a commit to dimaanj/kibana that referenced this pull request Jun 3, 2022
…n view (elastic#123206)

* [Discover] fix relative time filter for csv export from discover main page

* [Discover] fix array assignment

* [Discover] fix functional test

* [Discover] add test coverage for the issue

* [Discover] add debug points for functional test

* [Discover] try to get clipboard permissions

* [Discover] fix functional test

* [Discover] apply suggestion

* [Discover] apply suggestion

* [Discover] apply naming suggestion

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit deb7099)

# Conflicts:
#	src/plugins/discover/public/application/apps/main/utils/get_sharing_data.ts
#	x-pack/test/functional/apps/discover/reporting.ts
dimaanj added a commit to dimaanj/kibana that referenced this pull request Jun 3, 2022
…n view (elastic#123206)

* [Discover] fix relative time filter for csv export from discover main page

* [Discover] fix array assignment

* [Discover] fix functional test

* [Discover] add test coverage for the issue

* [Discover] add debug points for functional test

* [Discover] try to get clipboard permissions

* [Discover] fix functional test

* [Discover] apply suggestion

* [Discover] apply suggestion

* [Discover] apply naming suggestion

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit deb7099)

# Conflicts:
#	src/plugins/discover/public/application/apps/main/utils/get_sharing_data.ts
dimaanj added a commit that referenced this pull request Jun 3, 2022
…n view (#123206) (#133506)

* [Discover] fix relative time filter for csv export from discover main page

* [Discover] fix array assignment

* [Discover] fix functional test

* [Discover] add test coverage for the issue

* [Discover] add debug points for functional test

* [Discover] try to get clipboard permissions

* [Discover] fix functional test

* [Discover] apply suggestion

* [Discover] apply suggestion

* [Discover] apply naming suggestion

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit deb7099)

# Conflicts:
#	src/plugins/discover/public/application/apps/main/utils/get_sharing_data.ts
#	x-pack/test/functional/apps/discover/reporting.ts

Co-authored-by: Dmitry Tomashevich <39378793+Dmitriynj@users.noreply.github.com>
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 6, 2022
@kibanamachine
Copy link
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.

@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Discover Discover Application release_note:fix Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v7.17.5 v8.0.2 v8.1.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Reporting] CSV Export URL generation adds an absolute time range filter
8 participants