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][ES]QL] Ensure the same time range is being used for documents and histogram #203215

Closed
wants to merge 18 commits into from

Conversation

kertal
Copy link
Member

@kertal kertal commented Dec 6, 2024

Summary

Resolves #201128

This PR fixes the case a relative time range is set (for example "Last 15 minutes") and the time range goes out of sync for table and histogram requests on Discover in ES|QL mode.

The main change is here:

export interface DataMainMsg extends DataMsg {
   foundDocuments?: boolean;
   timeRange?: TimeRange;
   timeRangeRelative?: TimeRange;
 }

By extending the DataMainMsg with timeRange, timeRangeRelative, and consuming these values in subsequent code relevant for data fetching, we make sure, no relative timeRange is being converted with a delay causing a slightly different absolute timeRange. These values are set when the data fetching starts, and the way the code was rewritten also will lead to less redundant requests caused by the Histogram in Discover, but it doesn't fully resolve the issue #165192 (which I thought it does initially, built on the given approach to reduce the sources of truth for all relevant state for data fetching, I'm confident this can be resolved longer down the road)

Testing

  1. Set a relative time range in Discover in ES|QL mode
  2. Observe via Inspect that time range filter is the same for Table and Visualization calls.

Checklist

@kertal
Copy link
Member Author

kertal commented Dec 6, 2024

/ci

@kertal
Copy link
Member Author

kertal commented Dec 6, 2024

/ci

@kertal
Copy link
Member Author

kertal commented Dec 6, 2024

/ci

@kertal
Copy link
Member Author

kertal commented Dec 6, 2024

/ci

@kertal
Copy link
Member Author

kertal commented Dec 6, 2024

/ci

@davismcphee
Copy link
Contributor

Thanks for investigating! This approach seems really similar to what I was thinking in #201128 (comment), and I wonder if it addresses that issue too? I know this investigation is mainly about the extra fetches, but maybe it's a two birds (or flies 🙂) at once kinda thing.

@kertal
Copy link
Member Author

kertal commented Dec 6, 2024

Thanks for investigating! This approach seems really similar to what I was thinking in #201128 (comment), and I wonder if it addresses that issue too? I know this investigation is mainly about the extra fetches, but maybe it's a two birds (or flies 🙂) at once kinda thing.

Yes, it seems to fix #201128 and #165192 , and CI is green?

In any case I think it should be a relatively easy issue to resolve (famous last words) @davismcphee

You're right, and it wasn't even my intention to fix this (if this is true), I just wanted to see if #201128 was still valid with all the changes we applied recently.

So I did use the main$ observable to store timerange, which is basically what you suggested with internalState, but it's the same concept ... and we can do more to simplify, I think

@kertal
Copy link
Member Author

kertal commented Dec 10, 2024

/ci

@kertal kertal self-assigned this Dec 11, 2024
@kertal kertal added Feature:Discover Discover Application Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. release_note:fix labels Dec 11, 2024
@kertal kertal changed the title Initial histogram debugging [Discover][ES]QL] Ensure the same time range is being used for documents and histogram Dec 11, 2024
@kertal
Copy link
Member Author

kertal commented Dec 11, 2024

/ci

@kertal
Copy link
Member Author

kertal commented Dec 11, 2024

/ci

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🎉 All tests passed! - kibana-flaky-test-suite-runner#7580

[✅] test/functional/apps/discover/group3/config.ts: 25/25 tests passed.
[✅] test/functional/apps/discover/esql/config.ts: 25/25 tests passed.

see run history

@kertal kertal marked this pull request as ready for review December 11, 2024 18:26
@kertal kertal requested a review from a team as a code owner December 11, 2024 18:26
@elasticmachine
Copy link
Contributor

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

@kertal kertal added the backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) label Dec 12, 2024
Comment on lines +394 to +395
timeRange,
relativeTimeRange: timeRangeRelative,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have just one time range which is in absolute format? The relative one was probably necessary in the histogram for the previous approach but now it might be redundant.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had a look at it, but I don't think we can currently do this because we are using the relative time range for e.g. the edit visualization

/**
* The relative time range, used when timeRange is an absolute range (e.g. for edit visualization button)
*/
relativeTimeRange?: TimeRange;

I think that's used e.g. for the time range when clicking on the Lens button in DataView mode

@@ -48,7 +50,7 @@ export function updateVolatileSearchSource(

if (dataView.type !== DataViewType.ROLLUP) {
// Set the date range filter fields from timeFilter using the absolute format. Search sessions requires that it be converted from a relative range
const timeFilter = data.query.timefilter.timefilter.createFilter(dataView);
const timeFilter = data.query.timefilter.timefilter.createFilter(dataView, inputTimeRange);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to be passing a time range to the histogram which is a result of createFilter instead of the input time range because the bounds can be different due to its internal logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe the naming is misleading, because the input here is

And getAbsoluteTime takes care of the bounds and considering now

@kertal kertal requested a review from jughosta December 13, 2024 08:18
@elasticmachine
Copy link
Contributor

💚 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 786.1KB 786.4KB +306.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
discover 18 17 -1

Total ESLint disabled count

id before after diff
discover 20 19 -1

History

cc @kertal

Comment on lines +56 to +57
timeRange?: TimeRange;
timeRangeRelative?: TimeRange;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather call it differently:

Suggested change
timeRange?: TimeRange;
timeRangeRelative?: TimeRange;
timeRangeAbsolute?: TimeRange;
timeRangeOriginal?: TimeRange;

Btw is it correct that they are optional?

@@ -57,7 +80,7 @@ export function sendLoadingMsg<T extends DataMsg>(
props?: Omit<T, 'fetchStatus'>
) {
if (data$.getValue().fetchStatus !== FetchStatus.LOADING) {
data$.next({ ...props, fetchStatus: FetchStatus.LOADING } as T);
data$.next({ ...data$.getValue(), ...props, fetchStatus: FetchStatus.LOADING } as T);
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be better to spread only the new props. I am not sure how it would affect the app otherwise. Don't want surprises 😀

@@ -235,6 +237,12 @@ export function getDataStateContainer({

abortController?.abort();
abortControllerFetchMore?.abort();
sendFetchStartMsg(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be after if (options.fetchMore) { block as fetching more should be based on the original time range.

...main$.getValue(),
timeRange,
timeRangeRelative,
query,
Copy link
Contributor

Choose a reason for hiding this comment

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

documents$ already has query but it's being set after documents are loaded. I anticipate it becoming confusing if we introduce query for main$ too but it would be set before the loading even starts. What are we trying to solve by adding query with a different logic here?

timeRangeRelative: TimeRange,
query: AggregateQuery | Query | undefined
) {
main$.next({
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we break "state machine" concept by editing props without changing fetchStatus. We could either introduce a new state or incorporate this new data into LOADING event.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or create another observable like searchRequestParams$ instead of modifying main$ or documents$.

timefilter.getTimeUpdate$().pipe(map(() => timefilter.getTime())),
timefilter.getTime()
);
const { timeRangeRelative, timeRange, query } = useObservable(main$, main$.getValue());
Copy link
Contributor

Choose a reason for hiding this comment

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

I am seeing a delay in screen updates. Like it briefly shows "Searching" message and then pauses with a white screen. And only after some moments it shows loading indicators in the histogram and table sections. Can it be related to these changes?

Dec-17-2024 14-59-33

timefilter.getAbsoluteTime(),
timefilter.getTime(),
appStateContainer.getState().query
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would not sendResetMsg erase it?

@kertal
Copy link
Member Author

kertal commented Dec 19, 2024

closing in favor of #204694

@kertal kertal closed this Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) 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.
Projects
None yet
5 participants