-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat(FlameGraph): Keep focus whenever the profile data changes #325
base: main
Are you sure you want to change the base?
Conversation
@@ -38,16 +38,17 @@ | |||
"@emotion/css": "11.10.6", | |||
"@grafana/data": "11.3.2", | |||
"@grafana/faro-web-sdk": "^1.10.0", | |||
"@grafana/flamegraph": "11.3.2", |
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.
Removed and added all its dependencies instead.
@@ -14,6 +13,7 @@ import { PyroscopeLogo } from '@shared/ui/PyroscopeLogo'; | |||
import React, { useEffect, useMemo } from 'react'; | |||
import { Unsubscribable } from 'rxjs'; | |||
|
|||
import { FlameGraph } from '../../../../tmp/grafana-flamegraph/src/'; |
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.
TS was complaining when I tried aliasing @gfrafana/flamegraph
. Webpack didn't 🤷🏾♂️
* Whether or not to keep any focused item when the profile data changes. | ||
*/ | ||
keepFocusOnDataChange?: boolean; | ||
}; |
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.
👆🏾 The change
From the feedback:
Shouldn't we lock entire FlameGraph state when users starts drilling down? And maybe show some sort of indication that there's new data coming in and the graph needs refreshing? I found it a bit confusing that the graph tries to keep the focus also when I change the time range. The block that is in focus may not exist anymore. |
} | ||
|
||
if (focusedItem) { | ||
const percentValue = totalTicks > 0 ? Math.round(10000 * (focusedItem.item.value / totalTicks)) / 100 : 0; |
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.
A small change to prevent NaN
or 0 values to appear. A tooltip has also been added to remind which function is focused, as well as some minor CSS alignment changes below.
verticalAlign: 'text-bottom', | ||
margin: theme.spacing(0, 0.5), | ||
}), | ||
metadata: css({ |
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 fixes the alignment
setSandwichItem(undefined); | ||
}, [setSandwichItem]); | ||
|
||
useEffect(() => { |
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.
The change.
setRangeMin(item.start / totalViewTicks); | ||
setRangeMax((item.start + item.value) / totalViewTicks); | ||
} else { | ||
setFocusedItemData({ |
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.
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.
Works great!
My only doubt is about FlameGraphCanvas vs FlameGraphContainer responsibilities. Canvas sets range
when user clicks while container sets range
to keep the focus. Also container is responsible for resetting range when focus is reset. Just a gut feeling but maybe setting range
based on focused item should be fully controlled by the container 🤔 otherwise we end up with similar code in both:
setRangeMin(clickedItemData.item.start / totalViewTicks);
setRangeMax((clickedItemData.item.start + clickedItemData.item.value) / totalViewTicks);
onItemFocused(clickedItemData);
Anyway, probably something to tackle separately. Good stuff!
What's the plan?
|
Thanks for the testing and review! I agree to your suggestion, it seems a good improvement to the code. We have a couple of issues for the flame graph package in our backlog, we will have many opportunities to refactor and clarify the responsibilities of the components in the future. |
I've updated grafana/grafana#98356 and will ping Joey and André to see if they want to have a look at it. Then I'd suggest to merge this PR so the functionality does not depend on Grafana's release cycle and has a chance to hit production faster. |
<Icon className={styles.sandwichMarkerIcon} name={'arrow-down'} /> | ||
let canvas = null; | ||
|
||
if (levelsCallers?.length) { |
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 made to prevent runtime errors (as seen in prod) when either:
levelsCallers[levelsCallers.length - 1]
is undefinedlevels[0]
is undefined
✨ Description
Related issue(s): resolves #260, related (draft) PR in Grafana grafana/grafana#98356
This PR introduces a new
keepFocusOnDataChange
prop to theFlameGraph
component.📖 Summary of the changes
In order to simplify the implementation of the fix, the whole @grafana/flamegraph package has been copy-pasted. Once agreed on the definitive solution, I'll update the PR in the Grafana repository.
I've commented the changes the diff tab (mainly in
src/tmp/grafana-flamegraph/src/FlameGraphContainer.tsx
).🧪 How to test?
The same should occur for the sandwich view