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: Add table filtering for Flamegraph panel #78962

Merged
merged 15 commits into from
Dec 7, 2023

Conversation

Rperry2174
Copy link
Contributor

@Rperry2174 Rperry2174 commented Dec 1, 2023

Addresses grafana/pyroscope#2786

Screen.Recording.2023-12-01.at.10.16.46.AM.mov

@Rperry2174 Rperry2174 requested a review from a team as a code owner December 1, 2023 15:49
@CLAassistant
Copy link

CLAassistant commented Dec 1, 2023

CLA assistant check
All committers have signed the CLA.

@grafana-delivery-bot grafana-delivery-bot bot added this to the 10.3.x milestone Dec 1, 2023
@Rperry2174 Rperry2174 changed the title Add table filtering for Flamegraph panel Flamegraph: Add table filtering for Flamegraph panel Dec 1, 2023
Copy link
Contributor

@joey-grafana joey-grafana left a comment

Choose a reason for hiding this comment

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

The filtering of the table looks good but there seems to be an issue with what is filtered in the flame graph.

e.g. if the search term is net/http.(*Server).Serve the only block I can see highlighted in the flame graph is net/http.serverHandler.ServeHTTP.

Screenshot 2023-12-04 at 09 12 26

Comment on lines 108 to 109
const unfilteredRows = screen.queryAllByText('SomeOtherTextNotInSearch');
expect(unfilteredRows.length).toBe(0); // Expect not to find rows that should be filtered out
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also search for this rows text before we perform the filter to make sure it does exist before a search term is input.

It should also be text that we know exists in the table so it is found before we input a search term.

packages/grafana-flamegraph/src/FlameGraphHeader.tsx Outdated Show resolved Hide resolved
table[label].totalRight = table[label].totalRight ? table[label].totalRight + valueRight : valueRight;

// Check if the label includes the search string
if (!search || label.toLowerCase().includes(search.toLowerCase())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to do some kind of fuzzy search in the future but I think this works nicely for a first step.

@Rperry2174
Copy link
Contributor Author

Rperry2174 commented Dec 4, 2023

The filtering of the table looks good but there seems to be an issue with what is filtered in the flame graph.

e.g. if the search term is net/http.(*Server).Serve the only block I can see highlighted in the flame graph is net/http.serverHandler.ServeHTTP.

as it turns out this is how it works currently in production as well I suspect this is on purpose. It seems the search ignores certain characters and does a sort of fuzzy matching approach

image

I guess we need to do the same logic in the table (or at least be consistent with whatever we're doing)

Copy link
Contributor

@joey-grafana joey-grafana left a comment

Choose a reason for hiding this comment

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

I heard you had a chat with @aocenas about fuzzy search, that you may want to add it to this PR. Let me know if that's not the case.


// Verify that rows with some other text are not shown after filter
const rowsAfterFilter = screen.queryAllByText('compress/gzip.(*Writer).Write');
expect(rowsAfterFilter.length).toBe(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

We would be more likely to catch an issue with the filtering if we also check this value before we apply the search filter to make sure it exists. That way, after we apply the search filter we expect it not to exist but we know that it did previously exist.

@Rperry2174
Copy link
Contributor Author

After doing some more digging I think this is going to be to complicated for me to implement as the scope is getting increasingly larger.

It seems to be working fine(ish), but:

  1. I can't figure out what is going on with the tests (it seems they are finding text that shouldn't be present elsewhere on the page (I think maybe in the flamegraph (?))
  2. @aocenas recommended I reuse the fuzzy search that is being used in the flamegraph itself and refector it to be "higher up" -- I'm not sure how to do that properly (
    function useFoundLabels(search: string | undefined, data: FlameGraphDataContainer): Set<string> | undefined {
    )

For these reasons I'm going to close and leave this to someone who is better equipped!

@Rperry2174 Rperry2174 closed this Dec 5, 2023
@grafana-delivery-bot grafana-delivery-bot bot removed this from the 10.3.x milestone Dec 5, 2023
@Rperry2174 Rperry2174 reopened this Dec 6, 2023
@grafana-delivery-bot grafana-delivery-bot bot added this to the 10.3.x milestone Dec 6, 2023
await userEvent.type(searchInput, 'Handler serve');

// We have to wait for filter to take effect
await waitFor(() => {
Copy link
Member

@aocenas aocenas Dec 7, 2023

Choose a reason for hiding this comment

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

@Rperry2174 maybe this is why you had trouble with the tests. The filter is debounced so the filtering happens async and the test needs to wait for it to have an effect. There is no explicit synchonization so the way to do it is this a bit crude "try/wait/try until some deadline" helper that the library provides.

Copy link
Contributor

@joey-grafana joey-grafana left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Screenshot 2023-12-07 at 13 27 20

@Rperry2174 Rperry2174 requested a review from a team as a code owner December 7, 2023 15:44
@Rperry2174 Rperry2174 requested review from Clarity-89 and JoaoSilvaGrafana and removed request for a team December 7, 2023 15:44
@aocenas aocenas merged commit aa12c6c into main Dec 7, 2023
17 checks passed
@aocenas aocenas deleted the flamegraph-search-filtering branch December 7, 2023 17:52
@aangelisc aangelisc modified the milestones: 10.3.x, 10.2.3 Dec 21, 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

5 participants