-
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
[Logs UI] Load <LogStream> entries via async searches #86899
[Logs UI] Load <LogStream> entries via async searches #86899
Conversation
893f2c2
to
96cd32a
Compare
76451b9
to
05b55aa
Compare
34a4a34
to
a855f10
Compare
Pinging @elastic/logs-metrics-ui (Team:logs-metrics-ui) |
⌛ resolving merge conflicts... |
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 downloaded the branch and everything seems to work correctly and code LGTM. I want to run two things with you (which can be addressed in a different PR).
The first thing is about the useFetchLogEntries {Before,After,Around}
hook separation. Is the intention to expose them to other possible consumers? If so, I wonder if they could be unified somehow. I don't see scenarios where the hooks are not used together and right now we have some duplication to initialise them.
const {
fetchLogEntriesBefore,
isRequestRunning: isLogEntriesBeforeRequestRunning,
logEntriesBeforeSearchResponse$,
} = useFetchLogEntriesBefore({
sourceId,
startTimestamp,
endTimestamp,
query: parsedQuery,
columnOverrides: columns,
});
const {
fetchLogEntriesAround,
isRequestRunning: isLogEntriesAroundRequestRunning,
logEntriesAroundSearchResponses$,
} = useFetchLogEntriesAround({
sourceId,
startTimestamp,
endTimestamp,
query: parsedQuery,
columnOverrides: columns,
});
const {
fetchLogEntriesAfter,
isRequestRunning: isLogEntriesAfterRequestRunning,
logEntriesAfterSearchResponse$,
} = useFetchLogEntriesAfter({
sourceId,
startTimestamp,
endTimestamp,
query: parsedQuery,
columnOverrides: columns,
});
If we could unify them, the API becomes simpler.
const {
fetchLogEntries,
isRequestRunning: isLogEntriesRequestRunning,
logEntriesSearchResponse$,
} = useFetchLogEntries({
sourceId,
startTimestamp,
endTimestamp,
query: parsedQuery,
columnOverrides: columns,
});
fetchLogEntries({ before: 'last' })
fetchLogEntries({ after: 'first' })
fetchLogEntries({ center/around: {...} })
The second comment is about the stateful (for the lack of a better word) nature of the hook. We pass the source, timestamp, query and columns on hook creation, and the cursor when calling the callback. This means that if any value changes (not uncommon) the hook gets recreated again. Would it make sense to make the hook stateless and pass everything on the callback?
const {
fetchLogEntries,
isRequestRunning: isLogEntriesRequestRunning,
logEntriesSearchResponse$,
} = useFetchLogEntries();
fetchLogEntries({
sourceId,
startTimestamp,
endTimestamp,
query: parsedQuery,
columnOverrides: columns,
before: 'last',
})
I think this only matters if the hooks will be used more publicly (i.e. in other hooks that we own). I understand this might make handling the center/around
use case harder.
You're making good points, @afgomez.
While I don't particularly favor the duplication either, I can think of a few reason to keep them separate:
I tried to factor out the common aspects of three variants to shared code paths. It's not ideal but optimizes for write-once/read-many-times to an acceptable degree IMHO. 🤔 But maybe I'm missing the obvious unifying approach, so I'm open for specific suggestions.
That was indeed an almost arbitrary choice. I tried to separate the arguments into those that likely won't change with every request and those that likely will. My criterion was: "Assuming the But if we realize that this decision doesn't match the usage in the future we could obviously revise it at any time. Does that make sense? |
@afgomez, just having written the above response the following idea came to mind: The arguments could easily be made less repetitious by factoring them out as in: const commonFetchArguments = {
sourceId,
startTimestamp,
endTimestamp,
query: parsedQuery,
columnOverrides: columns,
};
const {
fetchLogEntriesBefore,
isRequestRunning: isLogEntriesBeforeRequestRunning,
logEntriesBeforeSearchResponse$,
} = useFetchLogEntriesBefore(commonFetchArguments);
const {
fetchLogEntriesAround,
isRequestRunning: isLogEntriesAroundRequestRunning,
logEntriesAroundSearchResponses$,
} = useFetchLogEntriesAround(commonFetchArguments);
const {
fetchLogEntriesAfter,
isRequestRunning: isLogEntriesAfterRequestRunning,
logEntriesAfterSearchResponse$,
} = useFetchLogEntriesAfter(commonFetchArguments); What do you think of that? Interestingly this also seems to validate my reasoning about dividing the arguments into the more general and more specific ones in the response above. |
I've read through them and I agree. Let's keep it like this :) |
💚 Build SucceededMetrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
ℹ️ I'll wait for #89871 before I create the backport |
Merged! |
…-ml-jobs * 'master' of github.com:elastic/kibana: (254 commits) [Security Solution] [Detections] Remove allow_no_indices to prevent error being thrown in response of field capabilities (elastic#89927) Skip test for cloud (elastic#89450) [Fleet] Fix duplicate data streams being shown in UI (elastic#89812) Bump package dependencies (elastic#90034) [App Search] DRY helper for encoding/decoding routes that can have special characters in params (elastic#89811) TypeScript project references for Observability plugin (elastic#89320) [SearchSource] Combine sort and parent fields when serializing (elastic#89808) Made imports static (elastic#89935) [ml] migrate file_data_visualizer/import route to file_upload plugin (elastic#89640) [Discover] Adapt default column behavior (elastic#89826) Round start and end values (elastic#89030) Rename getProxyAgents to getCustomAgents (elastic#89813) [Form lib] UseField `onError` listener (elastic#89895) [APM] use latency sum instead of avg for impact (elastic#89990) migrate more core-owned plugins to tsproject ref (elastic#89975) [Logs UI] Load <LogStream> entries via async searches (elastic#86899) [APM] Abort browser requests when appropriate (elastic#89557) [Alerting] Allow user to select existing connector of same type when fixing broken connector (elastic#89062) [Data Table] Use shared CSV export mechanism (elastic#89702) chore(NA): improve logic check when installing Bazel tools (elastic#89634) ...
Summary
This PR replaces the usage of plain HTTP routes to load the log stream entries with async search strategy calls.
related to #86439
Implementation notes
The changes in this PR can be categorized roughly into one of these categories:
data
plugin'ssearch
functionalityuseLogStream
hook, which is called by the "view-in-context" and embeddable componentTo the user nothing really changes, except that running requests are now cancelled if the
<LogStream />
component is unmounted because the "view-in-context" modal is closed or the APM trace log tab is hidden. The progress indicators and cancellation buttons will improve the UX later (see follow-ups below).Follow-up tasks
For the sake of limiting the scope of this PR still leaves many of the ACs of #86439 and #86441 to follow-up PRs: