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

Flamegraph: Move to package #73113

Merged
merged 29 commits into from
Sep 12, 2023
Merged

Flamegraph: Move to package #73113

merged 29 commits into from
Sep 12, 2023

Conversation

aocenas
Copy link
Member

@aocenas aocenas commented Aug 9, 2023

Moving the Flamegraph code into a separate package so it can bu published in NPM and used outside of Grafana. Main usecase right now is the Pyroscope web app:

Screenshot 2023-09-05 at 22 07 37

See the draft PR in the pyro web app for usage.

Main part of the changes here are obviously that the code of the flamegraph was moved from the core grafana to a separate package/ directory.

There are also some other notable changes I will also try to highlight in the code:

  • Removed dependency on grafana/runtime. This does not make sense in a component package anyway and was used mainly for interaction reporting. This was moved to an injectable hooks that fire on specific interactions.
  • Add getTheme prop so theme can be injected instead of relying on useTheme and it's access to theme in react context.
  • stickyHeader prop to control the header css. Before it relied on knowing which part of Grafana was this used in which again does not make sense in a package.
  • extraHeaderElements + vertical props. Allows more customization for usecases inside the pyroscope app.

Wider context

why new package?
We want to unify the flamegraph components across grafana and Pyroscope web app. Because of that we need to be able to import the component into non grafana envirnment.

why not adding it to grafana/ui
The grafana/ui is probably wider than it should be. Adding visualizations would make it too big to act as a general component library. Visualizations also mostly act as a small self contained applications so may not fit the same abstraction. Also we want to eventually have the flexibility of having separate release for visualizations panel plugins and if they depended on grafana/ui with most of their code they would still be tied to it.

Testing

The basic test would be to see if the flamegraph still works ok inside grafana either with devenv pyroscope block or using test data source.

To see it used in Pyroscope app this is a bit harder right now. You have to setup local npm server and publish the package there. See the packages readme for instructions, then you can use the Pyroscope PR, install it there and try it out.

// the language from the backend and use the right regex but right now we just try all of them from most to least
// specific.
const matchers = [
['phpspy', /^(?<packageName>(.*\/)*)(?<filename>.*\.php+)(?<line_info>.*)$/],

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings containing many repetitions of '/'.
// specific.
const matchers = [
['phpspy', /^(?<packageName>(.*\/)*)(?<filename>.*\.php+)(?<line_info>.*)$/],
['pyspy', /^(?<packageName>(.*\/)*)(?<filename>.*\.py+)(?<line_info>.*)$/],

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings containing many repetitions of '/'.
const matchers = [
['phpspy', /^(?<packageName>(.*\/)*)(?<filename>.*\.php+)(?<line_info>.*)$/],
['pyspy', /^(?<packageName>(.*\/)*)(?<filename>.*\.py+)(?<line_info>.*)$/],
['rbspy', /^(?<packageName>(.*\/)*)(?<filename>.*\.rb+)(?<line_info>.*)$/],

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings containing many repetitions of '/'.
@github-actions
Copy link
Contributor

github-actions bot commented Aug 10, 2023

⚠️   Possible breaking changes

(Open the links below in a new tab to go to the correct steps)

grafana-flamegraph has possible breaking changes (more info)

Console output
Read our guideline

@github-actions github-actions bot added the levitate breaking change A label indicating a breaking change and assigned by Levitate. label Aug 10, 2023
@tolzhabayev
Copy link
Contributor

Shouldn't this live in grafana/ui or grafana/experimental? What is the need for another package?

@torkelo
Copy link
Member

torkelo commented Aug 10, 2023

can't it be used via PanelRenderer or scenes VizPanel?

@aocenas
Copy link
Member Author

aocenas commented Aug 31, 2023

Sorry for late reply:
@tolzhabayev

Shouldn't this live in grafana/ui or grafana/experimental? What is the need for another package?

I talked to front end platform and they were quite strongly against adding more visualization into grafana/ui package. Also if we want to speed up the development of plugins we probably want to make them less dependant on bigger packages like grafana/ui which may have less frequent releases.

@torkelo

can't it be used via PanelRenderer or scenes VizPanel?

This should be used both in app plugin but also in separate pyroscope web app (and maybe in flamegraph.com) which do not have any grafana runtime stuff.

@aocenas aocenas marked this pull request as ready for review September 5, 2023 20:01
@aocenas aocenas requested a review from a team as a code owner September 5, 2023 20:01
@aocenas
Copy link
Member Author

aocenas commented Sep 6, 2023

@academo sorry just now pushed the readme

@tolzhabayev
Copy link
Contributor

@aocenas I would love to have a clear why not grafana/ui before we merge anything (looks like you pinged Josh above).

And @staton-hyse11 would be interesting to hear what you think?

Additionally please add your squad as owners for this package after this line

/packages/grafana-schema/src/**/*tempo* @grafana/observability-traces-and-profiling

Hooking into publishing pipeline should be done by frontend platform I guess, probably some CI scripts need to be adjusted.

@aocenas aocenas requested a review from a team September 6, 2023 14:46
@aocenas
Copy link
Member Author

aocenas commented Sep 6, 2023

@tolzhabayev I added some more context to the description in this PR

@aocenas
Copy link
Member Author

aocenas commented Sep 7, 2023

The question of putting this into grafana/ui was discussed separately and we agreed to continue with the PR as it is.

data={props.dataFrames[0]}
stickyHeader={true}
getTheme={() => config.theme2}
onTableSymbolClick={() => interaction('table_item_selected')}
Copy link
Member Author

Choose a reason for hiding this comment

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

To remove grafana/runtime the interaction reporting is injected like this now.

<FlameGraph
data={props.dataFrames[0]}
stickyHeader={true}
getTheme={() => config.theme2}
Copy link
Member Author

Choose a reason for hiding this comment

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

Injected theme so we don't rely on having it in the react context

Copy link
Contributor

Choose a reason for hiding this comment

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

Will there be cases where the flamegraph will run without the Theme context? Is the idea that this package can be used outside of Grafana?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes in the pyroscope web app.

value={selectedView}
onChange={setSelectedView}
/>
{extraHeaderElements && <div className={styles.extraElements}>{extraHeaderElements}</div>}
Copy link
Member Author

Choose a reason for hiding this comment

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

Extra elements rendered here. In pyroscope used to inject a button to download the profile in various formats.

@joey-grafana
Copy link
Contributor

Works locally with testdb & pyroscope/phlare backend, but do you have more details to test this in the app?

Copy link
Contributor

@mckn mckn left a comment

Choose a reason for hiding this comment

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

LGTM! I really like the work you have done here and I would love to see more of our "bigger" visualisations be structured like this.

packages/grafana-flamegraph/src/FlameGraphContainer.tsx Outdated Show resolved Hide resolved
@aocenas aocenas merged commit e4f26a5 into main Sep 12, 2023
17 of 20 checks passed
@aocenas aocenas deleted the aocenas/flamegraph/package branch September 12, 2023 10:28
chauchausoup pushed a commit to chauchausoup/grafana that referenced this pull request Sep 15, 2023
rwwiv pushed a commit that referenced this pull request Oct 2, 2023
@zerok zerok modified the milestones: 10.2.x, 10.2.0 Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants