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
Explore: Clear live logs #64237
Explore: Clear live logs #64237
Conversation
Thanks @abdulhdr1 for submitting this! @grafana/observability-logs could you please have a look at this? Tested it locally and works nicely 👍 I just wonder if that could be somehow added to |
Sure! It was my bad, I'm still getting familiar with the codebase 😅 . After coming to the problem again it's a better approach as the logic should be contained within redux, will work on moving it to |
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.
This is amazing! 🚀 Really great job with this! I think this is going to be a great feature for live tailing. I've left some feedback, let me know what do you think, if you have any questions.
@@ -147,6 +159,10 @@ class LiveLogs extends PureComponent<Props, State> { | |||
</tbody> | |||
</table> | |||
<div className={styles.logsRowsIndicator}> | |||
<Button variant="secondary" onClick={onClear} className={styles.button}> |
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 move this button after the Resume
|Pause
button as that is the most important one in row.
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.
also you can use the icon
prop on the button to have the icon properly rendered as a prefix (and without the need to add the "margin" with
)
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.
Got it, moved Clear logs
to be the second one and use the Button icon
prop, I thought it was nice to make it consistent in close use cases, so I've also changed Resume | Pause
to use the prop, but couldn't change the Exit live mode
button because it uses the type
Icon
prop that isn't available on Button's prop API (maybe a new issue?)
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.
} | ||
return rowsToRender; | ||
}; | ||
|
||
orderRowsByTime = (rows: LogRowModel[]) => { |
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.
In public/app/features/logs/utils.ts
we already have sortLogRows
function. Could we use that instead?
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.
Sure, I didn't notice that there was one already 😅
@@ -0,0 +1,31 @@ | |||
import { MutableDataFrame, LogLevel, LogRowModel } from '@grafana/data'; | |||
export const makeLogs = (numberOfLogsToCreate: number, overrides?: Partial<LogRowModel>): LogRowModel[] => { |
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.
😍
@@ -1065,7 +1108,7 @@ export const processQueryResponse = ( | |||
graphResult, | |||
tableResult, | |||
rawPrometheusResult, | |||
logsResult, | |||
logsResult: filterLogRows(state, logsResult), |
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.
nit pick - to make it more clear that we filter logs only if we are in live mode, I'd do something like logsResult: state.isLive ? filterLogRows(state.clearedAt, logsResult) : logsResult
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.
Hmmm, thinking about it, couldn't we make filterLogRows
-> filterLogRowsByTime
accept log rows and clearedAt and then use it also in LiveLogs.ts
?
@abdulhdr1 whenever this is ready for review, could you please re-request them. Also, it seems that there is a merge conflict so you need to merge main, before we can review again. |
given we are filtering the logs every time we get more data, i'm wondering what will be the performance implications 🤔 This means that potentially, given enough time, we'll have to filter a huge number on logs based on their timestamp. What if instead clearing logs saved the size of the array and when rendering we only display btw sorry for the delay, i'll take some time to review this properly on monday |
@Elfo404 yeah, that is a very good point, performance-wise |
Yeah, I hadn't thought of it before but it's surely going to affect performance. |
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 have found 2 bugs:
-
If you clear logs and then press
pause
, no logs are visible anymore -
We initially load logs from your previous query (if you've run some). In my case, I have line limit set to
1000
, so initially I have 1000 logs. If I have slow-coming logs and if click onclear logs
before the first batch of live tailing logs arrive, theclearAtIndex
will be999
and I won't see any incoming logs.
edge.case.live.tailing.mov
Sorry, I don't get it, should the cleared logs "return" when you pause?
I worked on this in the last commit, but I don't know if there's a better way of checking if it's the first batch. Also, I'm basing it on the assumption that the state can only go |
This pull request was removed from the 9.5.0 milestone because 9.5.0 is currently being released. |
First of all thank you for being so responsive and working on this useful feature! Really appreciated!! 🧡 And I am excited to see it being part of Live tailing.
I am wondering if you have considered adding this kind of logic to What do you think about this?
Oh, could be an issue on my side. When I pressed pause, all logs in live tailing disappeared for me even if I didn't press |
The pleasure is all mine, thank you for the feedback on my code, I'm looking forward to contributing to other features!
That surely would be a better design, but I didn't want to make the clear logs button unresponsive during the |
Not sure if I understand. The loading state is only at the beginning when we display logs from previously run "normal" query (that was displayed in regular logs view) in live tailing view. So if we use clear action - that returns empty And then when all the new logs come trough But maybe I am missing something. 🤔 |
You're right. I must have misunderstood something before, there is no unresponsiveness. I'm going to add the change you suggested |
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.
LGTM! 🚀 Really great job with this. @Elfo404 would you have a look as well.
Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
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.
🚀
* feat: add clear logs to explorer's live logs * refactor live logs pause/resume updating logic * add tests for clearing live logs * rm unused imports * move `onClear` live logs logic to redux * move clear logs tests to `query.test` * use utils `sortLogsRows` and Button's icon props * rename `filterLogRows` and add `clearedAt` as an arg * mv clearedAt type closer to live tailing items and add jsdoc * mv `filterLogRowsByTime` to `/utils` and use it at `LiveLogs` component * make `Exit live` button consistent with other actions * use `sortLogRows` and fix timestamp by id on `makeLogs` * change clear live logs from based on timestamp to index on logRows * assign `null` to `clearedAtIndex` on first batch of logs live * move `isFirstStreaming` implementation to `clearLogs` reducer * fix `clearLogs` tests * Update public/app/features/explore/state/query.ts Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> --------- Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
What is this feature?
A button that allows the user to clear the incoming live tailing logs, viewing only the newcoming ones
Why do we need this feature?
Sometimes, when viewing live logs, it's useful to look only at new messages
Which issue(s) does this PR fix?:
Fixes #25274