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

Explore: Clear live logs #64237

Merged
merged 18 commits into from Apr 20, 2023
Merged

Conversation

abdulhdr1
Copy link
Contributor

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

@abdulhdr1 abdulhdr1 requested a review from a team as a code owner March 6, 2023 15:10
@grafanabot grafanabot added area/explore area/frontend pr/external This PR is from external contributor labels Mar 6, 2023
@abdulhdr1 abdulhdr1 changed the title Feature/clear live logs Explore: Clear live logs Mar 6, 2023
@ifrost ifrost added this to the 9.5.0 milestone Mar 7, 2023
@ifrost ifrost added add to changelog no-backport Skip backport of PR labels Mar 7, 2023
@ifrost ifrost requested a review from a team March 7, 2023 08:51
@ifrost
Copy link
Contributor

ifrost commented Mar 17, 2023

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 useLiveTailControls 🤔

@ifrost ifrost removed the request for review from a team March 17, 2023 09:07
@abdulhdr1
Copy link
Contributor Author

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 useLiveTailControls

@abdulhdr1 abdulhdr1 requested a review from a team as a code owner March 19, 2023 20:06
@abdulhdr1 abdulhdr1 requested review from ashharrison90 and JoaoSilvaGrafana and removed request for a team March 19, 2023 20:06
Copy link
Member

@ivanahuckova ivanahuckova left a 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.

public/app/types/explore.ts Outdated Show resolved Hide resolved
@@ -147,6 +159,10 @@ class LiveLogs extends PureComponent<Props, State> {
</tbody>
</table>
<div className={styles.logsRowsIndicator}>
<Button variant="secondary" onClick={onClear} className={styles.button}>
Copy link
Member

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.

Copy link
Member

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 &nbsp;)

Copy link
Contributor Author

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?)

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't mind if we used square-shape icon without the type mono (that makes square filled) , as we already use square-shape without mono in live tailing button on top. So it would actually make it more consistent.
image

}
return rowsToRender;
};

orderRowsByTime = (rows: LogRowModel[]) => {
Copy link
Member

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?

Copy link
Contributor Author

@abdulhdr1 abdulhdr1 Mar 28, 2023

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[] => {
Copy link
Member

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),
Copy link
Member

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

Copy link
Member

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?

@ivanahuckova
Copy link
Member

@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.

@abdulhdr1 abdulhdr1 requested review from ivanahuckova and removed request for ashharrison90 and JoaoSilvaGrafana March 30, 2023 15:37
@Elfo404
Copy link
Member

Elfo404 commented Mar 31, 2023

given we are filtering the logs every time we get more data, i'm wondering what will be the performance implications 🤔
the fact that i can now clear logs means that (i suppose) a user will be less likely to leave the view (or refresh), as they can just clear the logs when they want to se only new data.

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 allLogs.slice(state.lastIndex)? it should be way faster.
although i'm not sure whether we actually need to modify the state to make to avoid any side effect. wdyt @ivanahuckova ?

btw sorry for the delay, i'll take some time to review this properly on monday

@ivanahuckova
Copy link
Member

@Elfo404 yeah, that is a very good point, performance-wise allLogs.slice(state.lastIndex) makes more sense. I like clearedAt from readability/possible reusability point, but it is true that with live tailing, you can have 1000s of log lines coming in. So maybe we could just change clearedAt -> clearedAtIndex and use the slice.

@abdulhdr1
Copy link
Contributor Author

given we are filtering the logs every time we get more data, i'm wondering what will be the performance implications

Yeah, I hadn't thought of it before but it's surely going to affect performance.
Changing clearedAt to clearedAtIndex, as @ivanahuckova suggested, seems to be the way, will work on making the changes

Copy link
Member

@ivanahuckova ivanahuckova left a 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 on clear logs before the first batch of live tailing logs arrive, the clearAtIndex will be 999 and I won't see any incoming logs.

edge.case.live.tailing.mov

@abdulhdr1
Copy link
Contributor Author

abdulhdr1 commented Apr 4, 2023

If you clear logs and then press pause, no logs are visible anymore

Sorry, I don't get it, should the cleared logs "return" when you pause?

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 on clear logs before the first batch of live tailing logs arrive, the clearAtIndex will be 999 and I won't see any incoming logs.

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 Loading -> Streaming on this scenario, is that fair to assume?

@grafanabot grafanabot removed this from the 9.5.0 milestone Apr 4, 2023
@grafanabot
Copy link
Contributor

This pull request was removed from the 9.5.0 milestone because 9.5.0 is currently being released.

@ivanahuckova
Copy link
Member

ivanahuckova commented Apr 6, 2023

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 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 Loading -> Streaming on this scenario, is that fair to assume?

I am wondering if you have considered adding this kind of logic to clearLogs, so we are handling everything related to clearLogs only in there and not in queryStreamUpdatedAction? In this case, we would be changing clearedAtIndex only if we have streaming state.

image

What do you think about this?

Sorry, I don't get it, should the cleared logs "return" when you pause?

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 clear logs. But I can't reproduce anymore, so feel free to disregard.

@abdulhdr1
Copy link
Contributor Author

The pleasure is all mine, thank you for the feedback on my code, I'm looking forward to contributing to other features!

What do you think about this?

That surely would be a better design, but I didn't want to make the clear logs button unresponsive during the loading state, maybe passing a disabled prop when state === "loading" should solve it.

@ivanahuckova
Copy link
Member

I didn't want to make the clear logs button unresponsive during the loading state, maybe passing a disabled prop when state === "loading" should solve it.

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 rows and set clearAtIndex to null, there shouldn't be any unresponsiveness.

And then when all the new logs come trough streaming, we can correctly set clearAtIndex to null.

But maybe I am missing something. 🤔

@abdulhdr1
Copy link
Contributor Author

You're right. I must have misunderstood something before, there is no unresponsiveness. I'm going to add the change you suggested

Copy link
Member

@ivanahuckova ivanahuckova left a 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.

public/app/features/explore/state/query.ts Show resolved Hide resolved
Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
@ivanahuckova ivanahuckova added this to the 10.0.0 milestone Apr 18, 2023
Copy link
Member

@Elfo404 Elfo404 left a comment

Choose a reason for hiding this comment

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

🚀

@ivanahuckova ivanahuckova merged commit 3a013cb into grafana:main Apr 20, 2023
12 checks passed
mdvictor pushed a commit that referenced this pull request Apr 21, 2023
* 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>
@abdulhdr1 abdulhdr1 deleted the feature/clear-live-logs branch April 22, 2023 18:28
@zerok zerok modified the milestones: 10.0.0, 10.0.0-preview May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/explore area/frontend no-backport Skip backport of PR pr/external This PR is from external contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Live tailing explore clear logs
6 participants