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

Correlations: Add transformations to Explore Editor #75930

Merged
merged 42 commits into from
Nov 2, 2023

Conversation

gelicia
Copy link
Contributor

@gelicia gelicia commented Oct 3, 2023

What is this feature?

Adds the ability to create one or more correlation transformations from the Explore correlation editor.

Why do we need this feature?

Transformations are almost necessary for creating correlations on logs. Logs' data format generally has more than one piece of information per field, notably the log line field and the labels field. Transformations were created to parse out information people may want, via a regular expression or logfmt.

Who is this feature for?

People who want to create correlations where data may be within in one field amongst other data.

Which issue(s) does this PR fix?:

Fixes #75832

Special notes for your reviewer:
Testing this with devenv, using Loki is probably your best bet. Logfmt will parse the devenv line, and labels can be parsed out with the following regex expressions:

  • namespace":"([a-z]*) - this is an unnamed capture group
  • namespace":"(?<test2>[a-z]*) this is a named capture group

In the ephemeral, loki data is available in the grafanacloud-ephemeral1511182175930gelicia-usage-insights Loki datasource. Doing a logfmt transformation against a Line field adds a lot of variables. Adding a regex transformation on labels works with the following

  • instance_type":"([a-z]*) - this is an unnamed capture group
  • instance_type":"(?<name>[a-z]*) - this is a named capture group

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2023

Backend code coverage report for PR #75930
No changes

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2023

Frontend code coverage report for PR #75930

Plugin Main PR Difference
correlations 90.15% 89.11% -1.04%
explore 85.57% 84.42% -1.15%

@gelicia gelicia force-pushed the kristina/correlations-editor-transform branch from bd6473d to a9e6b07 Compare October 4, 2023 01:20
@grafana grafana deleted a comment from ephemeral-instances-bot bot Oct 6, 2023
@grafana grafana deleted a comment from ephemeral-instances-bot bot Oct 6, 2023
@gelicia gelicia marked this pull request as ready for review October 6, 2023 17:37
@gelicia gelicia requested review from a team as code owners October 6, 2023 17:37
@gelicia gelicia removed the request for review from a team October 6, 2023 17:37
@gelicia gelicia requested a review from a team as a code owner October 20, 2023 15:51
@gelicia gelicia requested review from mckn and removed request for a team October 20, 2023 15:51
Copy link
Contributor

@ifrost ifrost left a comment

Choose a reason for hiding this comment

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

Transformations vars are not interpolated inside the editor

After adding transformations I was not able to use vars inside the editor / right pane. After saving everything works fine. It looks like only when we're inside the editor, then transformation vars are not used when interpolating.

interpolation.mov

Also probably not related to this PR but worth checking:

Mixed data source is used inside the default label instead of the underlying data source mixed-bug
Regex is case insenstive

I think it's been like this since we added this but I wonder if it shouldn't base case sensitive to allow capturing more specific cases. Or at least at it to the tooltip / docs.

case sensitive

${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_PANE} | ${true} | ${true} | ${false} | ${'Closing the pane will cause the correlation in progress to be lost. Would you like to save before continuing?'}
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_PANE} | ${true} | ${false} | ${true} | ${'Closing the pane will cause the query in the right pane to be re-ran and links added to that data. Would you like to save before continuing?'}
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_PANE} | ${true} | ${true} | ${true} | ${'Closing the pane will cause the correlation in progress to be lost. Would you like to save before continuing?'}
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE} | ${false} | ${false} | ${false} | ${undefined}
Copy link
Contributor

Choose a reason for hiding this comment

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

It may not happen with each data source but sometimes changing the data source without making any changes causes the modal to appear. Could it be because the editor calls onChange?

change-ds-triggers-the-prompt.mov

Copy link
Contributor Author

@gelicia gelicia Oct 26, 2023

Choose a reason for hiding this comment

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

Yeah :/ and I'm not quite sure what the solution is.

The order of events is this

  1. User changes the datasource to cloudwatch. This completes. The onChange function that we use to track a dirty query is passed into the query editor
  2. Cloudwatch's query editor internally runs a function that calls the onChange function passed in https://github.com/grafana/grafana/blob/main/public/app/plugins/datasource/cloudwatch/components/QueryEditor/QueryEditor.tsx#L28 - If you look at the queries before and after the change, it sets up the data structure for CW with log groups, region, an empty logGroups array, etc.
  3. The onChange function is executed and the query gets marked as dirty even without any user interaction interacting with the editor.

I need to investigate some more, but I don't know how to make the distinction between a user performed query change and an automatic one, when the editor itself doesn't make that distinction at all. I thought that ensuring the query was not marked as dirty after the DS changed would be enough, but the query editor for the plugin is mounted after and I don't think there's any sort of state change that happens after that mount occurs.

I feel like this is sorta similar to #52213 in that both situations would be very much improved if we knew when the query editor was done doing whatever it needed to do.

${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE} | ${true} | ${true} | ${true} | ${'Changing the datasource will cause the correlation in progress to be lost. Would you like to save before continuing?'}
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_EDITOR} | ${false} | ${false} | ${false} | ${undefined}
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_EDITOR} | ${false} | ${true} | ${false} | ${'Closing the editor will cause the correlation in progress to be lost. Would you like to save before continuing?'}
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_EDITOR} | ${false} | ${false} | ${true} | ${'Closing the editor will lose the changed query. Would you like to save before continuing?'}
Copy link
Contributor

Choose a reason for hiding this comment

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

In what sense "the query is lost"? I tried closing the right pane after changing the query and it seems to run exactly the same query without losing anything:

losing-the-query.mov

Copy link
Contributor Author

@gelicia gelicia Oct 23, 2023

Choose a reason for hiding this comment

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

Ah this is true. I might change this to say "Closing the editor will remove the variables, and your changed query may no longer be valid. Would you like to save before continuing?" in this instance

Fixed!

it.each`
action | isLeft | dirCor | dirQuer | expected
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_PANE} | ${false} | ${false} | ${false} | ${undefined}
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CLOSE_PANE} | ${false} | ${true} | ${false} | ${'Closing the pane will cause the correlation in progress to be lost. Would you like to save before continuing?'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing the label doesn't mark a correlation as dirty. Is it expected?

Screen.Recording.2023-10-23.at.11.38.28.mov

Copy link
Contributor Author

@gelicia gelicia Oct 23, 2023

Choose a reason for hiding this comment

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

No - changing the label means the correlation dirty state is true. This was a regression when I used the default value as a default value instead of the default value being blank and only using the default value on save.

And actually I think I'll be able to tackle this and the mixed datasource problem at the same time, so I'll be looking into this more.

Fixed!

@gelicia
Copy link
Contributor Author

gelicia commented Oct 23, 2023

Transformations vars are not interpolated inside the editor

fixed!

Mixed data source is used inside the default label instead of the underlying data source

Fixed (finally...)

Regex is case insenstive

I did this on purpose to increase the likelihood that people will have matches and I'd like to keep it that way for now. I added it to the tooltip.

@gelicia gelicia force-pushed the kristina/correlations-editor-transform branch from 1533148 to f473dd6 Compare October 23, 2023 21:10
Copy link
Contributor

@ifrost ifrost left a comment

Choose a reason for hiding this comment

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

Is documentation being added as part of this PR?

}
};

export const generateDefaultLabel = async (sourcePane: ExploreItemState, targetPane: ExploreItemState) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally correlations utils should not rely on any Explore specific types. This function could get datasourceRef passed instead of entire ExploreItemState.

${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE} | ${false} | ${false} | ${true} | ${'Changing the datasource will lose the changed query. Would you like to save before continuing?'}
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE} | ${false} | ${true} | ${true} | ${'Changing the datasource will lose the changed query. Would you like to save before continuing?'}
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE} | ${true} | ${false} | ${false} | ${undefined}
${CORRELATION_EDITOR_POST_CONFIRM_ACTION.CHANGE_DATASOURCE} | ${true} | ${true} | ${false} | ${'Changing the datasource will cause the correlation in progress to be lost. Would you like to save before continuing?'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I find it confusing that I'm asked if I want to save the correlation at this point. I'd expect a simple question like "Your progress will be lost. Do you want to continue?". But I'll leave it up to UX.

@gelicia
Copy link
Contributor Author

gelicia commented Oct 31, 2023

Is documentation being added as part of this PR?

Created #77457 and that will be my next task

@gelicia gelicia merged commit 9e0ca0d into main Nov 2, 2023
18 checks passed
@gelicia gelicia deleted the kristina/correlations-editor-transform branch November 2, 2023 20:09
zserge pushed a commit that referenced this pull request Nov 9, 2023
* Add transformation add modal and use it

* Hook up saving

* Add transformation vars to var list, show added transformations

* Form validation

* Remove type assertion, start building out transformation data in helper (WIP)

* Style expression better, add delete logic

* Add ability to edit, additional styling on transformation card in helper

* simplify styling, conditionally run edit set up logic

* Keep more field information in function, integrate it with new editor

* Show default label on collapsed section, use deleteButton for confirmation of deleting transformations

* Change transformation add calculations from function to hook, add label to collapsed header, add transformation tooltip

* Make correlation and editor dirty state distinctive and integrate, WIP

* Track action pane for more detailed messaging/actions

* Better cancel modal logic

* Remove changes to adminsitration transformation editor

* Remove debugging line

* Remove unneeded comment

* Add in logic for closing editor mode

* Add tests for modal logic

* Use state to build vars list for helper

* WIP

* Fix labels and dirty state

* Fix bad message and stop exiting mode if discard action is performed

* Fix tests

* Update to not use unstable component and tweak default label
@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.

Glue: Add transformations to Explore Correlations Editor
6 participants