-
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
[Discover][ES]QL] Ensure the same time range is being used for documents and histogram #203215
Conversation
/ci |
/ci |
/ci |
…na into discover-histogram-debugging
/ci |
/ci |
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 |
src/plugins/discover/public/application/main/components/layout/use_discover_histogram.ts
Outdated
Show resolved
Hide resolved
src/plugins/discover/public/application/main/hooks/use_saved_search_messages.ts
Outdated
Show resolved
Hide resolved
/ci |
/ci |
/ci |
Flaky Test Runner Stats🎉 All tests passed! - kibana-flaky-test-suite-runner#7580[✅] test/functional/apps/discover/group3/config.ts: 25/25 tests passed. |
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
timeRange, | ||
relativeTimeRange: timeRangeRelative, |
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.
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.
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.
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
kibana/src/plugins/unified_histogram/public/layout/layout.tsx
Lines 84 to 87 in 61d0320
/** | |
* 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); |
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.
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.
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.
maybe the naming is misleading, because the input here is
Line 242 in 1023a8e
timefilter.getAbsoluteTime(), |
And getAbsoluteTime
takes care of the bounds and considering now
💚 Build Succeeded
Metrics [docs]Async chunks
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
cc @kertal |
timeRange?: TimeRange; | ||
timeRangeRelative?: TimeRange; |
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.
I would rather call it differently:
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); |
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.
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( |
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.
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, |
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.
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({ |
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.
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.
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.
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()); |
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.
timefilter.getAbsoluteTime(), | ||
timefilter.getTime(), | ||
appStateContainer.getState().query | ||
); |
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.
Would not sendResetMsg
erase it?
closing in favor of #204694 |
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:
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
Checklist