Skip to content

feat: (LogPanelTable) - sync the display fields and urlColumns between the logs panel and table #1189

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

Merged
merged 10 commits into from
Apr 21, 2025

Conversation

L2D2Grafana
Copy link
Collaborator

@L2D2Grafana L2D2Grafana commented Apr 10, 2025

Screen.Recording.2025-04-10.at.3.59.25.PM.mov

@L2D2Grafana L2D2Grafana requested a review from a team as a code owner April 10, 2025 23:03
@gtk-grafana
Copy link
Contributor

Overall looking good and working as expected, I really like the idea of being able to switch more easily between the views without needing to reconfigure columns.

A few bugs/regressions with the log line and time columns to clean up and we should be good to go:

If I have nothing visualized, and I toggle the table and back to the logs panel, the log line is stripped out and I see the "show original log line" button. I would expect this to be a noop.

base-case.mov

The timestamp currently is always displayed in the logs panel, so it's a bit jarring to have it removed from the Table:
image
image

When taking a logs panel query to Explore, the Time column is always stripped out, which doesn't occur on latest main:
image

@L2D2Grafana
Copy link
Collaborator Author

Overall looking good and working as expected, I really like the idea of being able to switch more easily between the views without needing to reconfigure columns.

A few bugs/regressions with the log line and time columns to clean up and we should be good to go:

If I have nothing visualized, and I toggle the table and back to the logs panel, the log line is stripped out and I see the "show original log line" button. I would expect this to be a noop.

base-case.mov
The timestamp currently is always displayed in the logs panel, so it's a bit jarring to have it removed from the Table: image image

When taking a logs panel query to Explore, the Time column is always stripped out, which doesn't occur on latest main: image

TY! Let me know if you think this is a better fix. Basically I'm storing default columns for 'body' and 'timestamp'

Screen.Recording.2025-04-14.at.10.08.13.AM.mov

@gtk-grafana
Copy link
Contributor

@L2D2Grafana that is much closer to what I expect, except at the [0:29-0:33] timestamp in your video, I would expect the panel in Explore to have the same columns as the panel in Logs Drilldown

@L2D2Grafana
Copy link
Collaborator Author

L2D2Grafana commented Apr 14, 2025

@L2D2Grafana that is much closer to what I expect, except at the [0:29-0:33] timestamp in your video, I would expect the panel in Explore to have the same columns as the panel in Logs Drilldown

I opened a can of worms 🪱 updating the url state. I still have one more known bug to fix opening in explore. Go to Explore needed to be synced with localStorage. Updated!

@L2D2Grafana L2D2Grafana force-pushed the l2d2/1126-sync-logs-table branch from 4df791f to 7390701 Compare April 15, 2025 18:09
onActivateSyncDisplayedFieldsWithUrlColumns = () => {
const searchParams = new URLSearchParams(locationService.getLocation().search);
const urlColumnsParam = searchParams.get('urlColumns');
const urlColumnsUrl = urlColumnsParam ? (JSON.parse(decodeURIComponent(urlColumnsParam)) as string[]) : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a good candidate to use https://github.com/grafana/logs-drilldown/blob/main/src/services/narrowing.ts that was introduced by @gtk-grafana to have more confidence on the actual type of stuff like user input, parsed json, etc.
We could add a narrowArray(type: string) or narrowStringArray().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated! Interesting concept, I took a look they all kind of seem like type validations. I wonder about naming them isValidType or isEmpty.

Copy link
Contributor

@matyax matyax Apr 17, 2025

Choose a reason for hiding this comment

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

Definitely. Not a huge fan of the "narrow" prefix. ´assert[Type]´ could also be an option.

@matyax
Copy link
Contributor

matyax commented Apr 16, 2025

This is super cool! It makes a huge difference going back and forth between visualizations.

@matyax matyax requested a review from a team April 17, 2025 11:29
@@ -123,4 +123,19 @@ export function narrowFilterOperator(op: string): LabelFilterOp | NumericFilterO
}
}

export function narrowUrlParam(param: unknown): string[] | null {
Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent! My only suggestion would be to make it generic so we can reuse this narrowing elsewhere, maybe like:

Suggested change
export function narrowUrlParam(param: unknown): string[] | null {
export function narrowStringsArray(param: unknown): string[] | null {

I wanted to make it generic but I couldn't find an easy way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah if there was a generic narrowing strategy it would be the most imported typescript npm package, I think this is something that needs a bit of hand-holding

Copy link
Contributor

@gtk-grafana gtk-grafana Apr 17, 2025

Choose a reason for hiding this comment

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

there is a unknownToStrings method in narrowing already tho

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried unknownToStrings but it's a slightly different use case where the param are passed in as strings and not an array so it never gets past

if (Array.isArray(a)) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the func name.

Copy link
Contributor

@matyax matyax left a comment

Choose a reason for hiding this comment

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

I can't decide whether we should not include the body in the table unless the user explicitly set it in the Logs view, but I think this is a huge improvement already. Other than making the narrowing generic, LGTM. Great work!

Copy link
Contributor

@matyax matyax left a comment

Choose a reason for hiding this comment

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

☄️

@L2D2Grafana L2D2Grafana merged commit 139c580 into main Apr 21, 2025
4 checks passed
@gtk-grafana gtk-grafana added this to the 1.0.12 milestone Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants